|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Changesets-driven release. On every push to `main`: |
| 4 | +# - if there are pending changesets → opens/updates the "Version Packages" PR |
| 5 | +# (bumps versions, writes CHANGELOGs, deletes changesets) |
| 6 | +# - once that PR is merged (versions bumped, no changesets left) → publishes the |
| 7 | +# changed packages to npm `latest`, tags them, and cuts GitHub Releases. |
| 8 | +# |
| 9 | +# SECURITY: runs only on push to `main` (trusted, post-merge code). Publishing |
| 10 | +# uses npm Trusted Publishing (OIDC) — no long-lived NPM_TOKEN and no 2FA bypass; |
| 11 | +# npm verifies this repo + workflow via GitHub's id-token. Each published package |
| 12 | +# must have this repo + `release.yml` configured as a Trusted Publisher on npm. |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: [main] |
| 17 | + |
| 18 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: write # push the Version Packages PR branch + git tags |
| 22 | + pull-requests: write # open/update the Version Packages PR |
| 23 | + id-token: write # OIDC for npm Trusted Publishing (+ provenance) |
| 24 | + |
| 25 | +jobs: |
| 26 | + release: |
| 27 | + name: Release |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + # Mint a short-lived token from the org-owned GitHub App so the "Version |
| 31 | + # Packages" PR is opened by the App — that makes the required CI checks run |
| 32 | + # on it (a default-GITHUB_TOKEN PR wouldn't trigger workflows). No user PAT. |
| 33 | + - name: Generate GitHub App token |
| 34 | + id: app-token |
| 35 | + uses: actions/create-github-app-token@v1 |
| 36 | + with: |
| 37 | + app-id: ${{ secrets.RELEASE_APP_ID }} |
| 38 | + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} |
| 39 | + |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + token: ${{ steps.app-token.outputs.token }} |
| 45 | + |
| 46 | + - name: Setup pnpm |
| 47 | + uses: pnpm/action-setup@v4 |
| 48 | + |
| 49 | + - name: Setup Node.js |
| 50 | + uses: actions/setup-node@v4 |
| 51 | + with: |
| 52 | + node-version: 20 |
| 53 | + cache: pnpm |
| 54 | + registry-url: https://registry.npmjs.org/ |
| 55 | + |
| 56 | + - name: Install dependencies |
| 57 | + run: pnpm install --frozen-lockfile |
| 58 | + |
| 59 | + # npm Trusted Publishing (OIDC) needs npm >= 11.5.1; node 20 ships npm 10. |
| 60 | + - name: Upgrade npm for OIDC publishing |
| 61 | + run: npm install -g npm@latest |
| 62 | + |
| 63 | + - name: Create Version PR or publish |
| 64 | + uses: changesets/action@v1 |
| 65 | + with: |
| 66 | + version: pnpm changeset:version |
| 67 | + publish: pnpm changeset:release:ci |
| 68 | + env: |
| 69 | + # App token → the Version PR is opened by the App, so the required CI |
| 70 | + # checks run on it and it can push past branch protection. |
| 71 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 72 | + # No NPM_TOKEN: publish auth is npm Trusted Publishing via `id-token`. |
0 commit comments