From 2a5f690a71ca7120c9851b0a2bc9c3f6bb4e923b Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Mon, 6 Sep 2021 12:09:20 +0200 Subject: [PATCH] [fix] translation: lock weblate only when there is an actual change of messages.pot Close #290 --- docs/dev/translation.svg | 18 ++++++++++-------- manage | 23 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/docs/dev/translation.svg b/docs/dev/translation.svg index 70400cca..71f4172b 100644 --- a/docs/dev/translation.svg +++ b/docs/dev/translation.svg @@ -1,4 +1,4 @@ -master branchmaster branchtranslations_update branchtranslations_update branchtranslations branchtranslations branchweblate clone ofSearXNG repositoryweblate clone ofSearXNG repositoryweblatepending changesweblatepending changesfor each commit on master.github/workflows/integration.ymlmake weblate.push.translationswlc lockwlc pullwlc commitgit merge weblate/translationspybabel extractextract messages, store messages.pot on translations branchpybabel update (messages.po)git add searx/translationsgit commitgit pushwlc unlockevery Friday.github/workflows/translations-update.ymlmake weblate.translations.commitwlc lockwlc pullwlc commitgit merge weblate/translationspybabel compilecp searx/translationsgit addgit commitwlc unlockcreate or update pull request"Update translations"developper's reviewmerge pull request +--> \ No newline at end of file diff --git a/manage b/manage index 6f6f1a4f..53c31be0 100755 --- a/manage +++ b/manage @@ -239,16 +239,14 @@ weblate.push.translations() { local messages_pot diff_messages_pot last_commit_hash last_commit_detail \ last_commit_message exitcode + messages_pot="${TRANSLATIONS_WORKTREE}/searx/translations/messages.pot" ( set -e - # lock change on weblate - pyenv.cmd wlc lock # get translations branch in git worktree (TRANSLATIONS_WORKTREE) weblate.translations.worktree # update messages.pot in the master branch build_msg BABEL 'extract messages from source files and generate POT file' - messages_pot="${TRANSLATIONS_WORKTREE}/searx/translations/messages.pot" pyenv.cmd pybabel extract -F babel.cfg \ -o "${messages_pot}" \ "searx/" @@ -258,8 +256,25 @@ weblate.push.translations() { git diff -- "searx/translations/messages.pot") if ! echo "$diff_messages_pot" | grep -qE "[\+\-](msgid|msgstr)"; then build_msg BABEL 'no changes detected, exiting' - return 0 + return 42 fi + return 0 + ) + exitcode=$? + if [ "$exitcode" -eq 42 ]; then + return 0 + fi + if [ "$exitcode" ]; then + return $exitcode + fi + ( + set -e + + # lock change on weblate + # weblate may add commit(s) since the call to "weblate.translations.worktree". + # this is not a problem because after this line, "weblate.to.translations" + # calls again "weblate.translations.worktree" which calls "git pull" + pyenv.cmd wlc lock # save messages.pot in the translations branch for later pushd "${TRANSLATIONS_WORKTREE}"