Repository navigation
389 lines (378 loc) · 17.4 KB
/
Copy pathrelease.yml
File metadata and controls
389 lines (378 loc) · 17.4 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
384
385
386
387
388
389
name: Release
# Cuts a release from main, by hand: Actions → Release → Run workflow, with the bump. Nothing
# irreversible happens before the package is built and checked:
#
# plan the next version (0.X for a feature, 0.X.Y for a patch, from package.json), after
# checking that main's CI passed on this commit, that the tag is free, that
# @simlock/e2e exists on npm, and that the version is free for both packages
# build both packages at that version, on macOS with Xcode 27 so dist/bin/ holds both iOS
# capture programs (Linux cannot build them); their two tarballs are the artifacts
# every later job ships
# tag the release commit (both package.json files, CHANGELOG.md) and the tag v0.X.Y,
# pushed to main
# publish both tarballs to npm, @simlock/e2e first, through trusted publishing (OIDC, no
# stored token), with provenance
# release the GitHub release, with the same notes as CHANGELOG.md and both tarballs attached
# website the docs site, from the release commit (.github/workflows/website.yml)
#
# `dry_run` stops after build, with the tarballs to inspect, and may run from any branch (a release
# only from main). The version and changelog arithmetic is `node scripts/release.mjs`.
#
# Why it is shaped this way:
# - Every action is pinned to a commit. Nothing is cached (no actions/cache, no setup-node cache):
# a cache another run wrote cannot hand this one its files. Dependencies come from the lockfile
# with lifecycle scripts off; the scrcpy server is checked against its pinned SHA-256 by the
# build.
# - Each job holds the one permission it needs, and the checkout keeps no credentials: the push in
# tag is the only step that sees a write token, and publish has only the OIDC token, in the
# `release` environment that npm's trusted publisher is bound to, so no other workflow, job or
# branch can mint one.
# - Every job works from the commit plan saw (`github.sha`), and the release commit is pushed only
# if main still points there, so main moving during the run cannot change what ships. The
# tarballs published and attached are the ones build proved.
# - Nightly builds would be a `schedule` trigger: plan would name a channel, with a version like
# 0.X.Y-nightly.<date> and the `nightly` dist-tag, and tag, release and website would skip for
# it. Nothing else changes.
#
# One-time setup, outside this file: the `simlock` organisation on npm, a 0.0.0 placeholder of
# @simlock/e2e published by hand, and an npm trusted publisher for each of `simlock` and
# `@simlock/e2e` (owner callstackincubator, repository simlock, workflow release.yml,
# environment release, with `npm publish` allowed); a `release` environment on the repository whose deployments may come
# from main only; main's ruleset letting GitHub Actions push. Agents cannot start this workflow
# (`gh workflow run` is denied in .claude/settings.json).
on:
workflow_dispatch:
inputs:
bump:
description: "feature moves 0.X, patch moves 0.X.Y; auto is feature when a commit since the last tag is a feat or a breaking change"
type: choice
options: [auto, feature, patch]
default: auto
dry_run:
description: "Plan and build only; push, publish, release and deploy nothing"
type: boolean
default: false
permissions: {}
env:
COREPACK_ENABLE_PROJECT_SPEC: "0"
concurrency:
group: release
cancel-in-progress: false
jobs:
plan:
name: Plan
# why: a dry run pushes and publishes nothing, so it may try a branch; a release is main's.
if: github.ref == 'refs/heads/main' || inputs.dry_run
runs-on: ubuntu-24.04
permissions:
contents: read
checks: read
timeout-minutes: 5
outputs:
version: ${{ steps.next.outputs.version }}
tag: ${{ steps.next.outputs.tag }}
bump: ${{ steps.next.outputs.bump }}
previous_tag: ${{ steps.next.outputs.previous_tag }}
dist_tag: latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
# why: the tags say what the last release was, and the commits since it say what this
# one is.
fetch-depth: 0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- name: CI passed on this commit
env:
GH_TOKEN: ${{ github.token }}
run: |
for name in Quality Fallow Console; do
passed=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/check-runs?check_name=$name&per_page=20" \
--jq '[.check_runs[] | select(.conclusion == "success")] | length')
if [ "$passed" -eq 0 ]; then
echo "::error::$name has not passed on $GITHUB_SHA; release a commit main's CI is green on"
exit 1
fi
done
- name: Next version
id: next
env:
BUMP: ${{ inputs.bump }}
run: |
set -o pipefail
previous=$(git tag --list 'v[0-9]*' --sort=-v:refname | head -n 1)
if [ -n "$previous" ]; then range="$previous..HEAD"; else range=HEAD; fi
git log --format='%s%n%b' "$range" | node scripts/release.mjs plan --bump "$BUMP" | tee -a "$GITHUB_OUTPUT"
echo "previous_tag=$previous" | tee -a "$GITHUB_OUTPUT"
- name: The tag and the npm versions are free
env:
VERSION: ${{ steps.next.outputs.version }}
TAG: ${{ steps.next.outputs.tag }}
run: |
set -o pipefail
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "::error::$TAG exists already"
exit 1
fi
# why: npm binds a trusted publisher only to a package that exists, so the first version of
# @simlock/e2e is published by hand; a release does not start before that (ADR 0077 §4).
for name in simlock @simlock/e2e; do
status=$(curl -sS -o "$RUNNER_TEMP/npm.json" -w '%{http_code}' "https://registry.npmjs.org/${name/\//%2F}")
if [ "$status" = 404 ] && [ "$name" = "@simlock/e2e" ]; then
echo "::error::@simlock/e2e is not on npm yet: create the simlock organisation, publish a 0.0.0 placeholder by hand and add its trusted publisher, then run the release again"
exit 1
fi
if [ "$status" != 200 ]; then
echo "::error::npm answered $status for $name"
exit 1
fi
published=$(jq -r --arg v "$VERSION" '.versions[$v].version // empty' "$RUNNER_TEMP/npm.json")
if [ -n "$published" ]; then
echo "::error::$name@$VERSION is on npm already"
exit 1
fi
done
build:
name: Build
needs: plan
# why: dist/bin/ holds two Swift programs that only a Mac with Xcode builds; a package built
# on Linux would stream no iOS screen for anyone who installs it. simlock-device-capture links
# CoreDevice symbols that first ship with Xcode 27 (ADR 0031), and macos-15 and macos-26 carry
# Xcode 26 at most, so only the xcode-27 image (a preview, 2026-10) builds it.
runs-on: xcode-27
permissions:
contents: read
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- name: Enable Corepack
run: |
corepack enable
corepack prepare pnpm@12.8.1+sha512.f64ba907507f5ceafe06c8d38e6052d0179444580ec1279ddd5bfc11cb48aa8a2644b66598e07e761da84872a9fc57d5f902b87fa49d024198d558612aabbe45 --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Version
env:
VERSION: ${{ needs.plan.outputs.version }}
run: node scripts/release.mjs bump "$VERSION"
- name: Build
run: pnpm run build
- name: Both iOS capture programs built
run: |
for program in simlock-screen-capture simlock-device-capture; do
if [ ! -x "dist/bin/$program" ]; then
echo "::error::dist/bin/$program is missing; a release ships both iOS capture programs"
exit 1
fi
done
- name: Pack
env:
VERSION: ${{ needs.plan.outputs.version }}
run: |
set -o pipefail
mkdir -p "$RUNNER_TEMP/package"
# why: `prepare` installs git hooks, which a tarball does not need and this checkout
# cannot run.
pnpm pack --config.ignore-scripts=true --pack-destination "$RUNNER_TEMP/package"
pnpm --dir packages/e2e pack --config.ignore-scripts=true --pack-destination "$RUNNER_TEMP/package"
cd "$RUNNER_TEMP/package"
tar tzf "simlock-$VERSION.tgz" | tee contents.txt
for file in package/dist/cli/main.js package/dist/bin/simlock-screen-capture package/dist/bin/simlock-device-capture package/dist/vendor/scrcpy/NOTICE.md; do
grep -qx "$file" contents.txt || { echo "::error::$file is not in the tarball"; exit 1; }
done
tar tzf "simlock-e2e-$VERSION.tgz" | tee contents.txt
for file in package/dist/index.js package/dist/index.d.ts; do
grep -qx "$file" contents.txt || { echo "::error::$file is not in the @simlock/e2e tarball"; exit 1; }
done
if grep -q '\.test\.' contents.txt; then
echo "::error::the @simlock/e2e tarball holds a test file"
exit 1
fi
rm contents.txt
shasum -a 256 "simlock-$VERSION.tgz" "simlock-e2e-$VERSION.tgz" | tee SHA256SUMS.txt
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package
path: ${{ runner.temp }}/package
if-no-files-found: error
retention-days: 7
tag:
name: Tag
needs: [plan, build]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-24.04
permissions:
contents: write
timeout-minutes: 5
outputs:
sha: ${{ steps.commit.outputs.sha }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
fetch-depth: 0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
- name: Release notes
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.plan.outputs.tag }}
PREVIOUS: ${{ needs.plan.outputs.previous_tag }}
run: |
set -o pipefail
mkdir -p "$RUNNER_TEMP/notes"
args=(-f "tag_name=$TAG" -f "target_commitish=$GITHUB_SHA")
if [ -n "$PREVIOUS" ]; then args+=(-f "previous_tag_name=$PREVIOUS"); fi
gh api -X POST "repos/$GITHUB_REPOSITORY/releases/generate-notes" "${args[@]}" --jq .body \
| tee "$RUNNER_TEMP/notes/notes.md"
- name: Release commit and tag
id: commit
env:
VERSION: ${{ needs.plan.outputs.version }}
TAG: ${{ needs.plan.outputs.tag }}
PREVIOUS: ${{ needs.plan.outputs.previous_tag }}
run: |
node scripts/release.mjs bump "$VERSION"
node scripts/release.mjs changelog "$VERSION" "$PREVIOUS" "$RUNNER_TEMP/notes/notes.md"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json packages/e2e/package.json CHANGELOG.md
git commit -m "chore(release): $VERSION"
git tag -a "$TAG" -m "simlock $VERSION"
git show --stat HEAD
echo "sha=$(git rev-parse HEAD)" | tee -a "$GITHUB_OUTPUT"
- name: Push
env:
GITHUB_TOKEN: ${{ github.token }}
TAG: ${{ needs.plan.outputs.tag }}
# why: the lease fails the push when main moved since plan, instead of releasing a commit
# nobody checked; the pair goes atomically so a tag never exists without its commit.
# why: the token goes as the extraheader actions/checkout writes, set through git's
# GIT_CONFIG_* environment rather than `-c`, so it is in neither the remote URL nor git's argv.
run: |
auth=$(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 | tr -d '\n')
echo "::add-mask::$auth"
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0="http.https://github.com/.extraheader"
export GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $auth"
git push --atomic --force-with-lease="refs/heads/main:$GITHUB_SHA" \
"https://github.com/${GITHUB_REPOSITORY}.git" HEAD:refs/heads/main "refs/tags/$TAG"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: notes
path: ${{ runner.temp }}/notes
if-no-files-found: error
retention-days: 7
publish:
name: Publish to npm
needs: [plan, build, tag]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-24.04
environment: release
permissions:
contents: read
id-token: write
timeout-minutes: 10
steps:
# why: trusted publishing needs npm 11.5.1 or later; Node 24 bundles one. No checkout: the
# tarball is the package, and npm run inside the repository would refuse its devEngines.
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: package
path: ${{ runner.temp }}/package
- name: The tarballs are the planned version, and npm can publish without a token
working-directory: ${{ runner.temp }}/package
env:
VERSION: ${{ needs.plan.outputs.version }}
run: |
set -o pipefail
shasum -a 256 -c SHA256SUMS.txt
for tarball in "simlock-$VERSION.tgz" "simlock-e2e-$VERSION.tgz"; do
name=$(tar -xOzf "$tarball" package/package.json | jq -r .name)
packed=$(tar -xOzf "$tarball" package/package.json | jq -r .version)
if [ "$packed" != "$VERSION" ]; then
echo "::error::the tarball is $name@$packed, not $VERSION"
exit 1
fi
done
# why: Node's process.versions has no npm key; the version comes from npm itself.
npm_version=$(npm --version)
echo "npm $npm_version"
node -e 'const [a, b, c] = process.argv[1].split(".").map(Number); if (a < 11 || (a === 11 && (b < 5 || (b === 5 && c < 1)))) { console.error("npm 11.5.1 or later is needed for trusted publishing"); process.exit(1); }' "$npm_version"
# why: @simlock/e2e goes first, so a failure there leaves simlock unpublished and the release
# can be run again (ADR 0077 §4). A run again skips a package whose version is on npm, so a
# release that stopped between the two publishes finishes by re-running the failed job.
- name: Publish @simlock/e2e
working-directory: ${{ runner.temp }}/package
env:
VERSION: ${{ needs.plan.outputs.version }}
DIST_TAG: ${{ needs.plan.outputs.dist_tag }}
run: |
if npm view "@simlock/e2e@$VERSION" version >/dev/null 2>&1; then
echo "@simlock/e2e@$VERSION is on npm already, skipping"
exit 0
fi
npm publish "simlock-e2e-$VERSION.tgz" --provenance --access public --tag "$DIST_TAG"
- name: Publish simlock
working-directory: ${{ runner.temp }}/package
env:
VERSION: ${{ needs.plan.outputs.version }}
DIST_TAG: ${{ needs.plan.outputs.dist_tag }}
run: |
if npm view "simlock@$VERSION" version >/dev/null 2>&1; then
echo "simlock@$VERSION is on npm already, skipping"
exit 0
fi
npm publish "simlock-$VERSION.tgz" --provenance --access public --tag "$DIST_TAG"
release:
name: GitHub release
needs: [plan, tag, publish]
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-24.04
permissions:
contents: write
timeout-minutes: 5
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: package
path: ${{ runner.temp }}/package
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: notes
path: ${{ runner.temp }}/notes
- name: Create the release
working-directory: ${{ runner.temp }}/package
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.plan.outputs.version }}
TAG: ${{ needs.plan.outputs.tag }}
run: |
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" --verify-tag --latest \
--title "$TAG" --notes-file "$RUNNER_TEMP/notes/notes.md" \
"simlock-$VERSION.tgz" "simlock-e2e-$VERSION.tgz" SHA256SUMS.txt
website:
name: Website
needs: [tag, release]
if: ${{ !inputs.dry_run }}
permissions:
contents: read
pages: write
id-token: write
uses: ./.github/workflows/website.yml
with:
ref: ${{ needs.tag.outputs.sha }}