From ec4bacc1a8cd795f56fc9abf7b488afeff2bd088 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Tue, 3 Aug 2021 09:35:40 +0200 Subject: [PATCH] Translation: weblate integration * after each commit on the master branch: check if searx/translations/messages.pot must be updated, if yes: * merge commits from weblate * build & commit the messages.mo files * update & commit messages.pot * every Friday, the translations from weblate are commited into the master branch --- .github/workflows/integration.yml | 28 ++++++--------- .github/workflows/translations-update.yml | 34 ++++++++++++++++++ manage | 42 +++++++++++++++++++++-- 3 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/translations-update.yml diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 78fc66e3f..75386a9bc 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -102,32 +102,24 @@ jobs: - name: Checkout uses: actions/checkout@v2 with: - persist-credentials: false + fetch-depth: '0' + token: ${{ secrets.WEBLATE_GITHUB_TOKEN }} - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.9' architecture: 'x64' + - name: weblate & git setup + env: + WEBLATE_CONFIG: ${{ secrets.WEBLATE_CONFIG }} + run: | + mkdir -p ~/.config + echo "${WEBLATE_CONFIG}" > ~/.config/weblate + git config --global user.email "alex.searxng@al-f.net" + git config --global user.name "searxng-bot" - name: Update transations id: update - continue-on-error: true run: make V=1 ci.babel.update - - name: Open pull request - if: steps.update.outcome == 'success' - uses: peter-evans/create-pull-request@v3 - with: - commit-message: Update translations (pot, po) - committer: searx-bot - author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> - signoff: false - branch: update_translations_pot - delete-branch: true - draft: false - title: 'Update translations (pot, po)' - body: | - Update messages.pot and messages.po files - labels: | - translation dockers: name: Docker diff --git a/.github/workflows/translations-update.yml b/.github/workflows/translations-update.yml new file mode 100644 index 000000000..a5558a951 --- /dev/null +++ b/.github/workflows/translations-update.yml @@ -0,0 +1,34 @@ +name: "Update translations (weblate)" +on: + schedule: + - cron: "05 07 * * 5" + workflow_dispatch: + +jobs: + babel: + name: Weblate + runs-on: ubuntu-20.04 + if: ${{ github.repository_owner == 'searxng' && github.ref == 'refs/heads/master' }} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: '0' + token: ${{ secrets.WEBLATE_GITHUB_TOKEN }} + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + architecture: 'x64' + - name: weblate & git setup + env: + WEBLATE_CONFIG: ${{ secrets.WEBLATE_CONFIG }} + run: | + mkdir -p ~/.config + echo "${WEBLATE_CONFIG}" > ~/.config/weblate + git config --global user.email "alex.searxng@al-f.net" + 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 diff --git a/manage b/manage index 42c617f5b..b7e6044ee 100755 --- a/manage +++ b/manage @@ -126,6 +126,27 @@ babel.sha256sum() { grep "msgid" "searx/translations/messages.pot" | sort | sha256sum | cut -f1 -d ' ' } +weblate.merge.push.updates() { + ( set -e + pyenv.cmd wlc lock + 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 push + ) + exitcode=$? + ( # make sure to always unlock weblate + set -e + pyenv.cmd wlc unlock + ) + dump_return $exitcode +} + ci.babel.update() { local sha_before ( set -e @@ -133,12 +154,27 @@ ci.babel.update() { babel.extract if [ "$(babel.sha256sum)" = "${sha_before}" ]; then build_msg BABEL 'no changes detected, exiting' - return 1 + return 0 fi + + # call weblate.merge.push.updates right away + git stash push "searx/translations/messages.pot" + weblate.merge.push.updates babel.update + + # then update messages.pot while weblate is locked + pyenv.cmd wlc lock + git stash pop babel.update - build_msg BABEL 'update done, edit .po files if required and run babel.compile' + git add searx/translations + git commit -m "[translations] update messages.pot and messages.po files" + git push ) - dump_return $? + exitcode=$? + ( # make sure to always unlock weblate + set -e + pyenv.cmd wlc unlock + ) + dump_return $exitcode } babel.extract() {