-
Notifications
You must be signed in to change notification settings - Fork 1
144 lines (122 loc) · 5.49 KB
/
Copy pathrelease.yml
File metadata and controls
144 lines (122 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Release pipeline. Two jobs so the OIDC credential exists only where it is used:
# - version: opens/updates the Changesets "Version Packages" PR and decides whether a
# release is due. No id-token here.
# - publish: runs only when an unpublished version is on main, behind a manual
# `release` Environment gate, and is the ONLY job that can mint an npm OIDC token.
#
# Security boundary for a real publish = Version PR merge + main branch protection +
# the `release` Environment approval. This is the workflow file registered as the npm
# Trusted Publisher (settings on npmjs.com must reference `release.yml`).
name: Release
on:
push:
branches: [main]
workflow_dispatch:
# Never cancel a release mid-publish.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
version:
name: Version PR & publish gate
runs-on: ubuntu-latest
permissions:
contents: write # changesets/action commits + pushes the version branch
pull-requests: write # opens/updates the Version PR
outputs:
should_publish: ${{ steps.gate.outputs.should_publish }}
steps:
# persist-credentials stays default (true): changesets/action pushes the version
# branch using the checkout-provided git credentials.
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
- name: Install dependencies
run: bun install --frozen-lockfile --ignore-scripts
# Runs BEFORE changesets/action mutates the working tree, so it reads the COMMITTED
# versions and compares them to the registry. should_publish=true only on a
# Version-PR-merge commit (versions bumped, changesets consumed). Fail-closed.
- name: Publish gate (should_publish)
id: gate
run: bun run scripts/publish.ts --check
- name: Create or update the Version PR
uses: changesets/action@a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d # v1.9.0
with:
version: bun run version
# No `publish:` input — publishing is the separate, OIDC-gated job below.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish to npm (OIDC + provenance)
needs: version
if: needs.version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
environment: release # manual approval gate (configure required reviewers)
permissions:
contents: read
id-token: write # OIDC trusted publishing — the credential is scoped to this job only
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false # publish auth is OIDC, not git
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "22" # latest 22.x (OIDC trusted publishing requires >= 22.14)
registry-url: "https://registry.npmjs.org"
# OIDC trusted publishing requires npm >= 11.5.1; pin it explicitly.
- name: Pin npm
run: npm install -g npm@11.5.1
- name: Assert toolchain
run: |
node --version
npm --version
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)"
- name: Install dependencies
run: bun install --frozen-lockfile --ignore-scripts
- name: Build
run: bun run build
- name: Pre-publish gates (publint + are-the-types-wrong)
run: |
bun run publint
bun run attw
- name: Clean-room install smoke test
run: bun run scripts/smoke.ts
# Ordered npm publish (compiler → tskm → vite) with workspace:* rewrite, fail-closed
# idempotency, and a workspace:-leak guard. OIDC + provenance are automatic here.
- name: Publish
run: bun run release
# Tags + GitHub Releases live in a third job so the OIDC-bearing publish job keeps
# contents: read. `changeset tag` prints "New tag: <pkg>@<version>" for every missing
# tag; changesets/action parses those lines, pushes the tags, and creates one GitHub
# Release per package from its CHANGELOG.md section (createGithubReleases defaults to
# true). Already-tagged versions produce no output, so re-runs are no-ops.
github_release:
name: Tag & GitHub Releases
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write # push tags + create releases
steps:
# Full history so existing tags are fetched; without them `changeset tag` would
# re-create (and fail to push) tags that already exist on the remote.
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
- name: Install dependencies
run: bun install --frozen-lockfile --ignore-scripts
- name: Create tags and GitHub Releases
uses: changesets/action@a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d # v1.9.0
with:
publish: bun run changeset tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}