|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +# The site used to be built by Vercel's git integration, in a single build that |
| 4 | +# walked the 13 locales one after another — Docusaurus has no parallel mode. |
| 5 | +# Here every locale is built by its own job instead, and only the finished |
| 6 | +# static files are handed to Vercel (`vercel deploy --prebuilt`), so the wall |
| 7 | +# clock is the slowest single locale rather than the sum of all of them. |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: [main] |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + production: |
| 15 | + description: Publish on pnpm.io. Turn this off to get a preview URL instead. |
| 16 | + type: boolean |
| 17 | + default: true |
| 18 | + |
| 19 | +# A deploy always ships the whole site, so an in-flight one is pointless as |
| 20 | +# soon as a newer commit lands. |
| 21 | +concurrency: |
| 22 | + group: deploy |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +# Nothing here writes to the repository; the deploy goes out through Vercel. |
| 26 | +permissions: |
| 27 | + contents: read |
| 28 | + |
| 29 | +env: |
| 30 | + COREPACK_ENABLE_AUTO_PIN: 0 |
| 31 | + |
| 32 | +jobs: |
| 33 | + locales: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + outputs: |
| 36 | + locales: ${{ steps.read.outputs.locales }} |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + - id: read |
| 40 | + run: echo "locales=$(jq -c '[.[].locale]' locales.json)" >> "$GITHUB_OUTPUT" |
| 41 | + |
| 42 | + build: |
| 43 | + needs: locales |
| 44 | + runs-on: ubuntu-latest |
| 45 | + environment: deploy |
| 46 | + strategy: |
| 47 | + # One broken locale shouldn't hide the state of the other twelve; the |
| 48 | + # deploy job below refuses to ship an incomplete site anyway. |
| 49 | + fail-fast: false |
| 50 | + matrix: |
| 51 | + locale: ${{ fromJSON(needs.locales.outputs.locales) }} |
| 52 | + name: build (${{ matrix.locale }}) |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + # `showLastUpdateTime` reads the dates from the git history. |
| 57 | + fetch-depth: 0 |
| 58 | + - uses: pnpm/action-setup@v4.1.0 |
| 59 | + with: |
| 60 | + standalone: true |
| 61 | + - uses: actions/setup-node@v4 |
| 62 | + with: |
| 63 | + node-version: 22 |
| 64 | + cache: pnpm |
| 65 | + - run: pnpm install |
| 66 | + - name: Copy the current docs into the latest version |
| 67 | + # Crowdin maps the translations of the latest docs version onto this |
| 68 | + # copy, so it has to exist before the download below. |
| 69 | + run: pnpm copy-docs |
| 70 | + - name: Download the translations |
| 71 | + if: matrix.locale != 'en' |
| 72 | + run: | |
| 73 | + language=$(jq -r --arg locale "$LOCALE" '.[] | select(.locale == $locale) | .crowdinLanguage // empty' locales.json) |
| 74 | + test -n "$language" # locales.json must name the language for Crowdin |
| 75 | + pnpm exec crowdin download --language "$language" --no-progress --no-colors |
| 76 | + env: |
| 77 | + LOCALE: ${{ matrix.locale }} |
| 78 | + CROWDIN_PROJECT_ID: ${{ vars.CROWDIN_PROJECT_ID || '302994' }} |
| 79 | + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} |
| 80 | + - name: Build |
| 81 | + run: node scripts/build-with-fallback.mjs --locale "$LOCALE" |
| 82 | + env: |
| 83 | + LOCALE: ${{ matrix.locale }} |
| 84 | + - uses: actions/upload-artifact@v4 |
| 85 | + with: |
| 86 | + name: site-${{ matrix.locale }} |
| 87 | + path: build |
| 88 | + retention-days: 1 |
| 89 | + # The files are already minified; compressing them again costs more |
| 90 | + # time than it saves on the transfer. |
| 91 | + compression-level: 0 |
| 92 | + |
| 93 | + deploy: |
| 94 | + needs: build |
| 95 | + runs-on: ubuntu-latest |
| 96 | + environment: deploy |
| 97 | + steps: |
| 98 | + - uses: actions/checkout@v4 |
| 99 | + - uses: pnpm/action-setup@v4.1.0 |
| 100 | + with: |
| 101 | + standalone: true |
| 102 | + - uses: actions/setup-node@v4 |
| 103 | + with: |
| 104 | + node-version: 22 |
| 105 | + - name: Collect every locale |
| 106 | + uses: actions/download-artifact@v4 |
| 107 | + with: |
| 108 | + pattern: site-* |
| 109 | + # Each locale occupies its own subtree, so they merge into the single |
| 110 | + # directory the site is served from. |
| 111 | + merge-multiple: true |
| 112 | + path: .site-artifacts |
| 113 | + - name: Deploy to Vercel |
| 114 | + # `vercel build` doesn't rebuild the site: vercel.json points its build |
| 115 | + # command at scripts/assemble-site.mjs, which just moves the artifacts |
| 116 | + # into place. It is still needed to turn vercel.json into a deployment. |
| 117 | + run: | |
| 118 | + # esbuild, which the CLI depends on, has to run its install script. |
| 119 | + vercel () { pnpm dlx --allow-build=esbuild vercel@59.1.4 "$@"; } |
| 120 | + if [ "$PRODUCTION" = 'true' ]; then |
| 121 | + environment=production |
| 122 | + prod=--prod |
| 123 | + else |
| 124 | + environment=preview |
| 125 | + prod= |
| 126 | + fi |
| 127 | + vercel pull --yes --environment="$environment" --token="$VERCEL_TOKEN" |
| 128 | + vercel build $prod --token="$VERCEL_TOKEN" |
| 129 | + url=$(vercel deploy --prebuilt $prod --token="$VERCEL_TOKEN" | tail -n1) |
| 130 | + echo "Deployed $url" >> "$GITHUB_STEP_SUMMARY" |
| 131 | + env: |
| 132 | + PRODUCTION: ${{ github.event_name != 'workflow_dispatch' || inputs.production }} |
| 133 | + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} |
| 134 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 135 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} |
0 commit comments