From 7d77f8951ba788f85b7e85404500d380db0f9b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Wed, 10 Jul 2024 19:05:24 +0200 Subject: [PATCH] GHA: More robust OTA updates action Make the OTA translation updates action more robust: Split checking PO validity and uploading into separate steps and if there are errors, still upload the rest of the files. Otherwise one bad translation was blocking everything else. Add a separate step for checking validity so that the run fails on errors. Add logging of failed files and their content for easier debugging. --- .github/workflows/build-ota-updates.yml | 42 ++++++++++++++++++++----- scripts/build-ota-translations.sh | 12 +++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-ota-updates.yml b/.github/workflows/build-ota-updates.yml index 79140655aa..26bad3f071 100644 --- a/.github/workflows/build-ota-updates.yml +++ b/.github/workflows/build-ota-updates.yml @@ -7,28 +7,54 @@ on: - cron: '11 10 * * *' jobs: - build-ota-translations: - name: Build OTA translations + download-translations: + name: Download translations from Crowdin runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - - name: Install GNU gettext - run: sudo apt-get install gettext - - name: Install Crowdin CLI run: npm i -g @crowdin/cli - - name: Download latest translations from Crowdin run: | echo 'api_token: "${{secrets.CROWDIN_PERSONAL_TOKEN}}"' >>crowdin.yaml crowdin download rm crowdin.yaml + - uses: actions/upload-artifact@v4 + with: + name: translations + path: locales/*.po + check-po-validity: + name: Check translations + runs-on: ubuntu-latest + needs: download-translations + steps: + - uses: actions/download-artifact@v4 + with: + name: translations + - name: Install GNU gettext + run: sudo apt-get install gettext + - name: Check PO files with msgfmt -v -c + run: | + for i in locales/*.po ; do + echo "checking $i..." + msgfmt -v -c -o /dev/null $i + done + + build-ota-translations: + name: Build OTA translations + runs-on: ubuntu-latest + needs: download-translations + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: translations + - name: Install GNU gettext + run: sudo apt-get install gettext - name: Build OTA updates run: scripts/build-ota-translations.sh - - name: Upload OTA updates run: | VERSION=$(sed -n -e 's/.*POEDIT_VERSION.* "\([0-9]*\)\.\([0-9]*\).*".*/\1.\2/p' src/version.h) diff --git a/scripts/build-ota-translations.sh b/scripts/build-ota-translations.sh index 5bf47be880..25e19bb219 100755 --- a/scripts/build-ota-translations.sh +++ b/scripts/build-ota-translations.sh @@ -9,6 +9,18 @@ function finish { } trap finish EXIT +# check PO files for errors and remove the ones that won't compile: +for po in locales/*.po ; do + if ! stderr=$(msgfmt -c -o "$DESTDIR/$mo" "$po" 2>&1) ; then + echo "ERROR: $stderr" + echo "::warning file=$po,title=Failed to compile PO file::`echo $stderr`" + echo "::group::Content of $po" + cat "$po" + echo "::endgroup::" + rm "$po" + fi +done + # compile PO files, taking care to make them reproducible, i.e. not change if the actual # translations didn't change: for po in locales/*.po ; do