From aa3d342839e66a80f1a4dd3fa15ce4faa11ee59d Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sat, 30 Jan 2016 17:03:15 +0100 Subject: [PATCH] Test translation imports Test imported files whether those are valid (can be compiled by gettext) and do not propose them if they are invalid. If there are invalid files, a proposal of valid files will still happen. The script will fail at the end so that these invalid files can be detected. Change-Id: Ia48181bc79903dd47be054a6f7c7ee535506d282 --- jenkins/scripts/common_translation_update.sh | 24 ++++++++++++++++++- jenkins/scripts/propose_translation_update.sh | 6 +++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/jenkins/scripts/common_translation_update.sh b/jenkins/scripts/common_translation_update.sh index cbbd863a4f..141fc5b734 100644 --- a/jenkins/scripts/common_translation_update.sh +++ b/jenkins/scripts/common_translation_update.sh @@ -22,6 +22,9 @@ TOPIC=zanata/translations # Used for setup.py babel commands QUIET="--quiet" +# Have invalid files been found? +INVALID_PO_FILE=0 + # Get a module name of a project function get_modulename { local project=$1 @@ -381,8 +384,12 @@ function setup_django_openstack_auth { '{locale_with_underscore}/LC_MESSAGES/django.po' -f zanata.xml } -# Filter out files that we do not want to commit +# Filter out files that we do not want to commit. +# Sets global variable INVALID_PO_FILE to 1 if any invalid files are +# found. function filter_commits { + local ret + # Don't add new empty files. for f in $(git diff --cached --name-only --diff-filter=A); do # Files should have at least one non-empty msgid string. @@ -409,6 +416,21 @@ function filter_commits { | egrep -v "$REGEX" \ | egrep -c "^([+][^+#])") set -e + # Check that imported po files are valid + if [[ $f =~ .po$ ]] ; then + set +e + msgfmt --check-format -o /dev/null $f + ret=$? + set -e + if [ $ret -ne "0" ] ; then + # Set change to zero so that next expression reverts + # change of this file. + changed=0 + echo "ERROR: File $f is an invalid po file." + echo "ERROR: The file has not been imported and needs fixing!" + INVALID_PO_FILE=1 + fi + fi if [ $changed -eq 0 ]; then git reset -q "$f" git checkout -- "$f" diff --git a/jenkins/scripts/propose_translation_update.sh b/jenkins/scripts/propose_translation_update.sh index 5d50cc9a51..1bd3db45af 100755 --- a/jenkins/scripts/propose_translation_update.sh +++ b/jenkins/scripts/propose_translation_update.sh @@ -258,3 +258,9 @@ filter_commits # Propose patch to gerrit if there are changes. send_patch "$BRANCH" + +if [ $INVALID_PO_FILE -eq 1 ] ; then + echo "At least one po file in invalid. Fix all invalid files on the" + echo "translation server." + exit 1 +fi