Skip to content

Commit ba60384

Browse files
committed
fix(crowdin): workflow improvements
1 parent fd87584 commit ba60384

File tree

1 file changed

+39
-52
lines changed

1 file changed

+39
-52
lines changed

.github/workflows/translations-sync.yml

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@
33

44
# See translations-upload.yml for automation to upload our source content
55
# See translations-pr-lint.yml for quality control we conduct on ingress of new translations.
6-
name: Crowdin Download
6+
name: Crowdin Translations Sync
77

88
on:
9-
workflow_dispatch: # Allow running when we want to, for events such as urgent translation mistakes or 100% completed languages
9+
workflow_dispatch: # Manual trigger for urgent fixes
1010
schedule:
11-
- cron: '0 5 * * 5' # At 05:00 on Fridays. This guarantees that we have the 72 hour weekend time to review translations.
11+
- cron: '0 5 * * 5' # Fridays at 05:00 UTC, allowing weekend review time
1212

1313
# Cancel any runs on the same branch
1414
concurrency:
1515
group: ${{ github.workflow }}-${{ github.ref }}
1616
cancel-in-progress: true
1717

18-
permissions:
19-
contents: read
18+
permissions: {}
19+
20+
env:
21+
COMMIT_MSG: 'chore: sync translations from crowdin'
22+
HEAD_REF: chore/crowdin
2023

2124
jobs:
22-
synchronize-with-crowdin:
25+
sync-translations:
2326
runs-on: ubuntu-latest
2427
outputs:
25-
pull_request_number: ${{ steps.crowdin_pr.outputs.pull_request_number }}
26-
28+
pr_number: ${{ steps.crowdin_pr.outputs.pull_request_number }}
2729
steps:
2830
- name: Harden Runner
2931
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
@@ -35,48 +37,41 @@ jobs:
3537
with:
3638
token: ${{ secrets.CROWDIN_GITHUB_BOT_TOKEN }}
3739

38-
# see all the options at https://github.com/crowdin/github-action
39-
- name: Crowdin PR
40-
uses: crowdin/github-action@b8012bd5491b8aa8578b73ab5b5f5e7c94aaa6e2 # v2.7.0
40+
# Downloads translations from Crowdin and creates a PR
41+
# See all the options at https://github.com/crowdin/github-action
42+
- name: Download Translations & Create PR
4143
id: crowdin_pr
44+
uses: crowdin/github-action@b8012bd5491b8aa8578b73ab5b5f5e7c94aaa6e2 # v2.7.0
4245
with:
43-
# do not upload anything - this is a one-way operation download
4446
upload_sources: false
4547
upload_translations: false
46-
# the rest of this controls how the PR comes in with new translations
4748
download_translations: true
48-
localization_branch_name: chore/crowdin
49+
localization_branch_name: ${{ env.HEAD_REF }}
4950
create_pull_request: true
50-
pull_request_title: '[automated]: crowdin sync'
51-
pull_request_body: 'New Crowdin translations from the [Node.js Crowdin project](https://crowdin.com/project/nodejs-web)'
52-
commit_message: 'chore: synced translations from crowdin'
51+
pull_request_title: '[automated]: Crowdin Translations Sync'
52+
pull_request_body: 'New translations from the [Node.js Crowdin project](https://crowdin.com/project/nodejs-web)'
53+
commit_message: ${{ env.COMMIT_MSG }}
5354
env:
5455
GITHUB_TOKEN: ${{ secrets.CROWDIN_GITHUB_BOT_TOKEN }}
55-
# A numeric ID, found at https://crowdin.com/project/nodejs-web/tools/api
5656
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
57-
# Created from https://crowdin.com/settings#api-key logged in using nodejs-crowdin-bot
5857
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
5958

60-
format_crowdin_pull_request:
61-
needs: synchronize-with-crowdin
59+
format-translations:
60+
needs: sync-translations
6261
runs-on: ubuntu-latest
63-
64-
permissions:
65-
# This permission is required by `stefanzweifel/git-auto-commit-action`
66-
contents: write
67-
6862
steps:
6963
- name: Harden Runner
70-
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
64+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0
7165
with:
7266
egress-policy: audit
7367

74-
- name: Git Checkout
75-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
68+
# Checks out the PR branch created by the previous job
69+
- name: Checkout PR Branch
70+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
7671
with:
77-
# Use the number from the output of crowdin/github-action
78-
ref: refs/pull/${{ needs.synchronize-with-crowdin.outputs.pull_request_number }}/head
72+
ref: refs/pull/${{ needs.sync-translations.outputs.pr_number }}/head
7973
token: ${{ secrets.CROWDIN_GITHUB_BOT_TOKEN }}
74+
fetch-depth: 0
8075

8176
- name: Restore Lint Cache
8277
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
@@ -109,27 +104,19 @@ jobs:
109104
- name: Install packages
110105
run: pnpm install --frozen-lockfile
111106

112-
- name: Run `lint:md --fix`
113-
# This runs a specific version of ESLint with only the Translation Pages Globbing
114-
# This avoid that unrelated changes get linted/modified within this PR
115-
run: pnpm exec eslint "apps/site/pages/**/*.md?(x)" --fix --cache --cache-strategy=metadata --cache-file=apps/site/.eslintmdcache --config=apps/site/eslint.config.js
107+
# Re-stage latest commit and run lint-staged
108+
- name: Re-stage and Format Files
109+
run: |
110+
# Soft reset to unstage the commit but keep changes
111+
git reset --soft HEAD^
116112
117-
- name: Run `prettier --write`
118-
# This runs a specific version of Prettier with only the Translation Pages Globbing
119-
# This avoid that unrelated changes get prettied/modified within this PR
120-
run: pnpm exec prettier "apps/site/{pages,i18n}/**/*.{json,md,mdx}" --check --write --cache --cache-strategy=metadata --cache-location=apps/site/.prettiercache
113+
# Run lint-staged on the staged files
114+
# This will run linters/formatters only on changed files
115+
# according to the configuration in package.json or .lintstagedrc
116+
pnpm lint-staged
121117
122-
- name: Push Changes back to Pull Request
123-
uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5.2.0
124-
with:
125-
commit_options: '--no-verify --signoff'
126-
commit_message: 'chore: automated format of translated files'
127-
branch: 'chore/crowdin'
118+
git commit -m "$COMMIT_MSG" --signoff
128119
129-
- name: Save Lint Cache
130-
uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
131-
with:
132-
path: |
133-
apps/site/.eslintmdcache
134-
apps/site/.prettiercache
135-
key: cache-lint-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('apps/site/.eslintmdcache') }}
120+
# Push the changes back to the PR branch
121+
- name: Push Changes
122+
run: git push origin HEAD:$HEAD_REF

0 commit comments

Comments
 (0)