Repository navigation
298 lines (285 loc) · 14.1 KB
/
Copy pathrelease.yml
File metadata and controls
298 lines (285 loc) · 14.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
name: Release
on:
workflow_dispatch:
inputs:
candidate_sha:
description: Optional exact 40-character commit to verify privately
type: string
default: ""
verify_candidate:
description: Verify privately even when the version is already public
type: boolean
default: false
push:
branches: [main]
permissions:
contents: read
# A newer main commit supersedes the older run, which could never publish anyway.
# Publication is safe to interrupt: the release stays a private draft until done.
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && (inputs.verify_candidate || inputs.candidate_sha != '') && github.run_id || 'main' }}
cancel-in-progress: ${{ github.event_name == 'push' }}
jobs:
prepare:
name: Select candidate
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
statuses: write
outputs:
build: ${{ steps.select.outputs.build }}
publish: ${{ steps.select.outputs.publish }}
fast: ${{ steps.select.outputs.fast }}
candidate_sha: ${{ steps.select.outputs.candidate_sha }}
tag: ${{ steps.select.outputs.tag }}
steps:
- uses: actions/github-script@v9
id: select
env:
CANDIDATE_SHA: ${{ inputs.candidate_sha }}
VERIFY_CANDIDATE: ${{ inputs.verify_candidate }}
with:
script: |
const { owner, repo } = context.repo;
const requested = process.env.CANDIDATE_SHA || '';
if (requested && !/^[a-f0-9]{40}$/.test(requested)) throw new Error('candidate_sha must be an exact commit SHA.');
const sha = requested || context.sha;
const resolved = (await github.rest.repos.getCommit({ owner, repo, ref: sha })).data.sha;
if (resolved !== sha) throw new Error('Candidate did not resolve to the exact commit.');
const privateCandidate = context.eventName === 'workflow_dispatch' && (requested !== '' || process.env.VERIFY_CANDIDATE === 'true');
let superseded = false;
if (!privateCandidate) {
if (context.ref !== 'refs/heads/main') throw new Error('Publication requires main. Use verify_candidate for a private candidate.');
const main = (await github.rest.git.getRef({ owner, repo, ref: 'heads/main' })).data.object.sha;
superseded = main !== sha;
}
const { data } = await github.rest.repos.getContent({ owner, repo, path: 'package.json', ref: sha });
const version = JSON.parse(Buffer.from(data.content, 'base64').toString('utf8')).version;
if (typeof version !== 'string' || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) throw new Error('Invalid package version.');
const tag = `v${version}`;
// Every current main commit is a full candidate, so releases land on proven code.
const build = !superseded;
let publish = false;
if (!privateCandidate && !superseded) {
publish = true;
try {
const release = (await github.rest.repos.getReleaseByTag({ owner, repo, tag })).data;
publish = release.draft;
} catch (error) { if (error.status !== 404) throw error; }
if (publish) {
try {
await github.rest.git.getRef({ owner, repo, ref: `tags/${tag}` });
throw new Error('An unpublished release cannot reserve a version tag.');
} catch (error) { if (error.status !== 404) throw error; }
}
}
// A commit that only changes the version, on top of a commit whose full candidate
// passed, ships after building and smoke-testing its packages. The parent already
// ran every media, installer, update and UI suite on identical code.
let fast = false;
if (publish) {
const commit = (await github.rest.repos.getCommit({ owner, repo, ref: sha })).data;
const lines = (commit.files?.[0]?.patch ?? '').split('\n').filter((line) => /^[+-](?![+-])/.test(line));
const versionOnly = commit.parents.length === 1 && commit.files?.length === 1 && commit.files[0].filename === 'package.json'
&& lines.length === 2 && lines.every((line) => /^[+-]\s*"version": "[^"]+",$/.test(line));
if (versionOnly) {
const parent = commit.parents[0].sha;
const statuses = await github.paginate(github.rest.repos.listCommitStatusesForRef, { owner, repo, ref: parent, per_page: 100 });
// Statuses list newest first. Only the latest candidate result counts.
fast = statuses.find((status) => status.context === 'Release candidate')?.state === 'success';
if (!fast) core.notice(`${parent.slice(0, 7)} has no passing candidate, so this release runs every suite.`);
}
}
if (build && !publish)
await github.rest.repos.createCommitStatus({ owner, repo, sha, state: 'pending', context: 'Release candidate', description: 'Verifying all five packages',
target_url: `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}` });
core.setOutput('candidate_sha', sha);
core.setOutput('tag', tag);
core.setOutput('build', String(build));
core.setOutput('publish', String(publish));
core.setOutput('fast', String(fast));
await core.summary.addRaw(privateCandidate ? `Private candidate ${sha}, ${tag}. Publication disabled.` : superseded ? `Superseded ${sha}. Running app checks without packaging or publication.` : fast ? `Version-only release of ${tag} on a verified candidate. Build, smoke-test and publish.` : publish ? `Verifying and publishing ${tag} at ${sha} with every suite.` : `Verifying ${sha} as a private candidate. ${tag} is already public.`).write();
checks:
needs: prepare
uses: ./.github/workflows/verify.yml
with:
candidate_sha: ${{ needs.prepare.outputs.candidate_sha }}
app-checks:
needs: prepare
# A version-only release reuses the app checks its parent candidate passed.
if: needs.prepare.outputs.fast != 'true'
uses: ./.github/workflows/app-checks.yml
with:
candidate_sha: ${{ needs.prepare.outputs.candidate_sha }}
# Each target is built and verified on its own chain, alongside the shared checks.
# Publication still waits for every one of them through the Check gate.
win-x64:
needs: prepare
if: needs.prepare.outputs.build == 'true'
uses: ./.github/workflows/candidate.yml
with:
{
candidate_sha: "${{ needs.prepare.outputs.candidate_sha }}",
target: win-x64,
os: windows-2025,
smoke: "${{ needs.prepare.outputs.fast == 'true' }}",
}
mac-x64:
needs: prepare
if: needs.prepare.outputs.build == 'true'
uses: ./.github/workflows/candidate.yml
with:
{
candidate_sha: "${{ needs.prepare.outputs.candidate_sha }}",
target: mac-x64,
os: macos-15-intel,
smoke: "${{ needs.prepare.outputs.fast == 'true' }}",
}
mac-arm64:
needs: prepare
if: needs.prepare.outputs.build == 'true'
uses: ./.github/workflows/candidate.yml
with:
{ candidate_sha: "${{ needs.prepare.outputs.candidate_sha }}", target: mac-arm64, os: macos-15, smoke: "${{ needs.prepare.outputs.fast == 'true' }}" }
linux-x64:
needs: prepare
if: needs.prepare.outputs.build == 'true'
uses: ./.github/workflows/candidate.yml
with:
{
candidate_sha: "${{ needs.prepare.outputs.candidate_sha }}",
target: linux-x64,
os: ubuntu-24.04,
smoke: "${{ needs.prepare.outputs.fast == 'true' }}",
}
linux-arm64:
needs: prepare
if: needs.prepare.outputs.build == 'true'
uses: ./.github/workflows/candidate.yml
with:
{
candidate_sha: "${{ needs.prepare.outputs.candidate_sha }}",
target: linux-arm64,
os: ubuntu-24.04-arm,
smoke: "${{ needs.prepare.outputs.fast == 'true' }}",
}
check:
name: Check
if: always()
needs: [prepare, checks, app-checks, win-x64, mac-x64, mac-arm64, linux-x64, linux-arm64]
permissions:
contents: read
statuses: write
runs-on: ubuntu-latest
timeout-minutes: 15
env:
CANDIDATE_SHA: ${{ needs.prepare.outputs.candidate_sha }}
steps:
- uses: actions/github-script@v9
env:
RESULTS: ${{ toJSON(needs) }}
with:
script: |
const jobs = JSON.parse(process.env.RESULTS);
for (const name of ['prepare', 'checks', 'app-checks']) {
const expected = name === 'app-checks' && jobs.prepare.outputs.fast === 'true' ? 'skipped' : 'success';
if (jobs[name].result !== expected) throw new Error(`${name}: ${jobs[name].result}, expected ${expected}`);
}
for (const name of ['win-x64', 'mac-x64', 'mac-arm64', 'linux-x64', 'linux-arm64']) {
const expected = jobs.prepare.outputs.build === 'true' ? 'success' : 'skipped';
if (jobs[name].result !== expected) throw new Error(`${name}: ${jobs[name].result}, expected ${expected}`);
}
- uses: actions/checkout@v7
if: needs.prepare.outputs.build == 'true'
with:
ref: ${{ needs.prepare.outputs.candidate_sha }}
- uses: oven-sh/setup-bun@v2
if: needs.prepare.outputs.build == 'true'
with:
bun-version: "1.4.2"
- run: bun install --frozen-lockfile
if: needs.prepare.outputs.build == 'true'
- uses: actions/download-artifact@v8
if: needs.prepare.outputs.build == 'true'
with:
pattern: verified-*
path: work/verified
- name: Seal complete verified target set
if: needs.prepare.outputs.build == 'true'
run: bun scripts/ci-stage.ts seal
- name: Add the corresponding sources of the bundled media
if: needs.prepare.outputs.build == 'true'
uses: actions/download-artifact@v8
with:
name: media-sources
path: dist
- uses: actions/upload-artifact@v7
if: needs.prepare.outputs.build == 'true'
with:
name: sealed-release-candidate
path: dist/
if-no-files-found: error
retention-days: 14
- name: Record candidate outcome
if: needs.prepare.outputs.build == 'true'
run: echo "Verified candidate $CANDIDATE_SHA. Exact artifacts retained. Re-run failed jobs to retry verification without rebuilding successful targets." >> "$GITHUB_STEP_SUMMARY"
- name: Report the candidate result on the source commit
if: always() && needs.prepare.outputs.build == 'true' && needs.prepare.outputs.publish != 'true'
uses: actions/github-script@v9
env:
VERIFICATION_STATUS: ${{ job.status }}
with:
script: |
const sha = process.env.CANDIDATE_SHA;
if (!/^[a-f0-9]{40}$/.test(sha)) throw new Error('Invalid candidate commit');
const passed = process.env.VERIFICATION_STATUS === 'success';
await github.rest.repos.createCommitStatus({
...context.repo, sha, state: passed ? 'success' : 'failure', context: 'Release candidate',
description: passed ? 'All five packages verified' : 'Candidate verification failed',
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
});
publish:
name: Publish release
needs: [prepare, check]
# A version-only release skips app-checks, and a skipped job anywhere upstream makes the
# implicit success() false. The Check gate already requires every expected job.
if: ${{ !cancelled() && needs.prepare.outputs.publish == 'true' && needs.check.result == 'success' }}
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
with:
ref: ${{ needs.prepare.outputs.candidate_sha }}
- uses: oven-sh/setup-bun@v2
with:
bun-version: "1.4.2"
- uses: actions/download-artifact@v8
with:
name: sealed-release-candidate
path: dist
- name: Prepare update feeds
env:
RELEASE_TAG: ${{ needs.prepare.outputs.tag }}
run: bun scripts/prepare-update-feed.mjs dist dist/feed "$RELEASE_TAG"
- name: Select exact app downloads and feeds
env:
RELEASE_TAG: ${{ needs.prepare.outputs.tag }}
run: bun scripts/release-downloads.ts dist dist/feed dist/downloads "$RELEASE_TAG"
- name: Publish exact verified candidate
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ needs.prepare.outputs.tag }}
run: bun scripts/publish-release.ts
- name: Retain internal release provenance
if: always()
uses: actions/upload-artifact@v7
with:
name: release-provenance-${{ github.run_id }}
overwrite: true
path: dist/release-provenance.json
if-no-files-found: ignore
retention-days: 90