Repository navigation
1641 lines (1541 loc) · 64.7 KB
/
Copy pathrelease.yml
File metadata and controls
1641 lines (1541 loc) · 64.7 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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Create Release
on:
workflow_dispatch:
inputs:
version:
description: "Version number (e.g., 1.2.3, 1.2.3b1, or 1.2.3.dev1)"
required: true
type: string
channel:
description: "Release channel"
required: true
type: choice
options:
- stable
- beta
- rc
- nightly
source_sha:
description: "Exact full commit SHA for draft/published recovery; leave empty to resolve the current channel branch head"
required: false
type: string
important_notes:
description: "Important notes (breaking changes, critical info, etc.)"
required: false
workflow_call:
inputs:
version:
description: "Version number (e.g., 1.2.3, 1.2.3b1, or 1.2.3.dev1)"
required: true
type: string
channel:
description: "Release channel"
required: true
type: string
source_sha:
description: "Exact source commit to release"
required: true
type: string
important_notes:
description: "Important notes (breaking changes, critical info, etc.)"
required: false
type: string
secrets:
MUSIC_ASSISTANT_BOT_PRIVATE_KEY:
required: true
env:
BASE_IMAGE_VERSION_STABLE: "1.6.3"
BASE_IMAGE_VERSION_BETA: "1.7.0"
BASE_IMAGE_VERSION_NIGHTLY: "1.7.0"
EXPECTED_APP_SLUG: musicassistant-bot
EXPECTED_APP_INSTALLATION_ID: "146062122"
permissions:
contents: read
concurrency:
group: immutable-release
cancel-in-progress: false
jobs:
resolve:
name: Resolve and validate release state
runs-on: ubuntu-latest
permissions:
# GitHub only includes draft releases for tokens with push access.
contents: write
outputs:
branch: ${{ steps.branch.outputs.branch }}
source_sha: ${{ steps.source.outputs.sha }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
base_image_version: ${{ steps.version.outputs.base_image_version }}
release_state: ${{ steps.state.outputs.release_state }}
is_current: ${{ steps.state.outputs.is_current }}
release_id: ${{ steps.state.outputs.release_id }}
assets_ready: ${{ steps.state.outputs.assets_ready }}
wheel_name: ${{ steps.state.outputs.wheel_name }}
wheel_size: ${{ steps.state.outputs.wheel_size }}
wheel_sha256: ${{ steps.state.outputs.wheel_sha256 }}
sdist_name: ${{ steps.state.outputs.sdist_name }}
sdist_size: ${{ steps.state.outputs.sdist_size }}
sdist_sha256: ${{ steps.state.outputs.sdist_sha256 }}
steps:
# The dispatch ref picks the release tooling (github.workflow_sha), so keep it on dev.
# Under workflow_call, github.ref is the ref the calling workflow ran from.
- name: Require dispatch from dev
env:
DISPATCH_REF: ${{ github.ref }}
run: |
if [ "$DISPATCH_REF" != "refs/heads/dev" ]; then
echo "::error::Run this workflow from the dev branch, not $DISPATCH_REF. The channel still decides which branch gets released."
exit 1
fi
- name: Check out release workflow
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.workflow_sha }}
path: .release-workflow
persist-credentials: false
- name: Resolve source branch
id: branch
run: >-
python3 .release-workflow/scripts/release_workflow.py branch
--channel "${{ inputs.channel }}"
--github-output "$GITHUB_OUTPUT"
- name: Check out source branch
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ steps.branch.outputs.branch }}
fetch-depth: 0
path: source
persist-credentials: false
- name: Resolve exact source commit
id: source
env:
REQUESTED_SHA: ${{ inputs.source_sha }}
run: |
branch_sha=$(git -C source rev-parse HEAD)
if [ -n "$REQUESTED_SHA" ]; then
requested_sha=$(printf '%s' "$REQUESTED_SHA" |
tr '[:upper:]' '[:lower:]')
if ! [[ "$requested_sha" =~ ^[0-9a-f]{40}$ ]]; then
echo "source_sha must be a full commit SHA" >&2
exit 1
fi
source_sha=$(git -C source rev-parse "$requested_sha^{commit}")
if ! git -C source merge-base --is-ancestor "$source_sha" "$branch_sha"; then
echo "$source_sha is not part of ${{ steps.branch.outputs.branch }}" >&2
exit 1
fi
else
source_sha="$branch_sha"
fi
echo "sha=$source_sha" >> "$GITHUB_OUTPUT"
echo "Release source: ${{ steps.branch.outputs.branch }}@$source_sha"
- name: Validate version
id: version
env:
CHANNEL: ${{ inputs.channel }}
VERSION: ${{ inputs.version }}
run: |
python3 .release-workflow/scripts/release_workflow.py validate-version \
--channel "$CHANNEL" \
--version "$VERSION"
case "$CHANNEL" in
stable)
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
echo "base_image_version=${{ env.BASE_IMAGE_VERSION_STABLE }}" >> "$GITHUB_OUTPUT"
;;
beta)
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
echo "base_image_version=${{ env.BASE_IMAGE_VERSION_BETA }}" >> "$GITHUB_OUTPUT"
;;
rc)
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
echo "base_image_version=${{ env.BASE_IMAGE_VERSION_STABLE }}" >> "$GITHUB_OUTPUT"
;;
nightly)
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
echo "base_image_version=${{ env.BASE_IMAGE_VERSION_NIGHTLY }}" >> "$GITHUB_OUTPUT"
;;
esac
- name: Create immutable-settings token
id: immutable_token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.MUSIC_ASSISTANT_BOT_CLIENT_ID }}
private-key: ${{ secrets.MUSIC_ASSISTANT_BOT_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.repository }}
permission-administration: read
- name: Verify GitHub App identity
env:
APP_SLUG: ${{ steps.immutable_token.outputs.app-slug }}
INSTALLATION_ID: ${{ steps.immutable_token.outputs.installation-id }}
run: |
if [ "$APP_SLUG" != "$EXPECTED_APP_SLUG" ] || \
[ "$INSTALLATION_ID" != "$EXPECTED_APP_INSTALLATION_ID" ]; then
echo "Unexpected GitHub App installation: $APP_SLUG/$INSTALLATION_ID" >&2
exit 1
fi
- name: Require immutable releases
env:
GH_TOKEN: ${{ steps.immutable_token.outputs.token }}
run: |
enabled=$(gh api \
-H "X-GitHub-Api-Version: 2026-03-10" \
"repos/$GITHUB_REPOSITORY/immutable-releases" \
--jq '.enabled')
if [ "$enabled" != "true" ]; then
echo "Immutable releases must be enabled before a release can run" >&2
exit 1
fi
- name: Inspect existing tag and release
id: state
env:
GH_TOKEN: ${{ github.token }}
IS_PRERELEASE: ${{ steps.version.outputs.is_prerelease }}
SOURCE_SHA: ${{ steps.source.outputs.sha }}
VERSION: ${{ inputs.version }}
run: |
release_json="$RUNNER_TEMP/release.json"
release_lookup="$RUNNER_TEMP/release-lookup.txt"
gh api --paginate --slurp \
"repos/$GITHUB_REPOSITORY/releases?per_page=100" \
> "$RUNNER_TEMP/releases.json"
python3 .release-workflow/scripts/release_workflow.py select-release \
--version "$VERSION" \
--releases-json "$RUNNER_TEMP/releases.json" \
--release-json "$release_json" \
--github-output "$release_lookup"
release_exists=$(sed -n 's/^release_exists=//p' "$release_lookup")
release_id=$(sed -n 's/^release_id=//p' "$release_lookup")
tag_sha=""
tag_is_resumable=false
if git -C source show-ref --verify --quiet "refs/tags/$VERSION"; then
tag_sha=$(git -C source rev-parse "refs/tags/$VERSION^{commit}")
gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$VERSION" \
> "$RUNNER_TEMP/tag-ref.json"
if [ "$(jq -r '.object.type' "$RUNNER_TEMP/tag-ref.json")" = "tag" ]; then
tag_object_sha=$(jq -r '.object.sha' "$RUNNER_TEMP/tag-ref.json")
gh api "repos/$GITHUB_REPOSITORY/git/tags/$tag_object_sha" \
> "$RUNNER_TEMP/tag-object.json"
tag_message="Music Assistant release $VERSION from $SOURCE_SHA"
if jq -e \
--arg version "$VERSION" \
--arg source "$SOURCE_SHA" \
--arg message "$tag_message" \
'.tag == $version and
.message == $message and
.object.type == "commit" and
.object.sha == $source and
.tagger.name == "github-actions[bot]"' \
"$RUNNER_TEMP/tag-object.json" > /dev/null; then
tag_is_resumable=true
fi
fi
fi
current_outputs="$RUNNER_TEMP/current-version.txt"
python3 .release-workflow/scripts/release_workflow.py current-version \
--channel "${{ inputs.channel }}" \
--version "$VERSION" \
--repository source \
--github-output "$current_outputs"
cat "$current_outputs" >> "$GITHUB_OUTPUT"
is_current=$(sed -n 's/^is_current=//p' "$current_outputs")
if [ "$release_exists" = "false" ]; then
if [ -n "$tag_sha" ] && [ "$tag_is_resumable" != "true" ]; then
echo "Tag $VERSION already exists without a resumable workflow marker" >&2
exit 1
fi
if [ "$is_current" != "true" ]; then
echo "Version $VERSION is older than an existing channel tag" >&2
exit 1
fi
{
echo "release_state=new"
echo "release_id="
echo "assets_ready=false"
} >> "$GITHUB_OUTPUT"
if [ "$tag_is_resumable" = "true" ]; then
echo "Resuming the matching release tag $VERSION"
fi
exit 0
fi
draft=$(jq -r '.draft' "$release_json")
immutable=$(jq -r '.immutable' "$release_json")
target=$(jq -r '.target_commitish' "$release_json")
prerelease=$(jq -r '.prerelease' "$release_json")
echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
if [ "$draft" = "true" ]; then
if [ "$immutable" != "false" ] || [ "$target" != "$SOURCE_SHA" ]; then
echo "Existing draft does not match source commit $SOURCE_SHA" >&2
exit 1
fi
if [ "$tag_is_resumable" != "true" ] || [ "$tag_sha" != "$SOURCE_SHA" ]; then
echo "Existing draft does not have its matching workflow-created tag" >&2
exit 1
fi
if [ "$is_current" != "true" ]; then
echo "Draft $VERSION was superseded by a newer channel tag" >&2
exit 1
fi
echo "release_state=draft" >> "$GITHUB_OUTPUT"
asset_outputs="$RUNNER_TEMP/draft-assets.txt"
if python3 .release-workflow/scripts/release_workflow.py assets \
--version "$VERSION" \
--release-json "$release_json" \
--github-output "$asset_outputs"; then
cat "$asset_outputs" >> "$GITHUB_OUTPUT"
echo "assets_ready=true" >> "$GITHUB_OUTPUT"
echo "Reusing the verified assets from draft $VERSION"
else
echo "assets_ready=false" >> "$GITHUB_OUTPUT"
echo "Draft assets are incomplete or inconsistent and will be replaced"
fi
exit 0
fi
if [ "$immutable" != "true" ]; then
echo "Published release $VERSION is mutable and cannot be resumed" >&2
exit 1
fi
if [ -z "$tag_sha" ] || [ "$tag_sha" != "$SOURCE_SHA" ]; then
echo "Immutable release tag $VERSION does not match $SOURCE_SHA" >&2
exit 1
fi
if [ "$prerelease" != "$IS_PRERELEASE" ]; then
echo "Immutable release $VERSION has the wrong prerelease state" >&2
exit 1
fi
python3 .release-workflow/scripts/release_workflow.py assets \
--version "$VERSION" \
--release-json "$release_json" \
--github-output "$GITHUB_OUTPUT"
{
echo "release_state=published"
echo "assets_ready=true"
} >> "$GITHUB_OUTPUT"
echo "Immutable release $VERSION is already published; resuming downstream work"
if [ "$is_current" != "true" ]; then
echo "A newer channel release exists; rolling downstream state will not be changed"
fi
preflight:
name: Test exact release source
needs: resolve
if: needs.resolve.outputs.release_state != 'published'
permissions:
contents: read
pull-requests: read
uses: ./.github/workflows/test.yml
with:
ref: ${{ needs.resolve.outputs.source_sha }}
build_artifacts:
name: Build or recover release assets
runs-on: ubuntu-latest
needs: [resolve, preflight]
if: needs.resolve.outputs.release_state != 'published'
permissions:
# GitHub requires push access to download assets from draft releases.
contents: write
outputs:
reused_assets: ${{ steps.mode.outputs.reused_assets }}
wheel_name: ${{ steps.assets.outputs.wheel_name }}
wheel_size: ${{ steps.assets.outputs.wheel_size }}
wheel_sha256: ${{ steps.assets.outputs.wheel_sha256 }}
sdist_name: ${{ steps.assets.outputs.sdist_name }}
sdist_size: ${{ steps.assets.outputs.sdist_size }}
sdist_sha256: ${{ steps.assets.outputs.sdist_sha256 }}
steps:
- name: Check out release workflow
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.workflow_sha }}
path: .release-workflow
persist-credentials: false
- name: Check out release source
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ needs.resolve.outputs.source_sha }}
path: source
persist-credentials: false
- name: Select asset source
id: mode
env:
ASSETS_READY: ${{ needs.resolve.outputs.assets_ready }}
run: |
echo "reused_assets=$ASSETS_READY" >> "$GITHUB_OUTPUT"
mkdir -p source/dist
- name: Recover matching draft assets
if: needs.resolve.outputs.assets_ready == 'true'
env:
GH_TOKEN: ${{ github.token }}
RELEASE_ID: ${{ needs.resolve.outputs.release_id }}
SDIST_NAME: ${{ needs.resolve.outputs.sdist_name }}
SOURCE_SHA: ${{ needs.resolve.outputs.source_sha }}
VERSION: ${{ inputs.version }}
WHEEL_NAME: ${{ needs.resolve.outputs.wheel_name }}
run: |
if [ -z "$RELEASE_ID" ]; then
echo "Missing release id for reusable draft assets" >&2
exit 1
fi
gh api "repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID" \
> "$RUNNER_TEMP/release.json"
if [ "$(jq -r '.id // empty' "$RUNNER_TEMP/release.json")" != "$RELEASE_ID" ] || \
[ "$(jq -r '.tag_name // empty' "$RUNNER_TEMP/release.json")" != "$VERSION" ] || \
[ "$(jq -r '.draft' "$RUNNER_TEMP/release.json")" != "true" ] || \
[ "$(jq -r '.immutable' "$RUNNER_TEMP/release.json")" != "false" ] || \
[ "$(jq -r '.target_commitish' "$RUNNER_TEMP/release.json")" != "$SOURCE_SHA" ]; then
echo "Resolved release $RELEASE_ID is no longer the matching mutable draft" >&2
exit 1
fi
for asset_name in "$WHEEL_NAME" "$SDIST_NAME"; do
asset_count=$(jq \
--arg name "$asset_name" \
'[.assets[] | select(.name == $name)] | length' \
"$RUNNER_TEMP/release.json")
if [ "$asset_count" -ne 1 ]; then
echo "Draft must contain exactly one $asset_name asset" >&2
exit 1
fi
asset_id=$(jq -r \
--arg name "$asset_name" \
'.assets[] | select(.name == $name) | .id' \
"$RUNNER_TEMP/release.json")
gh api \
-H "Accept: application/octet-stream" \
"repos/$GITHUB_REPOSITORY/releases/assets/$asset_id" \
> "source/dist/$asset_name"
done
- name: Create appvars token
if: needs.resolve.outputs.assets_ready != 'true'
id: appvars_token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.MUSIC_ASSISTANT_BOT_CLIENT_ID }}
private-key: ${{ secrets.MUSIC_ASSISTANT_BOT_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: appvars
permission-contents: read
- name: Verify GitHub App identity
if: needs.resolve.outputs.assets_ready != 'true'
env:
APP_SLUG: ${{ steps.appvars_token.outputs.app-slug }}
INSTALLATION_ID: ${{ steps.appvars_token.outputs.installation-id }}
run: |
if [ "$APP_SLUG" != "$EXPECTED_APP_SLUG" ] || \
[ "$INSTALLATION_ID" != "$EXPECTED_APP_INSTALLATION_ID" ]; then
echo "Unexpected GitHub App installation: $APP_SLUG/$INSTALLATION_ID" >&2
exit 1
fi
- name: Set up Python
if: needs.resolve.outputs.assets_ready != 'true'
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version-file: "source/.python-version"
check-latest: true
- name: Install build dependencies
if: needs.resolve.outputs.assets_ready != 'true'
run: python3 -m pip install build tomli tomli-w
- name: Provision app secrets
if: needs.resolve.outputs.assets_ready != 'true'
env:
GH_TOKEN: ${{ steps.appvars_token.outputs.token }}
run: |
gh api \
-H "Accept: application/vnd.github.raw" \
"repos/music-assistant/appvars/contents/app_secrets.json" \
> source/music_assistant/helpers/app_secrets.json
- name: Set package version
if: needs.resolve.outputs.assets_ready != 'true'
working-directory: source
shell: python
env:
VERSION: ${{ inputs.version }}
run: |
import os
import tomli
import tomli_w
with open("pyproject.toml", "rb") as file_handle:
pyproject = tomli.load(file_handle)
pyproject["project"]["version"] = os.environ["VERSION"]
with open("pyproject.toml", "wb") as file_handle:
tomli_w.dump(pyproject, file_handle)
- name: Build wheel and source distribution
if: needs.resolve.outputs.assets_ready != 'true'
working-directory: source
run: python3 -m build
- name: Verify exact assets
id: assets
env:
REUSED_ASSETS: ${{ steps.mode.outputs.reused_assets }}
VERSION: ${{ inputs.version }}
run: |
extra_args=()
if [ "$REUSED_ASSETS" = "true" ]; then
extra_args=(--release-json "$RUNNER_TEMP/release.json")
fi
python3 .release-workflow/scripts/release_workflow.py assets \
--version "$VERSION" \
--directory source/dist \
"${extra_args[@]}" \
--github-output "$GITHUB_OUTPUT"
- name: Preserve release assets
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: release-dists-${{ github.run_id }}
path: source/dist/
if-no-files-found: error
compression-level: 0
retention-days: 1
overwrite: true
prepare_draft:
name: Prepare and verify draft release
runs-on: ubuntu-latest
needs: [resolve, build_artifacts]
if: needs.resolve.outputs.release_state != 'published'
permissions:
contents: write
pull-requests: read
outputs:
release_id: ${{ steps.draft.outputs.release_id }}
wheel_name: ${{ steps.assets.outputs.wheel_name }}
wheel_size: ${{ steps.assets.outputs.wheel_size }}
wheel_sha256: ${{ steps.assets.outputs.wheel_sha256 }}
sdist_name: ${{ steps.assets.outputs.sdist_name }}
sdist_size: ${{ steps.assets.outputs.sdist_size }}
sdist_sha256: ${{ steps.assets.outputs.sdist_sha256 }}
steps:
- name: Check out release workflow
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.workflow_sha }}
path: .release-workflow
persist-credentials: false
- name: Check out release source
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ needs.resolve.outputs.source_sha }}
fetch-depth: 0
path: source
persist-credentials: false
- name: Restore release assets
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: release-dists-${{ github.run_id }}
path: source/dist/
- name: Determine previous release tag
id: previous
working-directory: source
run: >-
python3 ../.release-workflow/scripts/release_workflow.py previous-tag
--channel "${{ inputs.channel }}"
--version "${{ inputs.version }}"
--github-output "$GITHUB_OUTPUT"
- name: Generate release notes
id: notes
uses: ./.release-workflow/.github/actions/generate-release-notes
with:
version: ${{ inputs.version }}
previous-tag: ${{ steps.previous.outputs.previous_tag }}
head-sha: ${{ needs.resolve.outputs.source_sha }}
repository-path: source
channel: ${{ inputs.channel }}
github-token: ${{ github.token }}
important-notes: ${{ inputs.important_notes }}
- name: Format release title
id: title
env:
CHANNEL: ${{ inputs.channel }}
VERSION: ${{ inputs.version }}
run: |
case "$CHANNEL" in
nightly)
if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)\.dev([0-9]+)$ ]]; then
title="${BASH_REMATCH[1]} NIGHTLY ${BASH_REMATCH[2]}"
else
title="$VERSION NIGHTLY"
fi
;;
beta)
if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)b([0-9]+)$ ]]; then
title="${BASH_REMATCH[1]} BETA ${BASH_REMATCH[2]}"
else
title="$VERSION BETA"
fi
;;
rc)
if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)rc([0-9]+)$ ]]; then
title="${BASH_REMATCH[1]} RC ${BASH_REMATCH[2]}"
else
title="$VERSION RC"
fi
;;
stable)
title="$VERSION"
;;
esac
echo "title=$title" >> "$GITHUB_OUTPUT"
- name: Create or update matching draft
id: draft
env:
GH_TOKEN: ${{ github.token }}
IS_PRERELEASE: ${{ needs.resolve.outputs.is_prerelease }}
RELEASE_ID: ${{ needs.resolve.outputs.release_id }}
RELEASE_NOTES_FILE: ${{ steps.notes.outputs.release-notes-file }}
RELEASE_TITLE: ${{ steps.title.outputs.title }}
SOURCE_SHA: ${{ needs.resolve.outputs.source_sha }}
VERSION: ${{ inputs.version }}
run: |
release_json="$RUNNER_TEMP/release.json"
if [ -n "$RELEASE_ID" ]; then
gh api "repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID" \
> "$release_json"
if [ "$(jq -r '.id // empty' "$release_json")" != "$RELEASE_ID" ] || \
[ "$(jq -r '.tag_name // empty' "$release_json")" != "$VERSION" ] || \
[ "$(jq -r '.draft' "$release_json")" != "true" ] || \
[ "$(jq -r '.immutable' "$release_json")" != "false" ] || \
[ "$(jq -r '.target_commitish' "$release_json")" != "$SOURCE_SHA" ]; then
echo "Resolved release $RELEASE_ID is no longer the matching mutable draft" >&2
exit 1
fi
release_exists=true
else
release_exists=false
fi
jq -n \
--arg tag "$VERSION" \
--arg target "$SOURCE_SHA" \
--arg name "$RELEASE_TITLE" \
--rawfile body "$RELEASE_NOTES_FILE" \
--argjson prerelease "$IS_PRERELEASE" \
'{
tag_name: $tag,
target_commitish: $target,
name: $name,
body: $body,
draft: true,
prerelease: $prerelease
}' > "$RUNNER_TEMP/release-payload.json"
tag_ref="$RUNNER_TEMP/tag-ref.json"
tag_error="$RUNNER_TEMP/tag-error.txt"
if gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$VERSION" \
> "$tag_ref" 2> "$tag_error"; then
tag_exists=true
elif grep -q "HTTP 404" "$tag_error"; then
tag_exists=false
else
cat "$tag_error" >&2
exit 1
fi
tag_message="Music Assistant release $VERSION from $SOURCE_SHA"
if [ "$tag_exists" = "true" ]; then
if [ "$(jq -r '.object.type' "$tag_ref")" != "tag" ]; then
echo "Existing tag $VERSION was not created by this workflow" >&2
exit 1
fi
tag_object_sha=$(jq -r '.object.sha' "$tag_ref")
gh api "repos/$GITHUB_REPOSITORY/git/tags/$tag_object_sha" \
> "$RUNNER_TEMP/tag-object.json"
jq -e \
--arg version "$VERSION" \
--arg source "$SOURCE_SHA" \
--arg message "$tag_message" \
'.tag == $version and
.message == $message and
.object.type == "commit" and
.object.sha == $source and
.tagger.name == "github-actions[bot]"' \
"$RUNNER_TEMP/tag-object.json" > /dev/null
elif [ "$release_exists" = "true" ]; then
echo "Existing draft $VERSION has no matching release tag" >&2
exit 1
else
tag_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
jq -n \
--arg tag "$VERSION" \
--arg message "$tag_message" \
--arg object "$SOURCE_SHA" \
--arg date "$tag_date" \
'{
tag: $tag,
message: $message,
object: $object,
type: "commit",
tagger: {
name: "github-actions[bot]",
email: "41898282+github-actions[bot]@users.noreply.github.com",
date: $date
}
}' > "$RUNNER_TEMP/tag-payload.json"
gh api --method POST \
"repos/$GITHUB_REPOSITORY/git/tags" \
--input "$RUNNER_TEMP/tag-payload.json" \
> "$RUNNER_TEMP/tag-object.json"
tag_object_sha=$(jq -r '.sha' "$RUNNER_TEMP/tag-object.json")
jq -n \
--arg ref "refs/tags/$VERSION" \
--arg sha "$tag_object_sha" \
'{ref: $ref, sha: $sha}' > "$RUNNER_TEMP/tag-ref-payload.json"
gh api --method POST \
"repos/$GITHUB_REPOSITORY/git/refs" \
--input "$RUNNER_TEMP/tag-ref-payload.json" \
> "$tag_ref"
fi
git -C source fetch origin \
"refs/tags/$VERSION:refs/tags/$VERSION" \
--quiet
tag_sha=$(git -C source rev-parse "refs/tags/$VERSION^{commit}")
if [ "$tag_sha" != "$SOURCE_SHA" ]; then
echo "Release tag $VERSION does not point to $SOURCE_SHA" >&2
exit 1
fi
if [ "$release_exists" = "true" ]; then
gh api --method PATCH \
"repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID" \
--input "$RUNNER_TEMP/release-payload.json" \
> "$release_json"
else
gh api --method POST \
"repos/$GITHUB_REPOSITORY/releases" \
--input "$RUNNER_TEMP/release-payload.json" \
> "$release_json"
fi
release_id=$(jq -r '.id // empty' "$release_json")
if [ -z "$release_id" ] || \
{ [ -n "$RELEASE_ID" ] && [ "$release_id" != "$RELEASE_ID" ]; } || \
[ "$(jq -r '.tag_name // empty' "$release_json")" != "$VERSION" ] || \
[ "$(jq -r '.draft' "$release_json")" != "true" ] || \
[ "$(jq -r '.immutable' "$release_json")" != "false" ] || \
[ "$(jq -r '.target_commitish' "$release_json")" != "$SOURCE_SHA" ]; then
echo "GitHub did not return the matching mutable draft for $VERSION" >&2
exit 1
fi
echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
- name: Replace draft assets
if: needs.build_artifacts.outputs.reused_assets != 'true'
env:
GH_TOKEN: ${{ github.token }}
RELEASE_ID: ${{ steps.draft.outputs.release_id }}
SDIST_NAME: ${{ needs.build_artifacts.outputs.sdist_name }}
VERSION: ${{ inputs.version }}
WHEEL_NAME: ${{ needs.build_artifacts.outputs.wheel_name }}
run: |
gh api "repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID" \
--jq '.assets[].id' |
while read -r asset_id; do
gh api --method DELETE \
"repos/$GITHUB_REPOSITORY/releases/assets/$asset_id"
done
for asset_path in \
"source/dist/$WHEEL_NAME" \
"source/dist/$SDIST_NAME"; do
asset_name=$(basename "$asset_path")
curl --fail-with-body --silent --show-error \
--request POST \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer $GH_TOKEN" \
--header "Content-Type: application/octet-stream" \
--header "X-GitHub-Api-Version: 2026-03-10" \
--data-binary "@$asset_path" \
"https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID/assets?name=$asset_name" \
> "$RUNNER_TEMP/upload-$asset_name.json"
done
- name: Verify draft assets
id: assets
env:
GH_TOKEN: ${{ github.token }}
RELEASE_ID: ${{ steps.draft.outputs.release_id }}
SOURCE_SHA: ${{ needs.resolve.outputs.source_sha }}
VERSION: ${{ inputs.version }}
run: |
gh api "repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID" \
> "$RUNNER_TEMP/release.json"
if [ "$(jq -r '.draft' "$RUNNER_TEMP/release.json")" != "true" ] || \
[ "$(jq -r '.target_commitish' "$RUNNER_TEMP/release.json")" != "$SOURCE_SHA" ]; then
echo "Draft release changed while its assets were prepared" >&2
exit 1
fi
python3 .release-workflow/scripts/release_workflow.py assets \
--version "$VERSION" \
--directory source/dist \
--release-json "$RUNNER_TEMP/release.json" \
--github-output "$GITHUB_OUTPUT"
exact_image:
name: Build or verify exact container image
runs-on: ubuntu-latest
needs: [resolve, prepare_draft]
if: >-
${{
always() &&
!cancelled() &&
needs.resolve.result == 'success' &&
(
needs.prepare_draft.result == 'success' ||
(
needs.resolve.outputs.release_state == 'published' &&
needs.prepare_draft.result == 'skipped'
)
)
}}
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.verify.outputs.digest }}
steps:
- name: Check out release workflow
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.workflow_sha }}
path: .release-workflow
persist-credentials: false
- name: Check out release source
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ needs.resolve.outputs.source_sha }}
path: source
persist-credentials: false
- name: Restore release assets
if: needs.resolve.outputs.release_state != 'published'
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: release-dists-${{ github.run_id }}
path: source/dist/
- name: Log in to GitHub Container Registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@594f3bf4285d9ea8dc53c9a0c9c4092420091003 # v4.4.0
- name: Inspect exact image
id: existing
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/server:${{ inputs.version }}
SOURCE_SHA: ${{ needs.resolve.outputs.source_sha }}
WHEEL_SHA256: ${{ needs.resolve.outputs.release_state == 'published' && needs.resolve.outputs.wheel_sha256 || needs.prepare_draft.outputs.wheel_sha256 }}
run: |
error_file="$RUNNER_TEMP/image-inspect-error.txt"
for attempt in 1 2 3; do
if docker buildx imagetools inspect "$IMAGE" \
--format '{{json .Manifest}}' \
> "$RUNNER_TEMP/exact-manifest.json" 2> "$error_file"; then
echo "exists=true" >> "$GITHUB_OUTPUT"
python3 .release-workflow/scripts/release_workflow.py verify-manifest \
--manifest-json "$RUNNER_TEMP/exact-manifest.json" \
--source-sha "$SOURCE_SHA" \
--wheel-sha256 "$WHEEL_SHA256"
exit 0
fi
if grep -Eqi 'not found|manifest unknown|status.*404' "$error_file"; then
echo "exists=false" >> "$GITHUB_OUTPUT"
if [ "${{ needs.resolve.outputs.release_state }}" = "published" ]; then
echo "Immutable release ${{ inputs.version }} has no exact image" >&2
exit 1
fi
exit 0
fi
if [ "$attempt" -lt 3 ]; then
sleep 5
fi
done
cat "$error_file" >&2
exit 1
- name: Build and push exact image
if: steps.existing.outputs.exists != 'true'
id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: source
platforms: linux/amd64,linux/arm64
file: source/Dockerfile
tags: ghcr.io/${{ github.repository_owner }}/server:${{ inputs.version }}
push: true
provenance: true
build-args: |
MASS_VERSION=${{ inputs.version }}
BASE_IMAGE_VERSION=${{ needs.resolve.outputs.base_image_version }}
labels: |
org.opencontainers.image.version=${{ inputs.version }}
org.opencontainers.image.revision=${{ needs.resolve.outputs.source_sha }}
io.music-assistant.wheel.sha256=${{ needs.prepare_draft.outputs.wheel_sha256 }}
annotations: |
index:org.opencontainers.image.version=${{ inputs.version }}
index:org.opencontainers.image.revision=${{ needs.resolve.outputs.source_sha }}
index:io.music-assistant.wheel.sha256=${{ needs.prepare_draft.outputs.wheel_sha256 }}
- name: Verify exact image
id: verify
env:
BUILT_DIGEST: ${{ steps.build.outputs.digest }}
IMAGE: ghcr.io/${{ github.repository_owner }}/server:${{ inputs.version }}
SOURCE_SHA: ${{ needs.resolve.outputs.source_sha }}
WHEEL_SHA256: ${{ needs.resolve.outputs.release_state == 'published' && needs.resolve.outputs.wheel_sha256 || needs.prepare_draft.outputs.wheel_sha256 }}
run: |
manifest_outputs=""
runtime_digests=""
for attempt in {1..12}; do
if docker buildx imagetools inspect "$IMAGE" \
--format '{{json .Manifest}}' \
> "$RUNNER_TEMP/exact-manifest.json"; then
if manifest_outputs=$(python3 \
.release-workflow/scripts/release_workflow.py verify-manifest \
--manifest-json "$RUNNER_TEMP/exact-manifest.json" \
--source-sha "$SOURCE_SHA" \
--wheel-sha256 "$WHEEL_SHA256"); then
printf '%s\n' "$manifest_outputs" >> "$GITHUB_OUTPUT"
runtime_digests=$(printf '%s\n' "$manifest_outputs" |
sed -n 's/^runtime_digests=//p')
break
fi
fi
if [ "$attempt" -eq 12 ]; then
echo "Exact image did not become verifiable" >&2
exit 1
fi
sleep 5
done
digest=$(jq -r '.digest' "$RUNNER_TEMP/exact-manifest.json")
if [ -n "$BUILT_DIGEST" ] && [ "$BUILT_DIGEST" != "$digest" ]; then
echo "Build output digest $BUILT_DIGEST does not match registry digest $digest" >&2
exit 1
fi
for runtime_digest in $runtime_digests; do
docker buildx imagetools inspect \
"ghcr.io/${{ github.repository_owner }}/server@$runtime_digest" \
--format '{{json .Image}}' > "$RUNNER_TEMP/image-config.json"
jq -e \
--arg source "$SOURCE_SHA" \
--arg wheel "$WHEEL_SHA256" \
'.config.Labels["org.opencontainers.image.revision"] == $source and
.config.Labels["io.music-assistant.wheel.sha256"] == $wheel' \
"$RUNNER_TEMP/image-config.json" > /dev/null
done
publish_release:
name: Publish and verify immutable release
runs-on: ubuntu-latest
needs: [resolve, prepare_draft, exact_image]
if: >-
${{
always() &&
!cancelled() &&
needs.resolve.result == 'success' &&
needs.exact_image.result == 'success' &&
(
needs.prepare_draft.result == 'success' ||
(
needs.resolve.outputs.release_state == 'published' &&
needs.prepare_draft.result == 'skipped'
)
)
}}
permissions:
contents: write
packages: read
outputs:
wheel_sha256: ${{ steps.verify_assets.outputs.wheel_sha256 }}
steps:
- name: Check out release workflow
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.workflow_sha }}
path: .release-workflow
persist-credentials: false