From 0ab235273b46caaa5d6b5da009d0fb6fe68606ee Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 8 Nov 2021 17:10:33 +0000 Subject: [PATCH] Tools: Detect missing translation strings on CI (#5688) --- .github/scripts/run_ci.sh | 32 ++++++++++++++++++----- .github/workflows/github-actions-main.yml | 8 ++++++ packages/tools/build-translation.js | 17 +++++++++++- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/.github/scripts/run_ci.sh b/.github/scripts/run_ci.sh index 0577fdc3688..c63b6749f61 100755 --- a/.github/scripts/run_ci.sh +++ b/.github/scripts/run_ci.sh @@ -81,7 +81,7 @@ fi # release randomly fail. # ============================================================================= -if [ "$IS_PULL_REQUEST" == "1" ]; then +if [ "$IS_PULL_REQUEST" == "1" ] || [ "$IS_DEV_BRANCH" = "1" ]; then echo "Step: Running linter..." npm run linter-ci ./ @@ -109,6 +109,27 @@ if [ "$IS_PULL_REQUEST" == "1" ]; then fi fi +# ============================================================================= +# Check that we didn't lose any string due to gettext not being able to parse +# newly modified or added scripts. This is convenient to quickly view on GitHub +# what commit may have broken translation building. We run this on macOS because +# we need the latest version of gettext (and stable Ubuntu doesn't have it). +# ============================================================================= + +if [ "$IS_PULL_REQUEST" == "1" ] || [ "$IS_DEV_BRANCH" = "1" ]; then + if [ "$IS_MACOS" == "1" ]; then + echo "Step: Checking for lost translation strings..." + + xgettext --version + + node packages/tools/build-translation.js --missing-strings-check-only + testResult=$? + if [ $testResult -ne 0 ]; then + exit $testResult + fi + fi +fi + # ============================================================================= # Find out if we should run the build or not. Electron-builder gets stuck when # building PRs so we disable it in this case. The Linux build should provide @@ -124,13 +145,12 @@ if [ "$IS_PULL_REQUEST" == "1" ]; then fi # ============================================================================= -# Prepare the Electron app and build it +# Build the Electron app or Docker image depending on the current tag. # # If the current tag is a desktop release tag (starts with "v", such as -# "v1.4.7"), we build and publish to github -# -# Otherwise we only build but don't publish to GitHub. It helps finding -# out any issue in pull requests and dev branch. +# "v1.4.7"), we build and publish to GitHub. Otherwise we only build but don't +# publish to GitHub. It helps finding out any issue in pull requests and dev +# branch. # ============================================================================= cd "$ROOT_DIR/packages/app-desktop" diff --git a/.github/workflows/github-actions-main.yml b/.github/workflows/github-actions-main.yml index e83afc1c19d..cfd3abeddcf 100644 --- a/.github/workflows/github-actions-main.yml +++ b/.github/workflows/github-actions-main.yml @@ -19,6 +19,14 @@ jobs: sudo apt-get update || true sudo apt-get install -y gettext sudo apt-get install -y libsecret-1-dev + sudo apt-get install -y translate-toolkit + + - name: Install macOS dependencies + if: runner.os == 'macOS' + run: | + brew update + brew install gettext + brew install translate-toolkit - name: Install Docker Engine if: runner.os == 'Linux' && startsWith(github.ref, 'refs/tags/server-v') diff --git a/packages/tools/build-translation.js b/packages/tools/build-translation.js index 99313e8d53e..1d212409a7e 100644 --- a/packages/tools/build-translation.js +++ b/packages/tools/build-translation.js @@ -346,7 +346,18 @@ function deletedStrings(oldStrings, newStrings) { async function main() { const argv = require('yargs').argv; - const potFilePath = `${localesDir}/joplin.pot`; + const missingStringsCheckOnly = !!argv['missing-strings-check-only']; + + let potFilePath = `${localesDir}/joplin.pot`; + + let tempPotFilePath = ''; + + if (missingStringsCheckOnly) { + tempPotFilePath = `${localesDir}/joplin-temp-${Math.floor(Math.random() * 10000000)}.pot`; + await fs.copy(potFilePath, tempPotFilePath); + potFilePath = tempPotFilePath; + } + const jsonLocalesDir = `${libDir}/locales`; const defaultLocale = 'en_GB'; @@ -360,6 +371,8 @@ async function main() { console.info(`Updated pot file. Total strings: ${oldPotStatus.untranslatedCount} => ${newPotStatus.untranslatedCount}`); + if (tempPotFilePath) await fs.remove(tempPotFilePath); + const deletedCount = oldPotStatus.untranslatedCount - newPotStatus.untranslatedCount; if (deletedCount >= 5) { if (argv['skip-missing-strings-check']) { @@ -374,6 +387,8 @@ async function main() { } } + if (missingStringsCheckOnly) return; + await execCommand(`cp "${potFilePath}" ` + `"${localesDir}/${defaultLocale}.po"`); fs.mkdirpSync(jsonLocalesDir, 0o755);