-
Notifications
You must be signed in to change notification settings - Fork 61
358 lines (309 loc) · 12.1 KB
/
release.yml
File metadata and controls
358 lines (309 loc) · 12.1 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
name: Release
on:
push:
# Release branches only.
branches:
- 'main'
- 'next-minor'
- 'changeset-release/main'
- 'changeset-release/next-minor'
tags-ignore:
- '**'
pull_request:
# Canary releases are opt-in via the "release canary" label.
types: [labeled]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
id-token: write # Required for OIDC
contents: write
pull-requests: write
checks: write
statuses: write
jobs:
release-main:
if: github.repository == 'primer/brand' && github.ref_name == 'main'
name: Main
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
persist-credentials: false
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: 24.14.1
- name: Install dependencies
run: npm ci
- uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
id: app-token
with:
app-id: ${{ vars.PRIMER_APP_ID_SHARED }}
private-key: ${{ secrets.PRIMER_APP_PRIVATE_KEY_SHARED }}
- name: Build
run: npm run build:lib
- name: Create release pull request or publish to npm
id: changesets
# Uses SHA for security hardening
# Please keep this up-to-date if you're changing the SHA below
uses: changesets/action@6a0a831ff30acef54f2c6aa1cbbc1096b066edaf # v1.7.0
with:
title: Release tracking
publish: npm run release
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
release-next-minor:
if: github.repository == 'primer/brand' && github.ref_name == 'next-minor'
name: Next minor
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
persist-credentials: false
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: 24.14.1
- name: Install dependencies
run: npm ci
- uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
id: app-token
with:
app-id: ${{ vars.PRIMER_APP_ID_SHARED }}
private-key: ${{ secrets.PRIMER_APP_PRIVATE_KEY_SHARED }}
- name: Build
run: npm run build:lib
- name: Create release pull request or publish to npm
id: changesets
# Uses SHA for security hardening
# Please keep this up-to-date if you're changing the SHA below
uses: changesets/action@6a0a831ff30acef54f2c6aa1cbbc1096b066edaf # v1.7.0
with:
title: Release tracking (next minor)
publish: npm run release
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
release-candidate:
if: github.repository == 'primer/brand' && github.ref_name == 'changeset-release/main'
name: Candidate
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: 24.14.1
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build:lib
- name: Publish release candidate
run: |
npm exec --workspaces -- ../../packages/repo-configs/scripts/prepare-release-candidate
npm exec -- changeset publish --tag next
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Output release candidate version
uses: actions/github-script@v8
with:
script: |
for (const path of ['react', 'design-tokens', 'css']) {
const pkg = require(`${process.env.GITHUB_WORKSPACE}/packages/${path}/package.json`)
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: 'success',
context: `Published ${pkg.name}`,
description: pkg.version,
target_url: `https://unpkg.com/${pkg.name}@${pkg.version}/`
})
}
release-candidate-next-minor:
if: github.repository == 'primer/brand' && github.ref_name == 'changeset-release/next-minor'
name: Next minor candidate (@next-minor)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: 24.14.1
- name: Install dependencies
run: npm ci
- uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
id: app-token
with:
app-id: ${{ vars.PRIMER_APP_ID_SHARED }}
private-key: ${{ secrets.PRIMER_APP_PRIVATE_KEY_SHARED }}
- name: Build
run: npm run build:lib
- name: Publish release candidate
run: |
npm exec --workspaces -- ../../packages/repo-configs/scripts/prepare-release-candidate
npm exec -- changeset publish --tag next-minor
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Output canary version
uses: actions/github-script@v8
with:
script: |
for (const path of ['react', 'design-tokens', 'css']) {
const pkg = require(`${process.env.GITHUB_WORKSPACE}/packages/${path}/package.json`)
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: 'success',
context: `Published ${pkg.name}`,
description: pkg.version,
target_url: `https://unpkg.com/${pkg.name}@${pkg.version}/`
})
}
release-canary:
# Runs only when all of the following are true:
# - Event is a pull request label event for "release canary"
# - PR is currently open
# - PR branch comes from this repository (not a fork)
# - PR head branch is not one of the release branches
if: >-
github.event_name == 'pull_request' &&
github.repository == 'primer/brand' &&
github.event.action == 'labeled' &&
github.event.label.name == 'release canary' &&
github.event.pull_request.state == 'open' &&
github.event.pull_request.head.repo.full_name == github.repository &&
github.head_ref != 'main' &&
github.head_ref != 'next-minor' &&
github.head_ref != 'changeset-release/main' &&
github.head_ref != 'changeset-release/next-minor'
name: Canary
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
issues: write
pull-requests: write
checks: write
statuses: write
steps:
# Re-check the live PR state and labels to prevent stale event payloads
# or workflow re-runs.
- name: Verify canary publish is valid
id: canary-gate
uses: actions/github-script@v8
with:
script: |
const labelName = 'release canary'
const {owner, repo} = context.repo
const pull_number = context.payload.pull_request.number
const {data: pullRequest} = await github.rest.pulls.get({
owner,
repo,
pull_number
})
const hasLabel = pullRequest.labels.some((label) => label.name === labelName)
const isOpen = pullRequest.state === 'open'
const shouldPublish = hasLabel && isOpen
core.setOutput('should_publish', shouldPublish ? 'true' : 'false')
if (shouldPublish) {
core.info(`Canary publish is authorized for PR #${pull_number}`)
return
}
core.info(`Skipping canary publish because PR #${pull_number} is ${pullRequest.state} or missing label "${labelName}"`)
- name: Checkout repository
if: steps.canary-gate.outputs.should_publish == 'true'
uses: actions/checkout@v6
with:
# Pin to the labeled-event head SHA so publish and status refer to the same commit.
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false
- name: Set up Node
if: steps.canary-gate.outputs.should_publish == 'true'
uses: actions/setup-node@v6
with:
node-version: 24.14.1
- name: Install dependencies
if: steps.canary-gate.outputs.should_publish == 'true'
run: npm ci
- uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
if: steps.canary-gate.outputs.should_publish == 'true'
id: app-token
with:
app-id: ${{ vars.PRIMER_APP_ID_SHARED }}
private-key: ${{ secrets.PRIMER_APP_PRIVATE_KEY_SHARED }}
- name: Build
if: steps.canary-gate.outputs.should_publish == 'true'
run: npm run build:lib
- name: Publish canary release
id: publish-canary
if: steps.canary-gate.outputs.should_publish == 'true'
run: |
npm exec --workspaces -- ../../packages/repo-configs/scripts/prepare-canary
npm exec -- changeset publish --tag canary
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Output canary version
if: steps.canary-gate.outputs.should_publish == 'true'
uses: actions/github-script@v8
with:
script: |
const sha = context.payload.pull_request.head.sha
for (const path of ['react', 'design-tokens', 'css']) {
const pkg = require(`${process.env.GITHUB_WORKSPACE}/packages/${path}/package.json`)
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha,
state: 'success',
context: `Published ${pkg.name}`,
description: pkg.version,
target_url: `https://unpkg.com/${pkg.name}@${pkg.version}/`
})
}
- name: Remove canary label on success
# Treat the label as a one-time publish request. Maintainers can
# re-add it later when they explicitly want a fresh canary.
if: always() && steps.canary-gate.outputs.should_publish == 'true' && steps.publish-canary.outcome == 'success'
uses: actions/github-script@v8
with:
script: |
const labelName = 'release canary'
const {owner, repo} = context.repo
const issue_number = context.payload.pull_request.number
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: labelName
})
core.info(`Removed label "${labelName}" from PR #${issue_number}`)
} catch (error) {
if (error.status === 404) {
core.info(`Label "${labelName}" was already removed from PR #${issue_number}`)
return
}
throw error
}
- name: Skip canary publish
if: steps.canary-gate.outputs.should_publish != 'true'
run: echo 'Skipping canary because the PR is closed or no longer has the "release canary" label.'