From 00699aaed429f9409ad987c3695521ad14e446b3 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Wed, 4 Aug 2021 11:03:05 +0200 Subject: [PATCH] Translations: github workflows use the translations branch --- .github/workflows/integration.yml | 6 +-- .github/workflows/translations-update.yml | 25 ++++++++-- Makefile | 2 +- manage | 56 ++++++++++++++++------- 4 files changed, 63 insertions(+), 26 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 75386a9bc..6ab0f9600 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -93,7 +93,7 @@ jobs: babel: name: Babel runs-on: ubuntu-20.04 - if: ${{ github.repository_owner == 'searxng' && github.ref == 'refs/heads/master' }} + if: ${{ github.repository_owner == 'dalf' && github.ref == 'refs/heads/master' }} needs: - python - themes @@ -115,11 +115,11 @@ jobs: run: | mkdir -p ~/.config echo "${WEBLATE_CONFIG}" > ~/.config/weblate - git config --global user.email "alex.searxng@al-f.net" + git config --global user.email "searxng-bot@users.noreply.github.com" git config --global user.name "searxng-bot" - name: Update transations id: update - run: make V=1 ci.babel.update + run: make V=1 babel.master.to.translations dockers: name: Docker diff --git a/.github/workflows/translations-update.yml b/.github/workflows/translations-update.yml index a5558a951..31c5ebf8e 100644 --- a/.github/workflows/translations-update.yml +++ b/.github/workflows/translations-update.yml @@ -8,7 +8,7 @@ jobs: babel: name: Weblate runs-on: ubuntu-20.04 - if: ${{ github.repository_owner == 'searxng' && github.ref == 'refs/heads/master' }} + if: ${{ github.repository_owner == 'dalf' && github.ref == 'refs/heads/master' }} steps: - name: Checkout uses: actions/checkout@v2 @@ -26,9 +26,24 @@ jobs: run: | mkdir -p ~/.config echo "${WEBLATE_CONFIG}" > ~/.config/weblate - git config --global user.email "alex.searxng@al-f.net" + git config --global user.email "searxng-bot@users.noreply.github.com" git config --global user.name "searxng-bot" - name: Merge and push transation updates - id: update - run: make V=1 weblate.merge.push.updates - \ No newline at end of file + run: make V=1 ci.babel.translations.to.master + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.WEBLATE_GITHUB_TOKEN }} + commit-message: Update translations + committer: searxng-bot + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + signoff: false + branch: translations_update + delete-branch: true + draft: false + title: 'Update translations' + body: | + Update translations + labels: | + translation diff --git a/Makefile b/Makefile index d48f5c531..01e0777a6 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ test.shell: # wrap ./manage script MANAGE += buildenv -MANAGE += ci.babel.update babel.extract babel.update babel.compile +MANAGE += babel.extract babel.update babel.compile babel.translations.to.master babel.master.to.translations MANAGE += data.all data.languages data.useragents data.osm_keys_tags MANAGE += docs.html docs.live docs.gh-pages docs.prebuild docs.clean MANAGE += docker.build docker.push docker.buildx diff --git a/manage b/manage index b7e6044ee..bbff8e08b 100755 --- a/manage +++ b/manage @@ -122,21 +122,16 @@ buildenv() { return "${PIPESTATUS[0]}" } -babel.sha256sum() { - grep "msgid" "searx/translations/messages.pot" | sort | sha256sum | cut -f1 -d ' ' -} - -weblate.merge.push.updates() { +babel.weblate.to.translations() { + local exitcode ( set -e pyenv.cmd wlc lock + git checkout translations if ! git remote get-url weblate; then git remote add weblate https://weblate.bubu1.eu/git/searxng/searxng/ fi git remote update weblate - git merge weblate/master - babel.compile - git add searx/translations - git commit -m "[translations] update messages.mo files" + git merge weblate/translations git push ) exitcode=$? @@ -147,22 +142,49 @@ weblate.merge.push.updates() { dump_return $exitcode } -ci.babel.update() { - local sha_before +babel.translations.to.master() { + ( set -e + # pull weblate commits + babel.weblate.to.translations + + # copy the changes to the master branch + git checkout translations + tar cf "/tmp/translations.tar.gz" searx/translations + git checkout master + tar xf "/tmp/translations.tar.gz" + + # compile translations + babel.compile + ) + dump_return $? +} + +babel.sha256sum() { + grep "msgid" "searx/translations/messages.pot" | sort | sha256sum | cut -f1 -d ' ' +} + +babel.master.to.translations() { + local new_sha translations_sha exitcode ( set -e - sha_before="$(babel.sha256sum)" babel.extract - if [ "$(babel.sha256sum)" = "${sha_before}" ]; then + new_sha=$(babel.sha256sum) + git stash push "searx/translations/messages.pot" + + git checkout translations + translations_sha="$(babel.sha256sum)" + + if [ "${new_sha}" = "${translations_sha}" ]; then build_msg BABEL 'no changes detected, exiting' + git stash drop return 0 fi - # call weblate.merge.push.updates right away - git stash push "searx/translations/messages.pot" - weblate.merge.push.updates babel.update + # update the translations branch with weblate commits + babel.weblate.to.translations - # then update messages.pot while weblate is locked + # update/commit/push messages.po while weblate is locked pyenv.cmd wlc lock + git checkout translations git stash pop babel.update git add searx/translations