From 3eac5546330fb9e6998111ac8212a8c1d6fc2316 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 19 Nov 2025 14:47:45 +0200 Subject: [PATCH] cache translation compilation action step --- .github/actions/build-translations/action.yml | 48 +++++++++++++++++++ .github/workflows/build-submit-android.yml | 7 ++- .github/workflows/build-submit-ios.yml | 7 ++- .../workflows/bundle-deploy-eas-update.yml | 11 ++--- .github/workflows/lint.yml | 8 +++- .github/workflows/pull-request-comment.yml | 5 +- .github/workflows/pull-request-commit.yml | 13 ++++- 7 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 .github/actions/build-translations/action.yml diff --git a/.github/actions/build-translations/action.yml b/.github/actions/build-translations/action.yml new file mode 100644 index 0000000000..4515346dcf --- /dev/null +++ b/.github/actions/build-translations/action.yml @@ -0,0 +1,48 @@ +name: 'Build Translations' +description: 'Compile translations with caching and optionally check for errors' +inputs: + check-for-errors: + description: 'Whether to check for i18n compilation errors' + required: false + default: 'false' +runs: + using: 'composite' + steps: + - name: 📝 Extract English source strings + shell: bash + run: yarn intl:extract + + - name: 🔑 Generate cache key + id: cache-key + shell: bash + run: | + EN_HASH=$(cat src/locale/locales/en/messages.po | shasum -a 256 | cut -d' ' -f1) + YARN_HASH=$(cat yarn.lock | shasum -a 256 | cut -d' ' -f1) + CACHE_KEY="translations-${EN_HASH}-${YARN_HASH}" + echo "key=${CACHE_KEY}" >> $GITHUB_OUTPUT + echo "Cache key: ${CACHE_KEY}" + + - name: 📦 Restore translations cache + id: cache-translations + uses: actions/cache@v4 + with: + path: | + src/locale/locales/*/messages.po + src/locale/locales/*/messages.js + key: ${{ steps.cache-key.outputs.key }} + + - name: 🔤 Compile translations + if: steps.cache-translations.outputs.cache-hit != 'true' + shell: bash + run: yarn intl:compile 2>&1 | tee i18n.log + + - name: Check for i18n compilation errors + if: inputs.check-for-errors == 'true' && steps.cache-translations.outputs.cache-hit != 'true' + shell: bash + run: | + if grep -q "invalid syntax" "i18n.log"; then + echo -e "\n\nFound compilation errors!\n\n" + exit 1 + else + echo -e "\n\nNo compilation errors!\n\n" + fi diff --git a/.github/workflows/build-submit-android.yml b/.github/workflows/build-submit-android.yml index ac8900e665..e7ec06c6c3 100644 --- a/.github/workflows/build-submit-android.yml +++ b/.github/workflows/build-submit-android.yml @@ -60,10 +60,9 @@ jobs: run: yarn install --frozen-lockfile - name: 🔤 Compile translations - run: yarn intl:build 2>&1 | tee i18n.log - - - name: Check for i18n compilation errors - run: if grep -q "invalid syntax" "i18n.log"; then echo "\n\nFound compilation errors!\n\n" && exit 1; else echo "\n\nNo compilation errors!\n\n"; fi + uses: ./.github/actions/build-translations + with: + check-for-errors: 'true' # EXPO_PUBLIC_ENV is handled in eas.json - name: Env diff --git a/.github/workflows/build-submit-ios.yml b/.github/workflows/build-submit-ios.yml index 2ebbd66ec9..0f2e773e9a 100644 --- a/.github/workflows/build-submit-ios.yml +++ b/.github/workflows/build-submit-ios.yml @@ -73,10 +73,9 @@ jobs: key: ${{ runner.os }}-pods-${{ hashFiles('yarn.lock') }} - name: 🔤 Compile translations - run: yarn intl:build 2>&1 | tee i18n.log - - - name: Check for i18n compilation errors - run: if grep -q "invalid syntax" "i18n.log"; then echo "\n\nFound compilation errors!\n\n" && exit 1; else echo "\n\nNo compilation errors!\n\n"; fi + uses: ./.github/actions/build-translations + with: + check-for-errors: 'true' # EXPO_PUBLIC_ENV is handled in eas.json - name: ✏️ Write environment variables diff --git a/.github/workflows/bundle-deploy-eas-update.yml b/.github/workflows/bundle-deploy-eas-update.yml index ee59cad977..13d4c5a466 100644 --- a/.github/workflows/bundle-deploy-eas-update.yml +++ b/.github/workflows/bundle-deploy-eas-update.yml @@ -79,10 +79,9 @@ jobs: run: yarn prettier --check . - name: 🔤 Compile translations - run: yarn intl:build 2>&1 | tee i18n.log - - - name: Check for i18n compilation errors - run: if grep -q "invalid syntax" "i18n.log"; then echo "\n\nFound compilation errors!\n\n" && exit 1; else echo "\n\nNo compilation errors!\n\n"; fi + uses: ./.github/actions/build-translations + with: + check-for-errors: 'true' - name: Type check run: yarn typecheck @@ -214,7 +213,7 @@ jobs: key: ${{ runner.os }}-pods-${{ hashFiles('yarn.lock') }} - name: 🔤 Compile translations - run: yarn intl:build + uses: ./.github/actions/build-translations # EXPO_PUBLIC_ENV is handled in eas.json - name: Env @@ -307,7 +306,7 @@ jobs: run: yarn install --frozen-lockfile - name: 🔤 Compile translations - run: yarn intl:build + uses: ./.github/actions/build-translations # EXPO_PUBLIC_ENV is handled in eas.json - name: Env diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6d6ee7eddd..964708b8cf 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -34,7 +34,9 @@ jobs: - name: Prettier check run: yarn prettier --check . - name: Check & compile i18n - run: yarn intl:build + uses: ./.github/actions/build-translations + with: + check-for-errors: 'true' - name: Type check run: yarn typecheck testing: @@ -55,7 +57,9 @@ jobs: attempt_limit: 3 attempt_delay: 2000 - name: Check & compile i18n - run: yarn intl:build + uses: ./.github/actions/build-translations + with: + check-for-errors: 'true' - name: Run tests run: | NODE_ENV=test yarn test --forceExit diff --git a/.github/workflows/pull-request-comment.yml b/.github/workflows/pull-request-comment.yml index 5668854f0a..4193dd2ecc 100644 --- a/.github/workflows/pull-request-comment.yml +++ b/.github/workflows/pull-request-comment.yml @@ -133,10 +133,7 @@ jobs: run: yarn lockfile-lint - name: 🔤 Compile translations - run: yarn intl:build 2>&1 | tee i18n.log - - - name: Check for i18n compilation errors - run: if grep -q "invalid syntax" "i18n.log"; then echo "\n\nFound compilation errors!\n\n" && exit 1; else echo "\n\nNo compilation errors!\n\n"; fi + uses: ./.github/actions/build-translations - name: Type check run: yarn typecheck diff --git a/.github/workflows/pull-request-commit.yml b/.github/workflows/pull-request-commit.yml index cc2dbe78bd..9f11347212 100644 --- a/.github/workflows/pull-request-commit.yml +++ b/.github/workflows/pull-request-commit.yml @@ -57,7 +57,9 @@ jobs: git config --global user.name "github-actions[bot]" git merge --no-edit $HEAD_REF yarn install - yarn intl:build + + - name: 🔤 Compile translations + uses: ./.github/actions/build-translations - name: 🔦 Generate stats file for PR run: | @@ -81,7 +83,14 @@ jobs: if: ${{ !steps.get-base-stats.outputs.cache-hit }} run: | yarn install - yarn intl:build + + - name: 🔤 Compile translations (base) + if: ${{ !steps.get-base-stats.outputs.cache-hit }} + uses: ./.github/actions/build-translations + + - name: 🔦 Generate base stats + if: ${{ !steps.get-base-stats.outputs.cache-hit }} + run: | yarn generate-webpack-stats-file mv stats.json stats-base.json