From 836707f83c30cfaac1923ee95250a034292aa8d8 Mon Sep 17 00:00:00 2001 From: plata Date: Sun, 30 Dec 2018 22:11:00 +0100 Subject: [PATCH] Update translations with Travis and not during build (#1676) --- .travis.yml | 19 ++++++++++++++++++ i18n/push_translations.sh | 35 +++++++++++++++++++++++++++++++++ phoenicis-configuration/pom.xml | 33 ++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100755 i18n/push_translations.sh diff --git a/.travis.yml b/.travis.yml index 064e3ece75c..0bffa4949e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,15 @@ jobs: install: true script: mvn -Pcheck-formatted validate formatter:validate + # Update translations + - stage: Basics + name: Update translations + install: true + script: mvn -Pupdate-translations validate + after_success: + # push translation updates only for master (PR changes must be committed to master before they are taken into account) + - if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./i18n/push_translations.sh; fi + # build + test - stage: Build + test name: Linux OpenJDK 10 @@ -79,3 +88,13 @@ jobs: script: - bundle exec jekyll build - bundle exec htmlproofer ./_site --only-4xx --check-favicon --check-html --assume-extension + +env: + global: + # to create secure for travis-ci.com + # 1. create personal access token with public_repo permissions + # 2. clone this repo (not a fork) + # 3. install travis gem (https://github.com/travis-ci/travis.rb) + # 4. run in the clone: travis encrypt GH_TOKEN="" --pro (GH_TOKEN is the variable which is used e.g. in push_translations.sh) + # 5. set output below + - secure: "NNFWW2gm1hzMI2vLr8b7EuRz8u+eSk5FGoXDq0UZbdnmcnb/8Isx2sd8j73VSRN4LvRAnqFnZUuouFjVBeX+T8eUv4qL1z8QBz4nqS1ZrbYEwVFKEv/87RB7FfpvA+nqEzJv0Nq9jFLmkgBw2pji5xNkL23RABxm4kFO9zJRrlrWNJCAFxNI2Tzrw8RWuFuG49eH16BPOZfECcMzP16rBcpr0YZjcZ/p+yjUaz+IaOinQyHs/p45oPVF3XxSVLOODVsaVw7kxZxXZRCDz60ssCefTt6XlgR5J5blo6QGX1Y3bks25A2Jeivax+Lv2J5zrOBV8TgDDyj6+XP2HyxM91A7LFnOvA/iXjDZUgh8jGGmBnCpESq8b+Llymhy1i9nfGAAQYedq2/zNaiETOr+vakcgbITk1sPb9YxydB0RIyjnRnlwjxAjWTckxZCWQbFieODYBsGBZN8X9k/4iHsMkIHpEJ41BPGapOxjolIHD8sAqA3XlT0hR1nKjTUM08c/9JHyCZ1BAyiFvbsD/gT9oYFwhe/Im57N/WBBiXzkiElmJ3RogUyFuapKYuwOvCQvgpSP2weDgO0k9Q+Y1g4VH5I5aViR+G44kf4P7Dn2RvvI1n6mLDs9bki94WYWNBMwhRM+cmcrYCtW/dszSIr5W5ZzH0jHd/9VxiLV44mL7k=" diff --git a/i18n/push_translations.sh b/i18n/push_translations.sh new file mode 100755 index 00000000000..0b0a1336841 --- /dev/null +++ b/i18n/push_translations.sh @@ -0,0 +1,35 @@ +#!/bin/bash +git config --global user.email "travis@travis-ci.org" +git config --global user.name "Travis CI" + +head_ref=$(git rev-parse HEAD) +if [[ $? -ne 0 || ! $head_ref ]]; then + echo "could not retrieve HEAD reference" + exit 1 +fi +branch_ref=$(git rev-parse "$TRAVIS_BRANCH") +if [[ $? -ne 0 || ! $branch_ref ]]; then + echo "could not retrieve $TRAVIS_BRANCH reference" + exit 1 +fi +if [[ $head_ref != $branch_ref ]]; then + echo "HEAD ref ($head_ref) does not match $TRAVIS_BRANCH ref ($branch_ref)" + echo "new commits have been added before this build cloned the repository" + exit 0 +fi +if [[ $TRAVIS_BRANCH != master ]]; then + echo "will not push translation updates to branch $TRAVIS_BRANCH" + exit 1 +fi +git checkout master + +# check if anything except "POT creation date" has changed +git diff --numstat i18n/keys.pot | awk '{ if($1 == 1 && $2 == 1) { exit 1 } else exit 0 }' +if [ $? == 0 ]; then + git add *.pot + git commit --message "Update translations" + if ! git push https://$GH_TOKEN@github.com/PhoenicisOrg/phoenicis.git > /dev/null 2>&1; then + echo "could not push translation updates" + exit 1 + fi +fi diff --git a/phoenicis-configuration/pom.xml b/phoenicis-configuration/pom.xml index 164eb338f64..0d2140f14d3 100644 --- a/phoenicis-configuration/pom.xml +++ b/phoenicis-configuration/pom.xml @@ -104,7 +104,6 @@ gettext compile - gettext dist @@ -118,4 +117,36 @@ + + + update-translations + + false + + + + + com.googlecode.gettext-commons + gettext-maven-plugin + 1.2.4 + + + gettext + validate + + gettext + + + + + ${project.basedir}/../i18n + ${project.basedir}/../ + org.phoenicis.configuration.localisation.Messages + properties + + + + + +