|
| 1 | +# Release pipeline. Two jobs so the OIDC credential exists only where it is used: |
| 2 | +# - version: opens/updates the Changesets "Version Packages" PR and decides whether a |
| 3 | +# release is due. No id-token here. |
| 4 | +# - publish: runs only when an unpublished version is on main, behind a manual |
| 5 | +# `release` Environment gate, and is the ONLY job that can mint an npm OIDC token. |
| 6 | +# |
| 7 | +# Security boundary for a real publish = Version PR merge + main branch protection + |
| 8 | +# the `release` Environment approval. This is the workflow file registered as the npm |
| 9 | +# Trusted Publisher (settings on npmjs.com must reference `release.yml`). |
| 10 | +name: Release |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: [main] |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +# Never cancel a release mid-publish. |
| 18 | +concurrency: |
| 19 | + group: release-${{ github.ref }} |
| 20 | + cancel-in-progress: false |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | +jobs: |
| 26 | + version: |
| 27 | + name: Version PR & publish gate |
| 28 | + runs-on: ubuntu-latest |
| 29 | + permissions: |
| 30 | + contents: write # changesets/action commits + pushes the version branch |
| 31 | + pull-requests: write # opens/updates the Version PR |
| 32 | + outputs: |
| 33 | + should_publish: ${{ steps.gate.outputs.should_publish }} |
| 34 | + steps: |
| 35 | + # persist-credentials stays default (true): changesets/action pushes the version |
| 36 | + # branch using the checkout-provided git credentials. |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 39 | + |
| 40 | + - name: Setup Bun |
| 41 | + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + run: bun install --frozen-lockfile --ignore-scripts |
| 45 | + |
| 46 | + # Runs BEFORE changesets/action mutates the working tree, so it reads the COMMITTED |
| 47 | + # versions and compares them to the registry. should_publish=true only on a |
| 48 | + # Version-PR-merge commit (versions bumped, changesets consumed). Fail-closed. |
| 49 | + - name: Publish gate (should_publish) |
| 50 | + id: gate |
| 51 | + run: bun run scripts/publish.ts --check |
| 52 | + |
| 53 | + - name: Create or update the Version PR |
| 54 | + uses: changesets/action@63a615b9cd06ba9a3e6d13796c7fbcb080a60a0b # v1.8.0 |
| 55 | + with: |
| 56 | + version: bun run version |
| 57 | + # No `publish:` input — publishing is the separate, OIDC-gated job below. |
| 58 | + env: |
| 59 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + publish: |
| 62 | + name: Publish to npm (OIDC + provenance) |
| 63 | + needs: version |
| 64 | + if: needs.version.outputs.should_publish == 'true' |
| 65 | + runs-on: ubuntu-latest |
| 66 | + environment: release # manual approval gate (configure required reviewers) |
| 67 | + permissions: |
| 68 | + contents: read |
| 69 | + id-token: write # OIDC trusted publishing — the credential is scoped to this job only |
| 70 | + steps: |
| 71 | + - name: Checkout |
| 72 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 73 | + with: |
| 74 | + persist-credentials: false # publish auth is OIDC, not git |
| 75 | + |
| 76 | + - name: Setup Bun |
| 77 | + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 |
| 78 | + |
| 79 | + - name: Setup Node |
| 80 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 81 | + with: |
| 82 | + node-version: "22" # latest 22.x (OIDC trusted publishing requires >= 22.14) |
| 83 | + registry-url: "https://registry.npmjs.org" |
| 84 | + |
| 85 | + # OIDC trusted publishing requires npm >= 11.5.1; pin it explicitly. |
| 86 | + - name: Pin npm |
| 87 | + run: npm install -g npm@11.5.1 |
| 88 | + |
| 89 | + - name: Assert toolchain |
| 90 | + run: | |
| 91 | + node --version |
| 92 | + npm --version |
| 93 | + node -e "const v=process.versions.node.split('.').map(Number); if (v[0]<22 || (v[0]===22 && v[1]<14)) throw new Error('Node >= 22.14 required for OIDC, got '+process.versions.node)" |
| 94 | +
|
| 95 | + - name: Install dependencies |
| 96 | + run: bun install --frozen-lockfile --ignore-scripts |
| 97 | + |
| 98 | + - name: Build |
| 99 | + run: bun run build |
| 100 | + |
| 101 | + - name: Pre-publish gates (publint + are-the-types-wrong) |
| 102 | + run: | |
| 103 | + bun run publint |
| 104 | + bun run attw |
| 105 | +
|
| 106 | + - name: Clean-room install smoke test |
| 107 | + run: bun run scripts/smoke.ts |
| 108 | + |
| 109 | + # Ordered npm publish (compiler → tskm → vite) with workspace:* rewrite, fail-closed |
| 110 | + # idempotency, and a workspace:-leak guard. OIDC + provenance are automatic here. |
| 111 | + - name: Publish |
| 112 | + run: bun run release |
0 commit comments