Repository navigation
Expand file tree
/
Copy pathdesktop-macos-preview-publish.yml
More file actions
583 lines (541 loc) · 25.5 KB
/
Copy pathdesktop-macos-preview-publish.yml
File metadata and controls
583 lines (541 loc) · 25.5 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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
name: Desktop macOS Preview Publish
# Trusted half of the macOS preview. Runs from main with secrets and a write
# token, so it must never execute PR code: the PR's JS bundle is only data that
# gets packaged into the app. Everything that runs here (packaging, signing,
# notarization, publishing) is main's code.
#
# Gate, in order: the completed build run belongs to an open PR that still
# carries the preview:mac label and whose head is the built commit, and the PR
# author is trusted by the vouch list. A maintainer applying the label alone is
# not enough, since the bundle gets signed with the Developer ID certificate.
#
# The label is consumed here once the gate passes, so it only ever covers the
# one commit a maintainer applied it to. A later push builds nothing until the
# label is applied again.
on:
workflow_run:
workflows: [Desktop macOS Preview]
types: [completed]
# The way out: closing the PR deletes its download, and removing the label
# before it is consumed cancels the preview. pull_request_target gives this a
# write token for fork PRs; it never checks out PR code.
pull_request_target:
types: [closed, unlabeled]
permissions:
contents: read
jobs:
resolve:
name: Verify preview eligibility
if: >-
github.event_name == 'workflow_run' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
# The build workflow completes for every PR push (its label gate is on the
# job), so this runs often and usually finds nothing. Keep it cheap.
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
actions: read
contents: read
# write only to consume the label; nothing here runs PR code.
pull-requests: write
outputs:
eligible: ${{ steps.gate.outputs.eligible }}
pr_number: ${{ steps.pr.outputs.pr_number }}
head_sha: ${{ steps.pr.outputs.head_sha }}
version: ${{ steps.version.outputs.version }}
clerk_publishable_key: ${{ steps.version.outputs.clerk_publishable_key }}
clerk_jwt_template: ${{ steps.version.outputs.clerk_jwt_template }}
clerk_cli_oauth_client_id: ${{ steps.version.outputs.clerk_cli_oauth_client_id }}
relay_url: ${{ steps.version.outputs.relay_url }}
steps:
- id: pr
name: Resolve the pull request behind the build
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const run = context.payload.workflow_run;
const { owner, repo } = context.repo;
// The build workflow also completes (with every job skipped) for
// label events that are not the preview label. Only a run that
// produced a bundle is worth resolving.
const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {
owner,
repo,
run_id: run.id,
per_page: 100,
});
const bundles = artifacts.filter((artifact) => artifact.name === "js-bundle" && !artifact.expired);
if (bundles.length !== 1) {
core.info(`Expected one js-bundle artifact; found ${bundles.length}. Skipping.`);
core.setOutput("eligible", "false");
return;
}
// workflow_run.pull_requests and the commit-to-PR lookup are both
// empty for fork PRs, so list open PRs by head owner and branch
// and require exactly one at the built commit. The build baked its
// PR number into the version, so two candidates would mean the
// asset name could belong to either.
const open = await github.paginate(github.rest.pulls.list, {
owner,
repo,
state: "open",
head: `${run.head_repository?.owner?.login}:${run.head_branch}`,
per_page: 100,
});
const matching = open.filter(
(candidate) =>
candidate.state === "open" &&
candidate.head.sha === run.head_sha &&
candidate.head.ref === run.head_branch &&
candidate.head.repo?.full_name === run.head_repository?.full_name,
);
if (matching.length !== 1) {
core.info(`Expected one open PR for ${run.head_sha}; found ${matching.length}. Skipping.`);
core.setOutput("eligible", "false");
return;
}
const { data: pull } = await github.rest.pulls.get({
owner,
repo,
pull_number: matching[0].number,
});
if (pull.state !== "open") {
core.info(`PR #${pull.number} is not open. Skipping.`);
core.setOutput("eligible", "false");
return;
}
if (pull.head.sha !== run.head_sha) {
core.info(`PR #${pull.number} moved to ${pull.head.sha} after ${run.head_sha} was built. Skipping.`);
core.setOutput("eligible", "false");
return;
}
if (!pull.labels.some((label) => label.name === "preview:mac")) {
core.info(`PR #${pull.number} no longer carries the preview:mac label. Skipping.`);
core.setOutput("eligible", "false");
return;
}
core.setOutput("artifact_id", String(bundles[0].id));
core.setOutput("eligible", "true");
core.setOutput("pr_number", String(pull.number));
core.setOutput("head_sha", pull.head.sha);
core.setOutput("author", pull.user.login);
# Reads VOUCHED.td from the default branch through the API, so a PR
# cannot vouch for itself.
- id: vouch
name: Check PR author trust
if: steps.pr.outputs.eligible == 'true'
uses: mitchellh/vouch/action/check-user@d66fa29a64600490892131ad87597c30c91fcac4 # v1.5.0
with:
user: ${{ steps.pr.outputs.author }}
allow-fail: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The label authorized exactly this build, so take it now, before the
# long signing job. Removing it with GITHUB_TOKEN does not fire the
# unlabeled cleanup below (workflow-token events never start runs), so
# the download this run publishes survives. If a maintainer removed the
# label first, that removal wins: the 404 makes this run ineligible.
- id: consume
name: Consume the preview label
if: steps.pr.outputs.eligible == 'true'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
PR_NUMBER: ${{ steps.pr.outputs.pr_number }}
with:
script: |
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: Number(process.env.PR_NUMBER),
name: "preview:mac",
});
core.setOutput("consumed", "true");
} catch (error) {
if (error.status !== 404) throw error;
core.info("The preview:mac label was removed before this build could consume it. Skipping.");
core.setOutput("consumed", "false");
}
- id: gate
name: Decide eligibility
shell: bash
env:
PR_ELIGIBLE: ${{ steps.pr.outputs.eligible }}
LABEL_CONSUMED: ${{ steps.consume.outputs.consumed }}
VOUCH_STATUS: ${{ steps.vouch.outputs.status }}
AUTHOR: ${{ steps.pr.outputs.author }}
run: |
set -euo pipefail
if [[ "$PR_ELIGIBLE" != "true" || "$LABEL_CONSUMED" != "true" ]]; then
echo "eligible=false" >> "$GITHUB_OUTPUT"
exit 0
fi
case "$VOUCH_STATUS" in
bot|collaborator|vouched)
echo "Author $AUTHOR is trusted ($VOUCH_STATUS)."
echo "eligible=true" >> "$GITHUB_OUTPUT"
;;
*)
echo "Author $AUTHOR is not vouched ($VOUCH_STATUS). Add them to .github/VOUCHED.td to allow signed previews."
echo "eligible=false" >> "$GITHUB_OUTPUT"
;;
esac
# Same inputs as the build workflow, read from the built commit through
# the contents API as data: the desktop manifest's base version plus the
# build run's number reproduces the version baked into the bundle, and
# .env.example holds the public T3 Connect identifiers the bundle was
# compiled with, which the signed app's passkey entitlement must match.
# Both are validated before they reach a file name or an entitlement.
- id: version
name: Resolve preview version and public configuration
if: steps.gate.outputs.eligible == 'true'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ steps.pr.outputs.pr_number }}
HEAD_SHA: ${{ steps.pr.outputs.head_sha }}
BUILD_RUN_NUMBER: ${{ github.event.workflow_run.run_number }}
run: |
set -euo pipefail
head_file() {
gh api "repos/${GITHUB_REPOSITORY}/contents/$1?ref=${HEAD_SHA}" --jq '.content' | base64 --decode
}
base_version="$(head_file apps/desktop/package.json | node -p "JSON.parse(require('fs').readFileSync(0, 'utf8')).version")"
# The committed desktop version is always a plain X.Y.Z; every
# prerelease identifier is added by a release run. Anything else
# would also let a foreign -pr.N. marker into the asset name, which
# is what publish and cleanup key on.
if [[ ! "$base_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Unexpected desktop version '$base_version' at $HEAD_SHA; expected X.Y.Z." >&2
exit 1
fi
echo "version=${base_version}-pr.${PR_NUMBER}.${BUILD_RUN_NUMBER}" >> "$GITHUB_OUTPUT"
head_file .env.example > "$RUNNER_TEMP/head.env.example"
for key in clerk_publishable_key:T3CODE_CLERK_PUBLISHABLE_KEY clerk_jwt_template:T3CODE_CLERK_JWT_TEMPLATE clerk_cli_oauth_client_id:T3CODE_CLERK_CLI_OAUTH_CLIENT_ID relay_url:T3CODE_RELAY_URL; do
output="${key%%:*}"
name="${key##*:}"
value="$(sed -n "s/^${name}=//p" "$RUNNER_TEMP/head.env.example" | head -n 1)"
if [[ ! "$value" =~ ^[A-Za-z0-9._:/-]+$ ]]; then
echo "$name is missing or malformed in .env.example at $HEAD_SHA." >&2
exit 1
fi
echo "${output}=${value}" >> "$GITHUB_OUTPUT"
done
# Only the default-branch revision that owns this workflow supplies the
# validator. Never check out the PR in a workflow_run job.
- name: Checkout trusted artifact validator
if: steps.gate.outputs.eligible == 'true'
shell: bash
env:
CHECKOUT_REF: ${{ github.sha }}
GIT_TERMINAL_PROMPT: "0"
# Anonymous fetch avoids checkout's credential cleanup, which fails on
# orphaned gitlinks in .repos even when that directory is excluded.
run: |
set -euo pipefail
git init .
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
git fetch --no-tags --depth=1 origin "$CHECKOUT_REF"
git sparse-checkout set .github/scripts
git checkout --detach FETCH_HEAD
# Fetch the archive as bytes. Extracting it over the checkout, even with
# download-artifact, could replace code that runs with signing secrets.
- name: Download and validate PR JS bundle
if: steps.gate.outputs.eligible == 'true'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
ARTIFACT_ID: ${{ steps.pr.outputs.artifact_id }}
run: |
set -euo pipefail
gh api "repos/${GITHUB_REPOSITORY}/actions/artifacts/${ARTIFACT_ID}/zip" > "$RUNNER_TEMP/js-bundle.zip"
python3 .github/scripts/stage-preview-bundle.py "$RUNNER_TEMP/js-bundle.zip" "$RUNNER_TEMP/js-bundle"
# Only validated bundle files cross into the signing job's artifact.
- name: Stage JS bundle for packaging
if: steps.gate.outputs.eligible == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: js-bundle
path: ${{ runner.temp }}/js-bundle
if-no-files-found: error
# Re-running this workflow re-uploads under the same run.
overwrite: true
retention-days: 1
build:
name: Package and sign macOS arm64 preview
needs: resolve
if: needs.resolve.outputs.eligible == 'true'
concurrency:
group: desktop-macos-preview-${{ needs.resolve.outputs.pr_number }}-build
cancel-in-progress: true
# release-desktop.yml asks for actions: read (its Windows builds list artifacts).
permissions:
actions: read
contents: read
uses: ./.github/workflows/release-desktop.yml
secrets:
CSC_LINK: ${{ secrets.CSC_LINK }}
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
MACOS_PROVISIONING_PROFILE: ${{ secrets.MACOS_PROVISIONING_PROFILE }}
with:
version: ${{ needs.resolve.outputs.version }}
ref: ${{ github.sha }}
release_channel: preview
relay_client_tracing: false
clerk_publishable_key: ${{ needs.resolve.outputs.clerk_publishable_key }}
clerk_jwt_template: ${{ needs.resolve.outputs.clerk_jwt_template }}
clerk_cli_oauth_client_id: ${{ needs.resolve.outputs.clerk_cli_oauth_client_id }}
relay_url: ${{ needs.resolve.outputs.relay_url }}
label: macOS arm64 preview
runner: blacksmith-12vcpu-macos-26
platform: mac
target: dmg
arch: arm64
rust_target: aarch64-apple-darwin
resource_key: darwin-arm64
cli_archive: false
untrusted_bundle: true
# Release assets download without a GitHub account, unlike workflow
# artifacts. All preview DMGs live on one rolling prerelease tagged
# "desktop-preview" (release.yml only matches v*.*.* tags), so publishing a
# build never notifies release watchers.
publish:
name: Publish anonymous download
needs: [resolve, build]
if: needs.resolve.outputs.eligible == 'true' && needs.build.result == 'success'
runs-on: blacksmith-8vcpu-ubuntu-2404
timeout-minutes: 10
# Its own group, so a publish never cancels a newer commit's signing job
# (they would share the build group) and is never cancelled mid-upload.
# preview_eligible's head check keeps a superseded publish from landing.
concurrency:
group: desktop-macos-preview-${{ needs.resolve.outputs.pr_number }}-publish
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
steps:
- name: Download macOS artifacts
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: desktop-mac-arm64
path: release
- id: upload
name: Upload DMG to the rolling preview release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ needs.resolve.outputs.pr_number }}
HEAD_SHA: ${{ needs.resolve.outputs.head_sha }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -euo pipefail
tag="desktop-preview"
# True while the PR is open and still points at the commit this
# build came from. The label was consumed in resolve, so it is not
# part of this check. A push does not cancel an already-running
# signing job, so this is what keeps a superseded commit's DMG off
# the release.
preview_eligible() {
[[ "$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" \
--json state,headRefOid \
--jq '.state + " " + .headRefOid')" == "OPEN $HEAD_SHA" ]]
}
# The build ran for many minutes. If the PR closed or moved on
# meanwhile, cleanup already ran in its own concurrency group or a
# newer build owns the asset, so publishing now would resurrect a
# deleted download or clobber a newer one.
if ! preview_eligible; then
echo "PR closed or head moved while building. Skipping publish."
exit 0
fi
shopt -s nullglob
dmg_files=(release/*.dmg)
if (( ${#dmg_files[@]} != 1 )); then
printf 'Expected one DMG, found %s.\n' "${#dmg_files[@]}" >&2
exit 1
fi
dmg_path="${dmg_files[0]}"
# Requiring this PR's marker keeps a build from clobbering or
# deleting another PR's asset, since those names carry a different
# -pr.N. marker.
if [[ "$(basename "$dmg_path")" != *"-pr.${PR_NUMBER}."* ]]; then
echo "DMG name '$(basename "$dmg_path")' does not carry this PR's -pr.${PR_NUMBER}. marker. Refusing to publish." >&2
exit 1
fi
if ! gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
# "|| true" tolerates a concurrent publish job creating the
# release between the check and the create.
gh release create "$tag" \
--repo "$GITHUB_REPOSITORY" \
--target "$DEFAULT_BRANCH" \
--prerelease \
--title "Desktop preview builds" \
--notes "Rolling desktop builds from pull requests with a preview label. Each download is removed when its pull request closes or loses the label. Install stable builds from the latest release instead." \
|| true
fi
# Keep one DMG per PR: drop this PR's older builds first. The
# trailing dot keeps -pr.12. from matching -pr.123. builds.
gh release view "$tag" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name' \
| { grep -F -- "-pr.${PR_NUMBER}." || true; } \
| while read -r asset; do
gh release delete-asset "$tag" "$asset" --repo "$GITHUB_REPOSITORY" --yes \
|| echo "Asset $asset was already removed by a concurrent run."
done
gh release upload "$tag" "$dmg_path" --repo "$GITHUB_REPOSITORY" --clobber
# Re-check after uploading. A cleanup run that started during the
# upload listed assets before ours existed, so it cannot delete it.
# Whichever writer acts last sees the final PR state; if the preview
# became ineligible, delete what we just uploaded.
if ! preview_eligible; then
gh release delete-asset "$tag" "$(basename "$dmg_path")" --repo "$GITHUB_REPOSITORY" --yes \
|| echo "Asset was already removed by a concurrent run."
echo "PR closed or head moved during upload. Removed the download."
exit 0
fi
echo "dmg_name=$(basename "$dmg_path")" >> "$GITHUB_OUTPUT"
echo "download_url=https://github.com/${GITHUB_REPOSITORY}/releases/download/${tag}/$(basename "$dmg_path")" >> "$GITHUB_OUTPUT"
- name: Comment download link
if: steps.upload.outputs.download_url != ''
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
PR_NUMBER: ${{ needs.resolve.outputs.pr_number }}
DOWNLOAD_URL: ${{ steps.upload.outputs.download_url }}
HEAD_SHA: ${{ needs.resolve.outputs.head_sha }}
PREVIEW_VERSION: ${{ needs.resolve.outputs.version }}
with:
script: |
const prNumber = Number(process.env.PR_NUMBER);
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
if (pullRequest.head.sha !== process.env.HEAD_SHA || pullRequest.state !== "open") {
core.info("Skipping the outdated macOS preview comment.");
return;
}
const marker = "<!-- desktop-macos-preview -->";
const body = [
marker,
"### macOS preview",
"",
`[Download Apple Silicon DMG](${process.env.DOWNLOAD_URL})`,
"",
`Version: ${process.env.PREVIEW_VERSION}`,
`Commit: ${process.env.HEAD_SHA.slice(0, 7)}`,
"",
"Signed and notarized, with T3 Connect enabled. The app bundle (server, web client, Electron main) is built from this PR; packaging, native helpers, and desktop dependencies come from `main`.",
"",
"No GitHub sign-in is needed. The download stays available until this PR closes. The `preview:mac` label was consumed by this build; a maintainer applies it again to build a newer commit.",
].join("\n");
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
const existing = comments.find(
(comment) => comment.user?.login === "github-actions[bot]" && comment.body?.includes(marker),
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}
cleanup:
name: Remove preview download
# A published preview no longer carries the label (resolve consumed it),
# so every close must look for assets; the -pr.N. filter below makes
# that a cheap no-op for PRs that never had one. A manual unlabel before
# the build consumed it withdraws the request and drops any older
# download too.
if: >-
github.event_name == 'pull_request_target' &&
(github.event.action == 'closed' ||
(github.event.action == 'unlabeled' && github.event.label.name == 'preview:mac'))
# Runs on every PR close and usually finds nothing. Keep it cheap.
runs-on: ubuntu-24.04
timeout-minutes: 10
# Cleanup runs must complete: a close event right after an unlabel queues
# behind the running cleanup instead of canceling it mid-delete.
concurrency:
group: desktop-macos-preview-${{ github.event.pull_request.number }}-cleanup
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
steps:
- id: delete
name: Delete this PR's preview assets
shell: bash
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail
tag="desktop-preview"
# A stale cleanup must not delete a download that became valid
# again. If the PR is open and labeled once more, the next publish
# owns this PR's assets and replaces them itself.
if [[ "$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" \
--json state,labels \
--jq '.state + " " + (.labels | map(.name) | contains(["preview:mac"]) | tostring)')" == "OPEN true" ]]; then
echo "PR is open and labeled again. Skipping cleanup."
echo "removed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "removed=true" >> "$GITHUB_OUTPUT"
if ! gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "No preview release exists. Nothing to clean up."
exit 0
fi
gh release view "$tag" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name' \
| { grep -F -- "-pr.${PR_NUMBER}." || true; } \
| while read -r asset; do
gh release delete-asset "$tag" "$asset" --repo "$GITHUB_REPOSITORY" --yes \
|| echo "Asset $asset was already removed by a concurrent run."
done
- name: Mark the preview comment as removed
if: steps.delete.outputs.removed == 'true'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const marker = "<!-- desktop-macos-preview -->";
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
per_page: 100,
});
const existing = comments.find(
(comment) => comment.user?.login === "github-actions[bot]" && comment.body?.includes(marker),
);
if (!existing) {
return;
}
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: [
marker,
"### macOS preview",
"",
"The preview download was removed because this PR closed or the preview label was removed.",
].join("\n"),
});