Skip to content

Commit

Permalink
Update translations with Travis and not during build (PhoenicisOrg#1676)
Browse files Browse the repository at this point in the history
  • Loading branch information
plata authored Dec 30, 2018
1 parent 9ba790a commit 836707f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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="<access_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="
35 changes: 35 additions & 0 deletions i18n/push_translations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
git config --global user.email "[email protected]"
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
33 changes: 32 additions & 1 deletion phoenicis-configuration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
<id>gettext</id>
<phase>compile</phase>
<goals>
<goal>gettext</goal>
<goal>dist</goal>
</goals>
</execution>
Expand All @@ -118,4 +117,36 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>update-translations</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.gettext-commons</groupId>
<artifactId>gettext-maven-plugin</artifactId>
<version>1.2.4</version>
<executions>
<execution>
<id>gettext</id>
<phase>validate</phase>
<goals>
<goal>gettext</goal>
</goals>
</execution>
</executions>
<configuration>
<poDirectory>${project.basedir}/../i18n</poDirectory>
<sourceDirectory>${project.basedir}/../</sourceDirectory>
<targetBundle>org.phoenicis.configuration.localisation.Messages</targetBundle>
<outputFormat>properties</outputFormat>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit 836707f

Please sign in to comment.