From 6d2c84bead99b346068635faa1f4017b7d65441b Mon Sep 17 00:00:00 2001 From: Julian Dominguez-Schatz Date: Tue, 7 Jan 2025 20:30:00 -0500 Subject: [PATCH] Pull/push strings via Git instead of via API --- .github/actions/setup/action.yml | 23 ++++- .../workflows/i18n-string-extract-master.yml | 98 ++++++++++++++----- upcoming-release-notes/4089.md | 6 ++ 3 files changed, 98 insertions(+), 29 deletions(-) create mode 100644 upcoming-release-notes/4089.md diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 2899f9b149f..77e4348ef53 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -1,5 +1,17 @@ name: Setup +inputs: + working-directory: + description: 'Working directory to run in, default .' + required: false + default: . + type: string + download-translations: + description: 'Whether to download translations as part of setup, default true' + required: false + default: true + type: boolean + runs: using: composite steps: @@ -15,9 +27,16 @@ runs: uses: actions/cache@v4 id: cache with: - path: '**/node_modules' - key: yarn-v1-${{ runner.os }}-${{ hashFiles('.nvmrc') }}-${{ hashFiles('**/yarn.lock') }} + path: ${{ format('{0}/**/node_modules', inputs.working-directory) }} + key: yarn-v1-${{ runner.os }}-${{ hashFiles(format('{0}/.nvmrc', inputs.working-directory)) }}-${{ hashFiles(format('{0}/**/yarn.lock', inputs.working-directory)) }} - name: Install + working-directory: ${{ inputs.working-directory }} run: yarn --immutable shell: bash if: steps.cache.outputs.cache-hit != 'true' + - name: Download translations + uses: actions/checkout@v4 + with: + repository: actualbudget/translations + path: ${{ inputs.working-directory }}/packages/desktop-client/locale + if: ${{ inputs.download-translations }} diff --git a/.github/workflows/i18n-string-extract-master.yml b/.github/workflows/i18n-string-extract-master.yml index ed413cd4703..b12a98931b2 100644 --- a/.github/workflows/i18n-string-extract-master.yml +++ b/.github/workflows/i18n-string-extract-master.yml @@ -1,36 +1,80 @@ name: Extract and upload i18n strings on: - push: - branches: - - master + schedule: + # 4am UTC + - cron: "0 4 * * *" workflow_dispatch: jobs: extract-and-upload-i18n-strings: runs-on: ubuntu-latest + if: github.repository == 'actualbudget/actual' steps: - - uses: actions/checkout@v4 - - name: Set up environment - uses: ./.github/actions/setup - - name: Configure i18n client - run: | - pip install wlc - - name: Generate i18n strings - run: yarn generate:i18n - - name: Upload i18n strings - run: | - if [[ ! -f packages/desktop-client/locale/en.json ]]; then - echo "File packages/desktop-client/locale/en.json not found. Ensure the file was generated correctly." - exit 1 - fi - wlc \ - --url https://hosted.weblate.org/api/ \ - --key "${{ secrets.WEBLATE_API_KEY_CI_STRINGS }}" \ - upload \ - --author-name "Actual Budget" \ - --author-email "dev@actualbudget.org" \ - --method add \ - --input packages/desktop-client/locale/en.json \ - actualbudget/actual/en - echo "Translations uploaded" + - name: Check out main repository + uses: actions/checkout@v4 + with: + path: actual + - name: Set up environment + uses: ./actual/.github/actions/setup + with: + working-directory: actual + download-translations: false # As we'll manually clone instead + - name: Configure Git config + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Configure i18n client + run: | + pip install wlc + + - name: Lock translations + run: | + wlc \ + --url https://hosted.weblate.org/api/ \ + --key "${{ secrets.WEBLATE_API_KEY_CI_STRINGS }}" \ + lock \ + actualbudget/actual + + - name: Update VCS with latest translations + run: | + wlc \ + --url https://hosted.weblate.org/api/ \ + --key "${{ secrets.WEBLATE_API_KEY_CI_STRINGS }}" \ + pull \ + actualbudget/actual + - name: Check out updated translations + uses: actions/checkout@v4 + with: + ssh-key: ${{ secrets.STRING_IMPORT_DEPLOY_KEY }} + repository: actualbudget/translations + path: translations + - name: Generate i18n strings + working-directory: actual + run: | + mkdir -p packages/desktop-client/locale/ + cp ../translations/en.json packages/desktop-client/locale/ + yarn generate:i18n + if [[ ! -f packages/desktop-client/locale/en.json ]]; then + echo "File packages/desktop-client/locale/en.json not found. Ensure the file was generated correctly." + exit 1 + fi + - name: Check in new i18n strings + working-directory: translations + run: | + cp ../actual/packages/desktop-client/locale/en.json . + git add . + if git commit -m "Update source strings"; then + git push + else + echo "No changes to commit" + fi + + - name: Unlock translations + if: always() # Clean up even on failure + run: | + wlc \ + --url https://hosted.weblate.org/api/ \ + --key "${{ secrets.WEBLATE_API_KEY_CI_STRINGS }}" \ + unlock \ + actualbudget/actual diff --git a/upcoming-release-notes/4089.md b/upcoming-release-notes/4089.md new file mode 100644 index 00000000000..5d57e5ea790 --- /dev/null +++ b/upcoming-release-notes/4089.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [jfdoming] +--- + +Include translations in builds