name: Release # Whichever of the two finishes last on a commit of main triggers the release, once both succeeded, # provided that commit is still main's latest: the release jobs check out `github.sha`, main's latest commit on: workflow_run: workflows: ["Tests", "Linting and typings"] types: - completed branches: - main # reset permissions and explicitly specify them for each job permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} jobs: gate: if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest outputs: ready: ${{ steps.check.outputs.ready }} permissions: actions: read # to read the runs of both workflows steps: - name: Check that Tests and Linting and typings succeeded on this commit id: check env: GH_TOKEN: ${{ github.token }} SHA: ${{ github.event.workflow_run.head_sha }} run: | if [ "$SHA" != "$GITHUB_SHA" ]; then echo "main has moved on to $GITHUB_SHA: its own runs will release it" echo "ready=false" >> "$GITHUB_OUTPUT" exit 0 fi ready=true for workflow in tests.yml lint-and-types.yml; do conclusion=$(gh api "repos/${{ github.repository }}/actions/workflows/$workflow/runs?head_sha=$SHA&per_page=1" --jq '.workflow_runs[0].conclusion // ""') echo "$workflow: ${conclusion:-not finished}" [ "$conclusion" = "success" ] || ready=false done echo "ready=$ready" >> "$GITHUB_OUTPUT" select-mode: needs: gate if: needs.gate.outputs.ready == 'true' runs-on: ubuntu-latest outputs: mode: ${{ steps.select-mode.outputs.mode }} publish-plan-artifact-id: ${{ steps.select-mode.outputs.publish-plan-artifact-id }} permissions: contents: read # to check out repo (actions/checkout) steps: - uses: actions/checkout@v7 with: persist-credentials: false - uses: pnpm/action-setup@v6 - name: Setup Node uses: actions/setup-node@v7 with: node-version: 24 package-manager-cache: false - name: Install dependencies run: pnpm i - name: Select Changesets mode id: select-mode uses: changesets/action/select-mode@v2 version: if: needs.select-mode.outputs.mode == 'version' needs: select-mode runs-on: ubuntu-latest permissions: contents: write # to commit version changes (changesets/action/version) pull-requests: write # to create the release pull request (changesets/action/version) steps: - uses: actions/checkout@v7 with: persist-credentials: false - uses: pnpm/action-setup@v6 - name: Setup Node uses: actions/setup-node@v7 with: node-version: 24 package-manager-cache: false - name: Install dependencies run: pnpm i - name: Version packages uses: changesets/action/version@v2 with: script: pnpm run version-packages pack: if: needs.select-mode.outputs.mode == 'publish' needs: select-mode runs-on: ubuntu-latest outputs: pack-dir-artifact-id: ${{ steps.pack.outputs.pack-dir-artifact-id }} permissions: contents: read # to check out repo (actions/checkout) steps: - uses: actions/checkout@v7 with: persist-credentials: false - uses: pnpm/action-setup@v6 - name: Setup Node uses: actions/setup-node@v7 with: node-version: 24 package-manager-cache: false - name: Install dependencies run: pnpm i - name: Build packages run: pnpm run build - name: Pack packages id: pack uses: changesets/action/pack@v2 with: publish-plan-artifact-id: ${{ needs.select-mode.outputs.publish-plan-artifact-id }} publish: needs: pack runs-on: ubuntu-latest permissions: contents: write # to push git tags and create GitHub releases (changesets/action/publish) id-token: write # for npm trusted publishing (OIDC) steps: - uses: actions/checkout@v7 with: persist-credentials: false - uses: pnpm/action-setup@v6 - name: Setup Node uses: actions/setup-node@v7 with: node-version: 24 package-manager-cache: false - name: Install dependencies run: pnpm i - name: Publish packages uses: changesets/action/publish@v2 with: pack-dir-artifact-id: ${{ needs.pack.outputs.pack-dir-artifact-id }} # Once per commit: only the run whose gate passed deploys, after its release jobs, unless one of them failed docs: needs: [gate, select-mode, version, pack, publish] if: ${{ !cancelled() && needs.gate.outputs.ready == 'true' && !contains(needs.*.result, 'failure') }} permissions: contents: read # to check out repo (actions/checkout) pages: write # to deploy to GitHub Pages (actions/deploy-pages) id-token: write # to authenticate the Pages deployment (actions/deploy-pages) concurrency: group: pages cancel-in-progress: false uses: ./.github/workflows/deploy.yml