11# This action automates the synchronization of our crowdin translations, so that a human does not need to kick it off from the crowdin UI
2+ # It also formats incoming content because it is often not adherent to our rules post-translation.
3+
24# See translations-upload.yml for automation to upload our source content
3- # See translations-pr-lint-and-format .yml for quality control we conduct on ingress of new translations.
5+ # See translations-pr-lint.yml for quality control we conduct on ingress of new translations.
46name : Crowdin Download
57
68on :
2830 with :
2931 egress-policy : audit
3032
31- - name : Checkout
32- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33-
3433 # see all the options at https://github.com/crowdin/github-action
35- - name : crowdin action
34+ - name : Crowdin PR
35+ id : crowdin
3636 uses : crowdin/github-action@2d540f18b0a416b1fbf2ee5be35841bd380fc1da # v2.3.0
3737 with :
3838 # do not upload anything - this is a one-way operation download
@@ -44,11 +44,81 @@ jobs:
4444 create_pull_request : true
4545 pull_request_title : ' [automated]: crowdin sync'
4646 pull_request_body : ' New Crowdin translations from the [Node.js Crowdin project](https://crowdin.com/project/nodejs-web)'
47- pull_request_labels : github_actions:pull-request
4847 commit_message : ' chore: synced translations from crowdin'
4948 env :
5049 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5150 # A numeric ID, found at https://crowdin.com/project/nodejs-web/tools/api
5251 CROWDIN_PROJECT_ID : ${{ secrets.CROWDIN_PROJECT_ID }}
5352 # Created from https://crowdin.com/settings#api-key logged in using nodejs-crowdin-bot
5453 CROWDIN_PERSONAL_TOKEN : ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
54+
55+ format_crowdin_pull_request :
56+ runs-on : ubuntu-latest
57+
58+ permissions :
59+ # This permission is required by `stefanzweifel/git-auto-commit-action`
60+ contents : write
61+
62+ steps :
63+ - name : Harden Runner
64+ uses : step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
65+ with :
66+ egress-policy : audit
67+
68+ - name : Git Checkout
69+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
70+ with :
71+ # Use the number from the output of crowdin/github-action
72+ ref : refs/pull/${{ steps.crowdin.outputs.pull_request_number }}/head
73+
74+ - name : Restore Lint Cache
75+ uses : actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
76+ with :
77+ path : |
78+ apps/site/.eslintmdcache
79+ apps/site/.prettiercache
80+ # We want to restore Turborepo Cache and ESlint and Prettier Cache
81+ # The ESLint and Prettier cache's are useful to reduce the overall runtime of ESLint and Prettier
82+ # as they will only run on files that have changed since the last cached run
83+ # this might of course lead to certain files not being checked against the linter, but the chances
84+ # of such situation from happening are very slim as the checksums of both files would need to match
85+ key : cache-lint-${{ hashFiles('package-lock.json') }}-
86+ restore-keys : |
87+ cache-lint-${{ hashFiles('package-lock.json') }}-
88+ cache-lint-
89+
90+ - name : Set up Node.js
91+ uses : actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
92+ with :
93+ # We want to ensure that the Node.js version running here respects our supported versions
94+ node-version-file : ' .nvmrc'
95+ cache : ' npm'
96+
97+ - name : Install npm packages
98+ # We want to avoid npm from running the Audit Step and Funding messages on a CI environment
99+ # We also use `npm i` instead of `npm ci` so that the node_modules/.cache folder doesn't get deleted
100+ run : npm i --no-audit --no-fund --ignore-scripts --userconfig=/dev/null
101+
102+ - name : Run `npx lint:md --fix`
103+ # This runs a specific version of ESLint with only the Translation Pages Globbing
104+ # This avoid that unrelated changes get linted/modified within this PR
105+ run : npx eslint "apps/site/pages/**/*.md?(x)" --fix --cache --cache-strategy=metadata --cache-file=apps/site/.eslintmdcache --config=apps/site/eslint.config.js
106+
107+ - name : Run `npx prettier --write`
108+ # This runs a specific version of Prettier with only the Translation Pages Globbing
109+ # This avoid that unrelated changes get prettied/modified within this PR
110+ run : npx prettier "apps/site/{pages,i18n}/**/*.{json,md,mdx}" --check --write --cache --cache-strategy=metadata --cache-location=apps/site/.prettiercache
111+
112+ - name : Push Changes back to Pull Request
113+ uses : stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 # v5.0.1
114+ with :
115+ commit_options : ' --no-verify --signoff'
116+ commit_message : ' chore: automated format of translated files'
117+
118+ - name : Save Lint Cache
119+ uses : actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
120+ with :
121+ path : |
122+ apps/site/.eslintmdcache
123+ apps/site/.prettiercache
124+ key : cache-lint-${{ hashFiles('package-lock.json') }}-${{ hashFiles('apps/site/.eslintmdcache') }}
0 commit comments