-
Notifications
You must be signed in to change notification settings - Fork 439
383 lines (336 loc) · 13.9 KB
/
release.yml
File metadata and controls
383 lines (336 loc) · 13.9 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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
name: Release
run-name: ${{ github.event_name == 'issue_comment' && format('Snapshot release by {0}', github.actor) || format('Release pipelines from {0}', github.ref_name) }}
on:
push:
branches:
- main
issue_comment:
types: [created]
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'issue_comment' && format('issue-{0}-{1}', github.event.issue.number, github.actor) || github.ref }}
cancel-in-progress: true
jobs:
release:
name: Release
if: ${{ github.event_name == 'push' && github.repository == 'clerk/javascript' }}
runs-on: ${{ vars.RUNNER_NORMAL || 'ubuntu-latest' }}
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}
permissions:
contents: write
id-token: write
packages: write
pull-requests: write
issues: read
statuses: write
checks: write
steps:
- name: Echo github context
run: echo "$GITHUB_CONTEXT"
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
show-progress: false
- name: Setup
id: config
uses: ./.github/actions/init
with:
playwright-enabled: true # Must be present to enable caching on branched workflows
# turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
# turbo-team: ${{ vars.TURBO_TEAM }}
# turbo-token: ${{ secrets.TURBO_TOKEN }}
- name: Upgrade npm for trusted publishing
run: npm install -g npm@latest
- name: Build release
run: pnpm turbo build $TURBO_ARGS --force
- name: Create Release PR
id: changesets
uses: changesets/action@v1
with:
commit: "ci(repo): Version packages"
title: "ci(repo): Version packages"
publish: pnpm release
# Workaround for https://github.com/changesets/changesets/issues/421
version: pnpm version-packages
env:
GITHUB_TOKEN: ${{ secrets.CLERK_COOKIE_PAT }}
HUSKY: "0"
NPM_CONFIG_PROVENANCE: true
- name: Trigger workflows on related repos
if: steps.changesets.outputs.published == 'true'
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
script: |
const preMode = require("fs").existsSync("./.changeset/pre.json");
if (!preMode) {
const clerkjsVersion = require('./packages/clerk-js/package.json').version;
const clerkUiVersion = require('./packages/ui/package.json').version;
const nextjsVersion = require('./packages/nextjs/package.json').version;
github.rest.actions.createWorkflowDispatch({
owner: 'clerk',
repo: 'sdk-infra-workers',
workflow_id: 'update-pkg-versions.yml',
ref: 'main',
inputs: { clerkjsVersion, clerkUiVersion }
})
github.rest.actions.createWorkflowDispatch({
owner: 'clerk',
repo: 'dashboard',
workflow_id: 'prepare-nextjs-sdk-update.yml',
ref: 'main',
inputs: { version: nextjsVersion }
})
github.rest.actions.createWorkflowDispatch({
owner: 'clerk',
repo: 'clerk-docs',
workflow_id: 'typedoc.yml',
ref: 'main',
})
} else{
core.warning("Changeset in pre-mode should not prepare a ClerkJS production release")
}
- name: Generate notification payload
id: notification
if: steps.changesets.outputs.published == 'true'
run: payload=$(node scripts/notify.mjs '${{ steps.changesets.outputs.publishedPackages }}' '${{ github.actor }}') && echo ::set-output name=payload::${payload//$'\n'/'%0A'}
- name: Send commit log to Slack
id: slack
if: steps.changesets.outputs.published == 'true'
uses: slackapi/slack-github-action@v1.24.0
with:
payload: ${{ steps.notification.outputs.payload }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CHANGELOG_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
canary-release:
name: Canary release
if: ${{ github.event_name == 'push' && github.repository == 'clerk/javascript' }}
runs-on: ${{ vars.RUNNER_NORMAL || 'ubuntu-latest' }}
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
TURBO_CACHE: remote:rw
permissions:
contents: read
id-token: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 1
fetch-tags: false
filter: 'blob:none'
- name: Setup
id: config
uses: ./.github/actions/init
with:
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
turbo-team: ${{ vars.TURBO_TEAM }}
turbo-token: ${{ secrets.TURBO_TOKEN }}
playwright-enabled: true # Must be present to enable caching on branched workflows
- name: Upgrade npm for trusted publishing
run: npm install -g npm@latest
- name: Version packages for canary
id: version-packages
run: pnpm version-packages:canary | tail -1 >> "$GITHUB_OUTPUT"
- name: Build release
if: steps.version-packages.outputs.success == '1'
run: pnpm turbo build $TURBO_ARGS
- name: Canary release
id: publish
if: steps.version-packages.outputs.success == '1'
run: pnpm release:canary
env:
NPM_CONFIG_PROVENANCE: true
- name: Trigger workflows on related repos
if: steps.publish.outcome == 'success'
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
script: |
const clerkjsVersion = require('./packages/clerk-js/package.json').version;
const clerkUiVersion = require('./packages/ui/package.json').version;
const nextjsVersion = require('./packages/nextjs/package.json').version;
github.rest.actions.createWorkflowDispatch({
owner: 'clerk',
repo: 'sdk-infra-workers',
workflow_id: 'update-pkg-versions.yml',
ref: 'main',
inputs: { clerkjsVersion, clerkUiVersion, sourceCommit: context.sha }
})
if (nextjsVersion.includes('canary')) {
console.log('clerk/nextjs changed, will notify clerk/accounts');
github.rest.actions.createWorkflowDispatch({
owner: 'clerk',
repo: 'accounts',
workflow_id: 'release-staging.yml',
ref: 'main',
inputs: { version: nextjsVersion }
})
}
snapshot-release:
name: Snapshot release
if: ${{ github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '!snapshot') && github.repository == 'clerk/javascript' && github.event.issue.pull_request }}
runs-on: ${{ vars.RUNNER_LARGE || 'ubuntu-latest-l' }}
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}
permissions:
contents: read
id-token: write
steps:
- name: Limit action to Clerk members
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
script: |
try {
const { data } = await github.rest.orgs.getMembershipForUser({
org: 'clerk',
username: context.actor
});
if (data.state !== 'active') {
core.setFailed(`@${context.actor} is not an active member of the Clerk organization`);
}
} catch (e) {
core.setFailed(`@${context.actor} is not a member of the Clerk organization`);
}
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head
fetch-depth: 1
fetch-tags: false
filter: 'blob:none'
- name: Ensure the PR hasn't changed since initiating the !snapshot command.
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
script: |
const commentCreated = new Date(context.payload.comment.created_at);
const pr = await github.rest.pulls.get({
owner: 'clerk',
repo: 'javascript',
pull_number: context.issue.number,
});
const prLastUpdated = new Date(pr.updated_at);
if (prLastUpdated > commentCreated) {
core.setFailed("The PR has been updated since !snapshot was initiated. Please review the changes and re-run the !snapshot command.");
}
- name: Setup
id: config
uses: ./.github/actions/init
with:
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
turbo-team: ${{ vars.TURBO_TEAM }}
turbo-token: ${{ secrets.TURBO_TOKEN }}
- name: Upgrade npm for trusted publishing
run: npm install -g npm@latest
- name: Extract snapshot name
id: extract-snapshot-name
uses: actions/github-script@v7
with:
script: |
const match = context.payload.comment.body.match(/!snapshot (.*)/)
const name = match && match[1] || '';
const isKebabCase = name.match(/^[a-z]+(-[a-z]+)*$/)
if(name && !isKebabCase) {
core.setFailed(`Invalid snapshot name: ${name}`);
}
core.setOutput('name', name);
- name: Version packages for snapshot
id: version-packages
run: npm run version-packages:snapshot ${{ steps.extract-snapshot-name.outputs.name }} | tail -1 >> "$GITHUB_OUTPUT"
- name: Build release
if: steps.version-packages.outputs.success == '1'
run: npx turbo build $TURBO_ARGS
- name: Snapshot release
if: steps.version-packages.outputs.success == '1'
run: npm run release:snapshot
env:
NPM_CONFIG_PROVENANCE: true
- name: Package info
if: steps.version-packages.outputs.success == '1'
id: package-info
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const files = await (await glob.create("./packages/*/package.json")).glob();
const descriptors = files
.map((file) => {
const { name, version } = JSON.parse(fs.readFileSync(file, "utf8"));
return { name, version };
})
.filter(({ version }) => version.includes("-${{ steps.extract-snapshot-name.outputs.name }}"));
let table = `| Package | Version |\n| --- | --- |\n`;
descriptors.forEach(({ name, version }) => {
table += `| ${name} | ${version} |\n`;
});
const snippets = descriptors
.map(
({ name, version }) =>
`\`${name}\`\n\`\`\`sh\nnpm i ${name}@${version} --save-exact\n\`\`\``
)
.join("\n");
core.setOutput("table", table);
core.setOutput("snippets", snippets);
- name: Update Comment
if: steps.version-packages.outputs.success == '1'
uses: peter-evans/create-or-update-comment@v3.0.0
with:
token: ${{ secrets.CLERK_COOKIE_PAT }}
comment-id: ${{ github.event.comment.id }}
reactions: heart
- name: Create snapshot release comment
if: steps.version-packages.outputs.success == '1'
uses: peter-evans/create-or-update-comment@v3.0.0
with:
token: ${{ secrets.CLERK_COOKIE_PAT }}
issue-number: ${{ github.event.issue.number }}
body: |
Hey @${{ github.event.comment.user.login }} - the snapshot version command generated the following package versions:
${{ steps.package-info.outputs.table }}
Tip: Use the snippet copy button below to quickly install the required packages.
${{ steps.package-info.outputs.snippets }}
# We're running the CI workflow (where node v20 modules are cached) in
# merge_group and not on main, we need to explicitly cache node_modules here so
# that follow-on branches can use the cached version of node_modules rather
# than recreating them every time.
cache-for-alternate-node-versions:
name: Cache for Alternate Node Versions
if: ${{ github.event_name == 'push' }}
runs-on: ${{ vars.RUNNER_NORMAL || 'ubuntu-latest' }}
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}
continue-on-error: true
strategy:
matrix:
version: [22] # NOTE: 18 is cached in the main release workflow
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 1
fetch-tags: false
filter: "blob:none"
show-progress: false
- name: Cache node_modules (Node v${{ matrix.version }})
uses: ./.github/actions/init
with:
node-version: ${{ matrix.version }}
turbo-team: ""
turbo-token: ""