From 361bc551294d313631a3c61e07ddf65b97e72041 Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Wed, 19 Feb 2020 19:57:41 +0100 Subject: Adds translation updates action (#15541) Adds an action to create a PR with translation updates once a week (Saturday 2:00 UTC) --- .github/workflows/translations.yml | 143 +++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 .github/workflows/translations.yml (limited to '.github') diff --git a/.github/workflows/translations.yml b/.github/workflows/translations.yml new file mode 100644 index 0000000000..2148d2b2d4 --- /dev/null +++ b/.github/workflows/translations.yml @@ -0,0 +1,143 @@ +name: Translation Updates + +on: + schedule: + - cron: "0 2 * * 6" + +jobs: + build: + + runs-on: ubuntu-latest + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_ROOT_PASSWORD: "" + MYSQL_DATABASE: piwik_tests + ports: + - 3306/tcp + + + steps: + - uses: shivammathur/setup-php@v1 + with: + php-version: '7.3' + - uses: actions/checkout@v2 + with: + ref: '4.x-dev' + lfs: false + - name: Prepare branches + run: | + cat <<- EOF > $HOME/.netrc + machine github.com + login $GITHUB_ACTOR + password $GITHUB_TOKEN + machine api.github.com + login $GITHUB_ACTOR + password $GITHUB_TOKEN + EOF + chmod 600 $HOME/.netrc + + git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" + git config --global user.name "$GITHUB_ACTOR" + + git remote add upstream https://github.com/matomo-org/matomo.git + + git push origin --delete translationupdates || true + git branch -D translationupdates || true + git fetch upstream 4.x-dev + git checkout -f upstream/4.x-dev + git branch translationupdates + git checkout -f translationupdates + - name: Checkout submodules + run: git submodule update --init --force + - name: Install Dependencies + run: composer install --prefer-dist + - name: Initialize Matomo + run: | + cp ./tests/travis/config.ini.travis.php ./config/config.ini.php + ./console development:enable + - name: Sync translations + run: ./console translations:update --username ${{ secrets.TransifexUsername }} --password ${{ secrets.TransifexPassword }} --force --no-interaction + - name: Check for changes + id: changes + run: | + IFS=$'\n' + changes=( $(git diff --numstat | grep -E '([0-9]+)\s+([0-9]+)\s+[a-zA-Z\/]*lang\/([a-z]{2,3}(?:-[a-z]{2,3})?)\.json' ) ) + unset IFS + + # abort here if no change available + if [[ ${#changes[@]} -eq 0 ]] + then + exit 0 + fi + + git add lang/ + git add "*.json" + + declare -i totaladditions=0 + declare -A additionsByLang + + for (( i=0; i < ${#changes[@]}; i++ )); do + line=( ${changes[$i]} ) + additions=${line[0]} + + if [[ ${line[0]} = "0" ]] + then + continue; + fi + + file=${line[2]} + lang=$( echo ${line[2]} | grep -oE '([a-z]{2,3}(?:-[a-z]{2,3})?)\.json' | cut -d'.' -f 1 ) + + totaladditions=$(( totaladditions + additions )) + additionsByLang[$lang]=$(( additionsByLang[$lang] + additions )) + done + + title="Updated $totaladditions strings in ${#additionsByLang[@]} languages (${!additionsByLang[@]})" + + languageInfo=( $( ./console translations:languageinfo ) ) + + for i in ${!additionsByLang[@]}; do + for j in ${languageInfo[@]}; do + if [[ "$j" == "$i|"* ]]; + then + IFS=$'\n' + info=( $( echo "$j" | tr "|" "\n" ) ) + unset IFS + break + fi + done + + message="$message- Updated ${info[1]} (${additionsByLang[$i]} changes / ${info[2]} translated)\n" + done + + message="$message\n\nHelp us translate Matomo in your language!\nSignup at https://www.transifex.com/matomo/matomo/\nIf you have any questions, get in touch with us at translations@matomo.org" + + echo $title + echo $message + + echo ::set-output name=title::$title + echo ::set-output name=message::$message + shell: bash + - name: Push changes + run: | + git commit -m "language update" + git push --set-upstream origin translationupdates + - name: Create PR + run: | + curl \ + --request POST \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + --header 'content-type: application/json' \ + --data '{ + "title":"[automatic translation update] ${{ steps.changes.outputs.title }}", + "body":"${{ steps.changes.outputs.message }}", + "head":"translationupdates", + "base":"4.x-dev" + }' \ + --url https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls + shell: bash + if: steps.changes.outputs.title -- cgit v1.2.3