|
| 1 | +--- |
| 2 | +# Syncs Crowdin distribution files from distributions.crowdin.net to a |
| 3 | +# dedicated git branch (dist) served via jsDelivr CDN. |
| 4 | +# |
| 5 | +# proxy-translator.js fetches manifest.json, languages.json and all translation |
| 6 | +# JSON files from https://distributions.crowdin.net. Those requests count |
| 7 | +# against the LizardByte Crowdin free-tier quota, so we mirror the content |
| 8 | +# here (refreshed daily) and redirect browser fetch() calls to jsDelivr via |
| 9 | +# the interceptor in src/js/crowdin.js. |
| 10 | +# |
| 11 | +# jsDelivr CDN URL pattern: |
| 12 | +# https://cdn.jsdelivr.net/gh/LizardByte/i18n@dist/<hash>/… |
| 13 | +# |
| 14 | +# jsDelivr guarantees Access-Control-Allow-Origin: * on all responses, which |
| 15 | +# means no CORS plugin is required in consumer pages. |
| 16 | + |
| 17 | +name: Sync Crowdin Distribution |
| 18 | +permissions: {} |
| 19 | + |
| 20 | +on: |
| 21 | + schedule: |
| 22 | + # Run daily at 02:00 UTC so translations are fresh at the start of each day. |
| 23 | + - cron: '0 2 * * *' |
| 24 | + workflow_dispatch: # Allow ad-hoc manual runs |
| 25 | + |
| 26 | +# Only one deployment at a time; do not cancel an in-progress run. |
| 27 | +concurrency: |
| 28 | + group: crowdin-dist-sync |
| 29 | + cancel-in-progress: false |
| 30 | + |
| 31 | +jobs: |
| 32 | + sync: |
| 33 | + name: Sync distributions to crowdin-dist branch |
| 34 | + runs-on: ubuntu-latest |
| 35 | + permissions: |
| 36 | + contents: write |
| 37 | + environment: |
| 38 | + name: crowdin-dist |
| 39 | + url: ${{ github.server_url }}/${{ github.repository }}/tree/dist |
| 40 | + if: github.repository_owner == 'LizardByte' # don't run for forks |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 45 | + with: |
| 46 | + token: ${{ secrets.GH_BOT_TOKEN }} |
| 47 | + |
| 48 | + - name: Set up Node.js |
| 49 | + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 |
| 50 | + with: |
| 51 | + node-version: 'node' |
| 52 | + |
| 53 | + - name: Download Crowdin distribution files |
| 54 | + env: |
| 55 | + CROWDIN_DISTRIBUTION_IDS: ${{ vars.CROWDIN_DISTRIBUTION_IDS }} |
| 56 | + OUTPUT_DIR: /tmp/dist |
| 57 | + run: node src/sync-crowdin-distribution.cjs |
| 58 | + |
| 59 | + - name: Commit and push to dist branch |
| 60 | + env: |
| 61 | + GH_BOT_NAME: ${{ vars.GH_BOT_NAME }} |
| 62 | + GH_BOT_EMAIL: ${{ secrets.GH_BOT_EMAIL }} |
| 63 | + run: | |
| 64 | + git config user.name "${GH_BOT_NAME}" |
| 65 | + git config user.email "${GH_BOT_EMAIL}" |
| 66 | +
|
| 67 | + # Create an orphan branch so the branch contains only distribution |
| 68 | + # files with no history from main (keeps the branch lean). |
| 69 | + git checkout --orphan dist |
| 70 | +
|
| 71 | + # Remove every file that was inherited from the main checkout. |
| 72 | + git rm -rf . --quiet |
| 73 | +
|
| 74 | + # Clean up any remaining untracked files / directories. |
| 75 | + git clean -fdx |
| 76 | +
|
| 77 | + # Populate the branch with the freshly downloaded distribution files. |
| 78 | + cp -r /tmp/dist/. . |
| 79 | +
|
| 80 | + git add . |
| 81 | +
|
| 82 | + # Only commit when there are actual changes. |
| 83 | + if git diff --staged --quiet; then |
| 84 | + echo "No changes – distribution files are already up to date." |
| 85 | + else |
| 86 | + git commit -m "chore: sync Crowdin distributions" |
| 87 | + git push origin dist --force |
| 88 | + fi |
0 commit comments