Repository navigation
684 lines (619 loc) · 32 KB
/
Copy pathcreate-github-release.yml
File metadata and controls
684 lines (619 loc) · 32 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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
name: 📦 Create GitHub Release
on:
workflow_run:
workflows: ["🔨 Build Mudlet", "🔨 Build Mudlet (windows)"]
types: [completed]
branches: [master, development, release-*, Mudlet-*]
# actions: write is for starting the Linux package build once a release is out
permissions:
contents: write
actions: write
jobs:
create-release:
runs-on: ubuntu-latest
if: >
github.repository_owner == 'Mudlet' &&
github.event.workflow_run.conclusion == 'success'
# Both build workflows trigger this; don't cancel the first - the second completes the release. Held by this
# job, not the run: the package build's attach job takes this group while linux-packages waits on that build.
concurrency:
group: create-github-release-${{ github.event.workflow_run.head_sha }}
cancel-in-progress: false
outputs:
type: ${{ steps.release-type.outputs.type }}
tag: ${{ steps.release-type.outputs.tag }}
published: ${{ steps.verify.outputs.published }}
steps:
- name: Check if platform builds completed
id: check
uses: actions/github-script@v9
with:
script: |
const triggeringRun = context.payload.workflow_run;
if (triggeringRun.event === 'pull_request') {
core.info(`Skipping: triggered by a pull_request build`);
core.setOutput('ready', 'false');
return;
}
const sha = triggeringRun.head_sha;
const platforms = {
'linux_macos': 'build-mudlet.yml',
'windows': 'build-mudlet-win.yml'
};
const runIds = {};
for (const [key, filename] of Object.entries(platforms)) {
const {data} = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: filename,
head_sha: sha,
status: 'success',
event: triggeringRun.event,
per_page: 1
});
if (data.total_count === 0) {
core.info(`Workflow "${filename}" has not completed successfully yet for ${sha}`);
} else {
runIds[key] = data.workflow_runs[0].id;
}
}
const totalPlatforms = Object.keys(platforms).length;
const completedCount = Object.keys(runIds).length;
if (completedCount === 0) {
core.info('No platform builds have succeeded yet');
core.setOutput('ready', 'false');
return;
}
// Release builds must wait for all platforms; PTBs can proceed with partial
if (completedCount < totalPlatforms && triggeringRun.head_branch !== 'development') {
core.info(`Only ${completedCount}/${totalPlatforms} platforms completed - waiting for all platforms (release build)`);
core.setOutput('ready', 'false');
return;
}
core.setOutput('ready', 'true');
core.setOutput('linux_macos_run_id', runIds['linux_macos'] || '');
core.setOutput('windows_run_id', runIds['windows'] || '');
# Checkout early so .git exists before artifact downloads — actions/checkout
# wipes the workspace when no .git directory is present, even with clean: false
- uses: actions/checkout@v7
if: steps.check.outputs.ready == 'true'
with:
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
# We are just reading the logs, so we don't need the files
filter: blob:none
# workflow_run always runs this file from the default branch, while the
# checkout above is the commit that was built - which may predate the release
# scripts below. Take them from the same ref as this workflow file.
- uses: actions/checkout@v7
if: steps.check.outputs.ready == 'true'
with:
ref: ${{ github.workflow_sha }}
path: release-scripts
fetch-depth: 1
- uses: leafo/gh-actions-lua@v13
if: steps.check.outputs.ready == 'true'
with:
luaVersion: "5.1.5"
- uses: leafo/gh-actions-luarocks@v6
if: steps.check.outputs.ready == 'true'
- name: Install changelog dependencies
if: steps.check.outputs.ready == 'true'
run: |
luarocks install argparse
luarocks install lunajson
# Download build metadata to determine if this is a release or PTB build (not present for snapshot/PR builds)
- name: Download metadata from Linux/macOS build
if: steps.check.outputs.ready == 'true' && steps.check.outputs.linux_macos_run_id != ''
id: download-metadata-lm
uses: actions/download-artifact@v8
continue-on-error: true
with:
pattern: release-metadata-*
run-id: ${{ steps.check.outputs.linux_macos_run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: metadata/
- name: Download metadata from Windows build
if: steps.check.outputs.ready == 'true' && steps.download-metadata-lm.outcome != 'success' && steps.check.outputs.windows_run_id != ''
id: download-metadata-win
uses: actions/download-artifact@v8
continue-on-error: true
with:
pattern: release-metadata-*
run-id: ${{ steps.check.outputs.windows_run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: metadata/
- name: Report skipped release
if: steps.check.outputs.ready == 'true' && steps.download-metadata-lm.outcome != 'success' && steps.download-metadata-win.outcome != 'success'
run: echo "::warning::Release metadata download failed - cannot determine release type"
- name: Determine release type
if: steps.check.outputs.ready == 'true' && (steps.download-metadata-lm.outcome == 'success' || steps.download-metadata-win.outcome == 'success')
id: release-type
run: |
META_FILE=$(find metadata/ -name 'release-metadata.json' -type f | head -1)
if [[ -z "${META_FILE}" ]]; then
echo "No release metadata found - this is likely a snapshot or PR build"
echo "type=skip" >> "$GITHUB_OUTPUT"
exit 0
fi
META=$(cat "${META_FILE}")
REF=$(echo "$META" | jq -r '.ref')
EVENT=$(echo "$META" | jq -r '.event')
VERSION=$(echo "$META" | jq -r '.version')
BUILD_SUFFIX=$(echo "$META" | jq -r '.build_suffix')
if [[ -z "${VERSION}" || "${VERSION}" == "null" ]]; then
echo "::error::VERSION field is empty or missing in release metadata"
exit 1
fi
if [[ -z "${REF}" || "${REF}" == "null" ]]; then
echo "::error::REF field is empty or missing in release metadata"
exit 1
fi
COMMIT=$(echo "$META" | jq -r '.commit')
if [[ "$REF" == refs/tags/Mudlet-* ]]; then
# release-scripts/ is this workflow's own ref, so the guard is present
# even when the tagged commit predates it
bash release-scripts/CI/check-release-tag.sh "${VERSION}" "${REF#refs/tags/}"
echo "type=release" >> "$GITHUB_OUTPUT"
echo "tag=${REF#refs/tags/}" >> "$GITHUB_OUTPUT"
echo "title=Mudlet ${VERSION}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
elif [[ "$EVENT" == "schedule" ]] || [[ "$BUILD_SUFFIX" == -ptb* ]]; then
if [[ -z "${COMMIT}" || "${COMMIT}" == "null" ]]; then
echo "::error::COMMIT field is empty or missing in release metadata for PTB"
exit 1
fi
# Nothing validates APP_VERSION on development, and a two-component one
# makes a PTB unofferable the same way
bash release-scripts/CI/check-release-tag.sh "${VERSION}"
PTB_TAG="Mudlet-${VERSION}${BUILD_SUFFIX}-${COMMIT}"
echo "type=ptb" >> "$GITHUB_OUTPUT"
echo "tag=${PTB_TAG}" >> "$GITHUB_OUTPUT"
echo "title=Public Test Build" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
else
echo "type=skip" >> "$GITHUB_OUTPUT"
fi
# Download all release assets from both workflow runs
- name: Download Linux/macOS release assets
if: (steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb') && steps.check.outputs.linux_macos_run_id != ''
id: download-linux-macos
continue-on-error: true
uses: actions/download-artifact@v8
with:
pattern: release-asset-*
run-id: ${{ steps.check.outputs.linux_macos_run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: assets/
- name: Download Windows release assets
if: (steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb') && steps.check.outputs.windows_run_id != ''
id: download-windows
continue-on-error: true
uses: actions/download-artifact@v8
with:
pattern: release-asset-*
run-id: ${{ steps.check.outputs.windows_run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: assets/
# A download that fails leaves the release short of a platform, so surface it
# rather than letting continue-on-error hide it
- name: Report asset download failures
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
env:
LINUX_MACOS_OUTCOME: ${{ steps.download-linux-macos.outcome }}
WINDOWS_OUTCOME: ${{ steps.download-windows.outcome }}
run: |
if [[ "${LINUX_MACOS_OUTCOME}" == "failure" ]]; then
echo "::warning::Downloading the Linux/macOS release assets failed - they will be missing from this release"
fi
if [[ "${WINDOWS_OUTCOME}" == "failure" ]]; then
echo "::warning::Downloading the Windows release assets failed - it will be missing from this release"
fi
- name: Prepare release assets
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
env:
RELEASE_TAG: ${{ steps.release-type.outputs.tag }}
RELEASE_TYPE: ${{ steps.release-type.outputs.type }}
run: bash release-scripts/CI/prepare-release-assets.sh assets/ "${RELEASE_TAG}" "${RELEASE_TYPE}"
# The release may already carry assets from the other build workflow's run of
# this job, so its SHA256SUMS.txt has to be merged rather than overwritten
- name: Fetch published SHA256SUMS.txt
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
env:
RELEASE_TAG: ${{ steps.release-type.outputs.tag }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p published/
if ! gh release view "${RELEASE_TAG}" 2> view-error.txt; then
if grep -qi 'release not found' view-error.txt; then
echo "Release ${RELEASE_TAG} does not exist yet - no checksums to merge"
exit 0
fi
cat view-error.txt
echo "::error::Could not read release ${RELEASE_TAG} - refusing to rebuild its checksums from a partial view"
exit 1
fi
if gh release download "${RELEASE_TAG}" --pattern SHA256SUMS.txt --dir published/; then
echo "Already published on ${RELEASE_TAG}:"
cat published/SHA256SUMS.txt
else
echo "::warning::${RELEASE_TAG} exists but its SHA256SUMS.txt could not be downloaded - any entry only it covers will be lost"
fi
# Assemble SHA256SUMS.txt from per-platform .sha256 sidecar files
- name: Assemble SHA256SUMS.txt
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
run: bash release-scripts/CI/assemble-release-checksums.sh assets/ published/SHA256SUMS.txt
- name: Generate changelog
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
env:
RELEASE_TYPE: ${{ steps.release-type.outputs.type }}
RELEASE_TAG: ${{ steps.release-type.outputs.tag }}
run: |
# GitHub refuses a release body over 125000 characters, and then publishes
# nothing at all; the margin below that is headroom
NOTES_LIMIT=120000
fit_notes() {
bash release-scripts/CI/fit-release-notes.sh "$@"
}
# By merge date from the range's oldest commit, as a compare link lists only 250
# commits; a failure falls back to every merged PR rather than cost the release
merged_prs_url() {
local search="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pulls?q=is%3Apr+is%3Amerged" from to
from=$(TZ=UTC git log --date=format-local:%Y-%m-%dT%H:%M:%SZ --format=%cd "$1..$2" | sort | head -1)
if [[ -n "${from}" ]] && to=$(TZ=UTC git log -1 --date=format-local:%Y-%m-%d --format=%cd "$2"); then
echo "${search}+merged%3A%3E%3D${from//:/%3A}+merged%3A%3C%3D${to}"
else
echo "::warning::Could not date $1..$2, so cut release notes link to every merged pull request" >&2
echo "${search}"
fi
}
if [[ "${RELEASE_TYPE}" == "release" ]]; then
# For release: changelog from previous stable release tag to this tag
PREV_TAG=$(git tag --sort=-version:refname | grep '^Mudlet-' | grep -v -- '-ptb' | grep -v "^${RELEASE_TAG}$" | head -1)
echo "Generating changelog from ${PREV_TAG} to ${RELEASE_TAG}"
if [[ -n "${PREV_TAG}" ]]; then
if ! RELEASE_CHANGELOG=$(lua CI/generate-changelog.lua -f md -m release \
--start-commit "${PREV_TAG}" --end-commit "${RELEASE_TAG}"); then
echo "::error::Changelog generation failed for stable release"
exit 1
fi
echo "${RELEASE_CHANGELOG}" | fit_notes "${NOTES_LIMIT}" "$(merged_prs_url "${PREV_TAG}" "${RELEASE_TAG}")" > changelog.md
else
echo "::error::No previous release tag found - cannot generate changelog for stable release"
exit 1
fi
else
# For PTB: short changelog since last PTB (prominent) + full changelog since last stable release (collapsed)
STABLE_TAG=$(git tag --sort=-version:refname | grep '^Mudlet-' | grep -v -- '-ptb' | head -1)
PTB_TAG=$(git tag --sort=-version:refname | grep '^Mudlet-' | grep -- '-ptb' | grep -v "^${RELEASE_TAG}$" | head -1)
# Verify the PTB tag is an ancestor of HEAD
if [[ -n "${PTB_TAG}" ]] && ! git merge-base --is-ancestor "${PTB_TAG}" HEAD; then
echo "::warning::Latest PTB tag ${PTB_TAG} is not an ancestor of HEAD, skipping PTB diff"
PTB_TAG=""
fi
# Generate the full changelog since last stable release
FULL_CHANGELOG=""
if [[ -n "${STABLE_TAG}" ]]; then
echo "Generating full changelog from ${STABLE_TAG} to HEAD"
if ! FULL_CHANGELOG=$(lua CI/generate-changelog.lua -f md -m release \
--start-commit "${STABLE_TAG}" --end-commit HEAD); then
echo "::warning::Full changelog generation failed (from ${STABLE_TAG} to HEAD)"
FULL_CHANGELOG=""
fi
fi
# Generate the incremental changelog since last PTB
PTB_CHANGELOG=""
if [[ -n "${PTB_TAG}" ]]; then
echo "Generating PTB changelog from ${PTB_TAG} to HEAD"
if ! PTB_CHANGELOG=$(lua CI/generate-changelog.lua -f md -m release \
--start-commit "${PTB_TAG}" --end-commit HEAD); then
echo "::warning::PTB changelog generation failed (from ${PTB_TAG} to HEAD)"
PTB_CHANGELOG=""
fi
fi
# Assemble the combined changelog
if [[ -n "${PTB_CHANGELOG}" && -n "${FULL_CHANGELOG}" ]]; then
# The PTB's own changes come first, the full changelog gets what is left.
# 2000 bytes keeps room for the wrapper and the full changelog's closing line
{
echo "#### Changes in this build since the previous PTB (${PTB_TAG})"
echo ""
echo "${PTB_CHANGELOG}" | fit_notes "$((NOTES_LIMIT - 2000))" "$(merged_prs_url "${PTB_TAG}" HEAD)"
echo ""
echo "<details>"
echo "<summary>Full changelog since last release (${STABLE_TAG})</summary>"
echo ""
} > changelog.md
CLOSING=$'\n</details>\n'
FULL_BUDGET=$((NOTES_LIMIT - $(wc -c < changelog.md) - ${#CLOSING}))
{
echo "${FULL_CHANGELOG}" | fit_notes "${FULL_BUDGET}" "$(merged_prs_url "${STABLE_TAG}" HEAD)"
printf '%s' "${CLOSING}"
} >> changelog.md
elif [[ -n "${FULL_CHANGELOG}" ]]; then
# No previous PTB or first PTB after a release - just show full changelog
echo "${FULL_CHANGELOG}" | fit_notes "${NOTES_LIMIT}" "$(merged_prs_url "${STABLE_TAG}" HEAD)" > changelog.md
else
echo "::warning::Changelog generation failed, using placeholder"
echo "See commit history for changes." > changelog.md
fi
fi
echo "Changelog preview:"
head -20 changelog.md
# Clean up old PTB releases, keeping only the latest 1 (+ the new one = 2 total)
- name: Clean up old PTB releases
if: steps.release-type.outputs.type == 'ptb'
env:
RELEASE_TAG: ${{ steps.release-type.outputs.tag }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Filter by -ptb in tag name to avoid deleting non-PTB prereleases (e.g. release candidates).
# Exclude the current tag so we never delete what we are about to publish.
gh release list --limit 100 --json tagName,isPrerelease,createdAt \
--jq '[.[] | select(.isPrerelease and (.tagName | contains("-ptb")))] | sort_by(.createdAt) | reverse | .[1:] | .[].tagName' | \
while IFS= read -r old_tag; do
if [[ "${old_tag}" == "${RELEASE_TAG}" ]]; then
continue
fi
echo "Cleaning up old PTB release: ${old_tag}"
gh release delete "${old_tag}" --yes --cleanup-tag 2>/dev/null || true
done
# Create the release if it doesn't exist yet, or upload any missing assets.
# Both build workflows trigger this job so it runs twice per commit - this
# avoids the old delete+recreate cycle that spammed notifications.
- name: Create or update GitHub Release
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
env:
RELEASE_TYPE: ${{ steps.release-type.outputs.type }}
RELEASE_TAG: ${{ steps.release-type.outputs.tag }}
RELEASE_TITLE: ${{ steps.release-type.outputs.title }}
TARGET_SHA: ${{ github.event.workflow_run.head_sha }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Everything in assets/ except the per-platform sidecars, which only feed
# SHA256SUMS.txt. Not a list of binary suffixes: a new asset type must not
# be able to reach the release without the checksum gate below seeing it.
mapfile -t BINARIES < <(find assets/ -type f ! -name '*.sha256' ! -name 'SHA256SUMS.txt')
if [[ ${#BINARIES[@]} -eq 0 ]]; then
echo "::error::No release files found to upload"
exit 1
fi
echo "Files to upload:"
printf '%s\n' assets/SHA256SUMS.txt "${BINARIES[@]}"
# Guard against publishing a binary SHA256SUMS.txt does not cover: the
# release ends up holding what is already on it plus what we upload now
: > final-assets.txt
if gh release view "${RELEASE_TAG}" --json assets --jq '.assets[].name' >> final-assets.txt 2> view-error.txt; then
RELEASE_EXISTS=yes
elif grep -qi 'release not found' view-error.txt; then
RELEASE_EXISTS=no
else
cat view-error.txt
echo "::error::Could not list the assets already published on ${RELEASE_TAG} - refusing to publish without checking checksum coverage"
exit 1
fi
basename -a -- "${BINARIES[@]}" >> final-assets.txt
echo "Assets the release will hold afterwards:"
sort -u final-assets.txt
bash release-scripts/CI/verify-release-checksums.sh assets/SHA256SUMS.txt final-assets.txt assets/
# SHA256SUMS.txt first: it is a superset of the old and new binaries, so if
# the upload dies partway the release is never left holding an uncovered one
if [[ "${RELEASE_EXISTS}" == "yes" ]]; then
echo "Release ${RELEASE_TAG} already exists - uploading any missing assets"
gh release upload "${RELEASE_TAG}" assets/SHA256SUMS.txt --clobber
gh release upload "${RELEASE_TAG}" "${BINARIES[@]}" --clobber
else
ARGS=(
"${RELEASE_TAG}"
--title "${RELEASE_TITLE}"
--notes-file changelog.md
)
if [[ "${RELEASE_TYPE}" == "ptb" ]]; then
ARGS+=(--prerelease --target "${TARGET_SHA}")
fi
gh release create "${ARGS[@]}" assets/SHA256SUMS.txt \
|| gh release upload "${RELEASE_TAG}" assets/SHA256SUMS.txt --clobber
gh release upload "${RELEASE_TAG}" "${BINARIES[@]}" --clobber
fi
# Confirm against the live release, not just the files we meant to upload
- name: Verify published release checksums
id: verify
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
env:
RELEASE_TAG: ${{ steps.release-type.outputs.tag }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# A freshly uploaded asset is not always immediately readable, so retry
# rather than declaring a good release broken
for attempt in 1 2 3 4 5; do
rm -rf published-final/
mkdir -p published-final/
if gh release download "${RELEASE_TAG}" --pattern SHA256SUMS.txt --dir published-final/ \
&& gh release view "${RELEASE_TAG}" --json assets --jq '.assets[].name' > published-final/assets.txt; then
break
fi
if [[ "${attempt}" -eq 5 ]]; then
echo "::error::Could not read back the published ${RELEASE_TAG} assets to verify them"
exit 1
fi
echo "Attempt ${attempt} could not read the published release yet - retrying"
sleep 10
done
echo "Published assets:"
cat published-final/assets.txt
bash release-scripts/CI/verify-release-checksums.sh published-final/SHA256SUMS.txt published-final/assets.txt
echo "published=true" >> "$GITHUB_OUTPUT"
# Generate and upload Sparkle appcast XML for macOS updates
- name: Add SSH agent for appcast upload
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.UPLOAD_PRIVATEKEY }}
- name: Generate Sparkle appcast XML
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
env:
RELEASE_TYPE: ${{ steps.release-type.outputs.type }}
RELEASE_TAG: ${{ steps.release-type.outputs.tag }}
RELEASE_VERSION: ${{ steps.release-type.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p appcast
# sparkle:version must match CFBundleVersion in the built app
export BUNDLE_VERSION="${RELEASE_TAG#Mudlet-}"
export RELEASE_VERSION
# From the built commit at the workspace root, not release-scripts/, so the
# feed matches the LSMinimumSystemVersion of the app it offers
MIN_MACOS=$(sed -n 's/^ *set(CMAKE_OSX_DEPLOYMENT_TARGET "\([0-9.]*\)".*/\1/p' CMakeLists.txt)
if [[ -z "${MIN_MACOS}" ]]; then
echo "::error::Could not read CMAKE_OSX_DEPLOYMENT_TARGET from CMakeLists.txt"
exit 1
fi
export MIN_MACOS
# Convert changelog to HTML for Sparkle's description field. Not exported:
# one environment variable over 128KB makes every later command fail
CHANGELOG_HTML=""
if [[ -f changelog.md ]]; then
CHANGELOG_HTML=$(pandoc changelog.md -f markdown -t html --no-highlight 2>/dev/null || true)
fi
if [[ -z "${CHANGELOG_HTML}" ]]; then
CHANGELOG_HTML="<p>See <a href='https://github.com/Mudlet/Mudlet/releases/tag/${RELEASE_TAG}'>release notes</a> for details.</p>"
fi
CHANNEL="release"
if [[ "${RELEASE_TYPE}" == "ptb" ]]; then
CHANNEL="ptb"
fi
export PUB_DATE=$(date -R)
# Get asset download URLs from the GitHub Release
RELEASE_JSON=$(gh release view "${RELEASE_TAG}" --json assets)
for ARCH in arm64 x86_64; do
DMG_FILE=$(find assets/ -name "*-${ARCH}.dmg" -type f | head -1)
if [[ -z "${DMG_FILE}" ]]; then
echo "No macOS DMG found for ${ARCH} - skipping appcast"
continue
fi
export FILE_SIZE=$(stat --printf="%s" "${DMG_FILE}")
DMG_NAME=$(basename "${DMG_FILE}")
export DOWNLOAD_URL=$(echo "${RELEASE_JSON}" | jq -r --arg name "${DMG_NAME}" '.assets[] | select(.name == $name) | .url')
if [[ -z "${DOWNLOAD_URL}" || "${DOWNLOAD_URL}" == "null" ]]; then
echo "::warning::Could not find download URL for ${DMG_NAME}"
continue
fi
# Unquoted: the values of the variables below are not expanded again, so the
# HTML is safe, but a literal $, ` or \ added to the template would be
cat > "appcast/${CHANNEL}-${ARCH}.xml" << APPCAST_EOF
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Mudlet Updates</title>
<description>Updates for Mudlet</description>
<language>en</language>
<item>
<title>Mudlet $RELEASE_VERSION</title>
<pubDate>$PUB_DATE</pubDate>
<sparkle:version>$BUNDLE_VERSION</sparkle:version>
<sparkle:shortVersionString>$RELEASE_VERSION</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>$MIN_MACOS</sparkle:minimumSystemVersion>
<description><![CDATA[$CHANGELOG_HTML]]></description>
<enclosure
url="$DOWNLOAD_URL"
length="$FILE_SIZE"
type="application/octet-stream"/>
</item>
</channel>
</rss>
APPCAST_EOF
echo "Generated appcast/${CHANNEL}-${ARCH}.xml (version=${BUNDLE_VERSION}, size=${FILE_SIZE})"
done
echo "Generated appcast files:"
ls -la appcast/ 2>/dev/null || echo "No appcast files generated"
- name: Upload appcast to mudlet.org
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
env:
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
run: |
shopt -s nullglob
APPCAST_FILES=(appcast/*.xml)
shopt -u nullglob
if [[ ${#APPCAST_FILES[@]} -eq 0 ]]; then
echo "::warning::No appcast files to upload"
exit 0
fi
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
[email protected] "mkdir -p \"${DEPLOY_PATH}/appcast\""
for f in "${APPCAST_FILES[@]}"; do
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
"$f" "[email protected]:${DEPLOY_PATH}/appcast/"
echo "Uploaded $(basename "$f")"
done
- name: Verify appcast upload
if: steps.release-type.outputs.type == 'release' || steps.release-type.outputs.type == 'ptb'
run: |
shopt -s nullglob
APPCAST_FILES=(appcast/*.xml)
shopt -u nullglob
for f in "${APPCAST_FILES[@]}"; do
basename=$(basename "$f")
url="https://www.mudlet.org/wp-content/files/appcast/${basename}"
if curl --output /dev/null --silent --head --fail "$url"; then
echo "Verified: ${url}"
else
echo "::warning::Appcast not yet accessible at ${url}"
fi
done
# A GITHUB_TOKEN release fires no release event, so start the package build here. A job of its own so
# waiting on it holds up nothing else, and so a failed package build turns this run red.
linux-packages:
name: Build the Linux packages
needs: create-release
# once the release is verified, even if a later step such as the appcast upload then fails
if: >
needs.create-release.outputs.published == 'true' &&
!cancelled() &&
needs.create-release.outputs.type == 'release' &&
vars.LINUX_PACKAGES_BASE_URL != ''
runs-on: ubuntu-latest
# room for the package build's queueing, its 120-minute matrix jobs, and its attach and publish jobs
timeout-minutes: 240
steps:
- name: Start the Linux package build and wait for it
env:
RELEASE_TAG: ${{ needs.create-release.outputs.tag }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
runs_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/workflows/build-linux-packages.yml"
# not retried: a request that failed may still have started a build
if ! started=$(gh workflow run build-linux-packages.yml --repo "${GITHUB_REPOSITORY}" -f tag="${RELEASE_TAG}" -f publish=true); then
echo "::error::Could not start the Linux package build for ${RELEASE_TAG}, check ${runs_url} before starting one by hand"
exit 1
fi
run_id=$(grep -oE '/actions/runs/[0-9]+' <<< "${started}" | grep -oE '[0-9]+$' || true)
if [[ -z "${run_id}" ]]; then
echo "::error::Started the Linux package build for ${RELEASE_TAG} but GitHub did not say which run it is, check ${runs_url}"
exit 1
fi
url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${run_id}"
echo "Linux package build for ${RELEASE_TAG}: ${url}" >> "$GITHUB_STEP_SUMMARY"
echo "Waiting for the Linux package build at ${url}"
# polled rather than gh run watch, which spends several requests a minute and gives up on one failed
# request; 46 polls 5 minutes apart end before timeout-minutes, so the error below still names the build
result=""
for _ in $(seq 1 46); do
sleep 300
result=$(gh run view "${run_id}" --repo "${GITHUB_REPOSITORY}" --json status,conclusion \
--jq '.status + " " + .conclusion') || result=""
if [[ "${result}" == completed* ]]; then
break
fi
done
case "${result}" in
"completed success")
;;
completed*)
echo "::error::The Linux package build for ${RELEASE_TAG} ended '${result#completed }': ${url}"
exit 1
;;
*)
echo "::error::The Linux package build for ${RELEASE_TAG} had not finished after 230 minutes (last status: '${result:-unknown}'), it may still be running: ${url}"
exit 1
;;
esac