diff --git a/playbooks/releasenotes/post.yaml b/playbooks/releasenotes/post.yaml new file mode 100644 index 00000000..6931e833 --- /dev/null +++ b/playbooks/releasenotes/post.yaml @@ -0,0 +1,7 @@ +- hosts: all + roles: + - role: fetch-tox-output + tox_envlist: releasenotes + - role: fetch-sphinx-output + sphinx_output_src: "{{ zuul.project.src_dir }}/doc/build/html/" + zuul_executor_dest: "{{ zuul.executor.log_root }}" diff --git a/playbooks/releasenotes/run.yaml b/playbooks/releasenotes/run.yaml index 2a4ef0a5..116c6888 100644 --- a/playbooks/releasenotes/run.yaml +++ b/playbooks/releasenotes/run.yaml @@ -1,130 +1,3 @@ - hosts: all - tasks: - - - shell: - cmd: | - set -e - set -x - - DOCNAME=releasenotes - DIRECTORY=releasenotes - - script_path=/usr/local/jenkins/slave_scripts - - # Mapping of language codes to language names - declare -A LANG_NAME=( - ["de"]="German" - ["en_AU"]="English (Australian)" - ["en_GB"]="English (United Kingdom)" - ["es"]="Spanish" - ["fr"]="French" - ["id"]="Indonesian" - ["it"]="Italian" - ["ja"]="Japanese" - ["ko_KR"]="Korean (South Korea)" - ["pt_BR"]="Portuguese (Brazil)" - ["ru"]="Russian" - ["tr_TR"]="Turkish (Turkey)" - ["zh_CN"]="Chinese (China)" - ) - - # This file always exists in OpenStack CI jobs, check for it so that - # it can be used manually as well. - if [ -e "$HOME/src/git.openstack.org/openstack/requirements/upper-constraints.txt" ]; then - export UPPER_CONSTRAINTS_FILE=$HOME/src/git.openstack.org/openstack/requirements/upper-constraints.txt - fi - - if [ ! -e ${DIRECTORY}/source/locale/ ]; then - echo "No translations found, only building normal release notes" - $script_path/run-tox.sh releasenotes - exit 0 - fi - - # Check that locale_dirs is really set, otherwise translations - # will not work. - if ! grep -q -E '^locale_dirs *=' $DIRECTORY/source/conf.py; then - echo "Translations exist and locale_dirs missing in source/conf.py" - exit 1 - fi - - REFERENCES=`mktemp` - trap "rm -f -- '$REFERENCES'" EXIT - - # Extract translations - tox -e venv -- sphinx-build -b gettext \ - -d ${DIRECTORY}/build/doctrees.gettext \ - ${DIRECTORY}/source/ \ - ${DIRECTORY}/source/locale/ - - # Add links for translations to index file - cat <> ${REFERENCES} - - Translated Release Notes - ======================== - - EOF - - # Check all language translation resources - for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do - # Skip if it is not a valid language translation resource. - if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}.po ]; then - continue - fi - language=$(basename $locale) - - echo "Building $language translation" - - # Prepare all translation resources - for pot in ${DIRECTORY}/source/locale/*.pot ; do - # Get filename - resname=$(basename ${pot} .pot) - - # Merge all translation resources. Note this is done the same - # way as done in common_translation_update.sh where we merge - # all strings together in a single file. - msgmerge --silent -o \ - ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \ - ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po \ - ${pot} - # Compile all translation resources - msgfmt -o \ - ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.mo \ - ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po - done - - # Build translated document - tox -e venv -- sphinx-build -b html -D language=${language} \ - -d "${DIRECTORY}/build/doctrees.${language}" \ - ${DIRECTORY}/source/ ${DIRECTORY}/build/html/${language} - - # Reference translated document from index file - if [ ${LANG_NAME["${language}"]+_} ] ; then - name=${LANG_NAME["${language}"]} - name+=" (${language})" - echo "* \`$name <${language}/index.html>\`__" >> ${REFERENCES} - else - echo "* \`${language} <${language}/index.html>\`__" >> ${REFERENCES} - fi - - # Remove newly created files - git clean -f -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.po - git clean -f -x -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.mo - # revert changes to po file - git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po - git checkout -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po - done - - # Now append our references to the index file. We cannot do this - # earlier since the sphinx commands will read this file. - cat ${REFERENCES} >> ${DIRECTORY}/source/index.rst - - # Remove newly created pot files - rm -f ${DIRECTORY}/source/locale/*.pot - - # Now build releasenotes with reference to translations - $script_path/run-tox.sh releasenotes - - # Revert any changes to the index file. - git checkout -- ${DIRECTORY}/source/index.rst - chdir: 'src/{{ zuul.project.canonical_name }}' - executable: /bin/bash + roles: + - build-releasenotes diff --git a/roles/build-releasenotes/README.rst b/roles/build-releasenotes/README.rst new file mode 100644 index 00000000..dd61f909 --- /dev/null +++ b/roles/build-releasenotes/README.rst @@ -0,0 +1,8 @@ +Build releasenotes for a project, optionally incorporating translations. + +**Role Variables** + +.. zuul:rolevar:: zuul_work_dir + :default: {{ zuul.project.src_dir }} + + Directory to build releasenotes in. diff --git a/roles/build-releasenotes/defaults/main.yaml b/roles/build-releasenotes/defaults/main.yaml new file mode 100644 index 00000000..9739eb17 --- /dev/null +++ b/roles/build-releasenotes/defaults/main.yaml @@ -0,0 +1 @@ +zuul_work_dir: "{{ zuul.project.src_dir }}" diff --git a/roles/build-releasenotes/tasks/main.yaml b/roles/build-releasenotes/tasks/main.yaml new file mode 100644 index 00000000..0161cb77 --- /dev/null +++ b/roles/build-releasenotes/tasks/main.yaml @@ -0,0 +1,130 @@ +# TODO(mordred) This needs to be reworked to use the tox role +# TODO(mordred) Put the translations logic into a sphinx plugin? +- name: Build releasenotes contents + shell: + chdir: '{{ zuul_work_dir }}' + executable: /bin/bash + cmd: | + set -e + set -x + + DOCNAME=releasenotes + DIRECTORY=releasenotes + + script_path=/usr/local/jenkins/slave_scripts + + # Mapping of language codes to language names + declare -A LANG_NAME=( + ["de"]="German" + ["en_AU"]="English (Australian)" + ["en_GB"]="English (United Kingdom)" + ["es"]="Spanish" + ["fr"]="French" + ["id"]="Indonesian" + ["it"]="Italian" + ["ja"]="Japanese" + ["ko_KR"]="Korean (South Korea)" + ["pt_BR"]="Portuguese (Brazil)" + ["ru"]="Russian" + ["tr_TR"]="Turkish (Turkey)" + ["zh_CN"]="Chinese (China)" + ) + + # This file always exists in OpenStack CI jobs, check for it so that + # it can be used manually as well. + if [ -e "$HOME/src/git.openstack.org/openstack/requirements/upper-constraints.txt" ]; then + export UPPER_CONSTRAINTS_FILE=$HOME/src/git.openstack.org/openstack/requirements/upper-constraints.txt + fi + + if [ ! -e ${DIRECTORY}/source/locale/ ]; then + echo "No translations found, only building normal release notes" + $script_path/run-tox.sh releasenotes + exit 0 + fi + + # Check that locale_dirs is really set, otherwise translations + # will not work. + if ! grep -q -E '^locale_dirs *=' $DIRECTORY/source/conf.py; then + echo "Translations exist and locale_dirs missing in source/conf.py" + exit 1 + fi + + REFERENCES=`mktemp` + trap "rm -f -- '$REFERENCES'" EXIT + + # Extract translations + tox -e venv -- sphinx-build -b gettext \ + -d ${DIRECTORY}/build/doctrees.gettext \ + ${DIRECTORY}/source/ \ + ${DIRECTORY}/source/locale/ + + # Add links for translations to index file + cat <> ${REFERENCES} + + Translated Release Notes + ======================== + + EOF + + # Check all language translation resources + for locale in `find ${DIRECTORY}/source/locale/ -maxdepth 1 -type d` ; do + # Skip if it is not a valid language translation resource. + if [ ! -e ${locale}/LC_MESSAGES/${DOCNAME}.po ]; then + continue + fi + language=$(basename $locale) + + echo "Building $language translation" + + # Prepare all translation resources + for pot in ${DIRECTORY}/source/locale/*.pot ; do + # Get filename + resname=$(basename ${pot} .pot) + + # Merge all translation resources. Note this is done the same + # way as done in common_translation_update.sh where we merge + # all strings together in a single file. + msgmerge --silent -o \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po \ + ${pot} + # Compile all translation resources + msgfmt -o \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.mo \ + ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${resname}.po + done + + # Build translated document + tox -e venv -- sphinx-build -b html -D language=${language} \ + -d "${DIRECTORY}/build/doctrees.${language}" \ + ${DIRECTORY}/source/ ${DIRECTORY}/build/html/${language} + + # Reference translated document from index file + if [ ${LANG_NAME["${language}"]+_} ] ; then + name=${LANG_NAME["${language}"]} + name+=" (${language})" + echo "* \`$name <${language}/index.html>\`__" >> ${REFERENCES} + else + echo "* \`${language} <${language}/index.html>\`__" >> ${REFERENCES} + fi + + # Remove newly created files + git clean -f -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.po + git clean -f -x -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/*.mo + # revert changes to po file + git reset -q ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po + git checkout -- ${DIRECTORY}/source/locale/${language}/LC_MESSAGES/${DOCNAME}.po + done + + # Now append our references to the index file. We cannot do this + # earlier since the sphinx commands will read this file. + cat ${REFERENCES} >> ${DIRECTORY}/source/index.rst + + # Remove newly created pot files + rm -f ${DIRECTORY}/source/locale/*.pot + + # Now build releasenotes with reference to translations + $script_path/run-tox.sh releasenotes + + # Move the built output into doc/build so that other roles can work well + mv ${DIRECTORY}/build doc diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index 67b7cf55..e1d86ede 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -272,6 +272,7 @@ parent: openstack-tox success-url: html/ run: playbooks/releasenotes/run + post-run: playbooks/releasenotes/post timeout: 1800 - job: