Repository navigation
1105 lines (1032 loc) · 46 KB
/
Copy pathsquad-standalone-release.yml
File metadata and controls
1105 lines (1032 loc) · 46 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: Squad Standalone Bundles
# Builds self-contained, npm-free Squad bundles for every supported platform and
# attaches them to a GitHub Release.
#
# Each bundle vendors its own Node.js runtime, so installing Squad from these
# artifacts touches github.com only — never registry.npmjs.org. This is what
# unblocks self-hosted runners and developer machines behind a firewall that
# blocks the npm registry (see #1593, and the deferred limitation in #1587).
#
# npm is still used at *build* time inside this workflow to resolve the
# dependency tree; it is the runtime dependency that is removed.
on:
workflow_call:
inputs:
node_version:
description: 'Node.js runtime version to vendor into the bundles'
required: false
default: '22.23.4'
type: string
upload:
description: 'Attach the built bundles to the requested release'
required: false
default: false
type: boolean
release_tag:
description: 'GitHub Release tag that receives the bundles'
required: false
default: ''
type: string
source_ref:
description: 'Git ref whose source is bundled'
required: false
default: ''
type: string
source_sha:
description: 'Full 40-hex commit SHA targeted by release_tag'
required: true
type: string
package_version:
description: 'Optional package version override for generated insider snapshots'
required: false
default: ''
type: string
publish_package_managers:
description: 'Publish the Homebrew cask and WinGet manifests (opt-in; each job runs a no-side-effect credential preflight first)'
required: false
default: false
type: boolean
secrets:
HOMEBREW_TAP_TOKEN:
description: 'Classic PAT with public_repo and write access to bradygaster/homebrew-squad'
required: false
WINGET_CREATE_GITHUB_TOKEN:
description: 'Classic public_repo PAT for tamirdresher/winget-pkgs and upstream PRs'
required: false
outputs:
checksum_binding:
description: 'VERIFIED when every uploaded standalone archive is bound to its validation record and SHA256SUMS'
value: ${{ jobs.publish.outputs.checksum_binding }}
workflow_dispatch:
inputs:
node_version:
description: 'Node.js runtime version to vendor into the bundles'
required: false
default: '22.23.4'
type: string
upload:
description: 'Attach the built bundles to the release matching the current tag'
required: false
default: false
type: boolean
release_tag:
description: 'GitHub Release tag that receives the bundles (defaults to the selected tag)'
required: false
default: ''
type: string
source_ref:
description: 'Git ref whose source is bundled (defaults to release_tag or the selected ref)'
required: false
default: ''
type: string
source_sha:
description: 'Full 40-hex commit SHA targeted by release_tag'
required: true
type: string
package_version:
description: 'Optional package version override for generated insider snapshots'
required: false
default: ''
type: string
publish_package_managers:
description: 'Publish the Homebrew cask and WinGet manifests (opt-in; each job runs a no-side-effect credential preflight first)'
required: false
default: false
type: boolean
concurrency:
group: squad-standalone-release-publication
cancel-in-progress: false
permissions:
contents: read
env:
NODE_VERSION: ${{ inputs.node_version || '22.23.4' }}
jobs:
guard:
name: Validate standalone release inputs and tag identity
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
tag: ${{ steps.validate.outputs.tag }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
ref: ${{ inputs.source_sha }}
fetch-depth: 0
- name: Validate inputs
id: validate
env:
SOURCE_SHA: ${{ inputs.source_sha }}
SOURCE_REF: ${{ inputs.source_ref }}
RELEASE_TAG: ${{ inputs.release_tag }}
NODE_VERSION_INPUT: ${{ inputs.node_version }}
PACKAGE_VERSION: ${{ inputs.package_version }}
UPLOAD: ${{ inputs.upload }}
DISPATCH_SHA: ${{ github.sha }}
WORKFLOW_SHA: ${{ github.workflow_sha }}
RUN_REF_TYPE: ${{ github.ref_type }}
RUN_REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
[[ "$SOURCE_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::source_sha must be a full lowercase 40-hex SHA"; exit 1; }
[[ "$NODE_VERSION_INPUT" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] || { echo "::error::node_version must be X.Y.Z"; exit 1; }
node scripts/release/node-security-floor.mjs --version "$NODE_VERSION_INPUT"
[ -z "$SOURCE_REF" ] || [ "$SOURCE_REF" = "$SOURCE_SHA" ] || { echo "::error::source_ref must be empty or equal source_sha"; exit 1; }
[ -z "$PACKAGE_VERSION" ] || [[ "$PACKAGE_VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-insider\.(0|[1-9][0-9]*)$ ]] || {
echo "::error::package_version must be empty or X.Y.Z-insider.N"; exit 1;
}
head_sha="$(git rev-parse HEAD)"
echo "Verified checkout HEAD: ${head_sha}"
test "$head_sha" = "$SOURCE_SHA" || { echo "::error::checkout differs from source_sha"; exit 1; }
test "$DISPATCH_SHA" = "$SOURCE_SHA" || { echo "::error::dispatch SHA differs from source_sha"; exit 1; }
test "$WORKFLOW_SHA" = "$SOURCE_SHA" || { echo "::error::workflow definition differs from source_sha"; exit 1; }
tag="$RELEASE_TAG"
if [ -z "$tag" ] && [ "$RUN_REF_TYPE" = tag ]; then tag="$RUN_REF_NAME"; fi
if [ "$UPLOAD" = true ]; then
[[ "$tag" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(preview|insider)\.(0|[1-9][0-9]*))?$ ]] || {
echo "::error::release_tag must be a stable, preview, or insider tag when upload=true"; exit 1;
}
node scripts/release/assert-publish-identity.mjs \
--source-sha "$SOURCE_SHA" \
--dispatch-sha "$DISPATCH_SHA" \
--workflow-sha "$WORKFLOW_SHA" \
--tag "$tag"
else
if [ -n "$tag" ]; then
[[ "$tag" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(preview|insider)\.(0|[1-9][0-9]*))?$ ]] || {
echo "::error::release_tag must be empty or a stable, preview, or insider tag"; exit 1;
}
fi
echo "Artifact-only validation: no tag or release publication will occur."
fi
if [ "${{ inputs.publish_package_managers }}" = true ] && [ "${{ inputs.upload }}" != true ]; then
echo "::error::publish_package_managers requires upload=true"; exit 1
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
credential-preflight:
name: Preflight package-manager credentials
needs: guard
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Verify auth and push access before standalone publication effects
if: inputs.publish_package_managers
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }}
run: |
set -euo pipefail
[ -n "$HOMEBREW_TAP_TOKEN" ] || { echo "::error::HOMEBREW_TAP_TOKEN is not configured"; exit 1; }
[ -n "$WINGET_CREATE_GITHUB_TOKEN" ] || { echo "::error::WINGET_CREATE_GITHUB_TOKEN is not configured"; exit 1; }
test "$(GH_TOKEN="$HOMEBREW_TAP_TOKEN" gh api repos/bradygaster/homebrew-squad --jq '.permissions.push // false')" = true || {
echo "::error::HOMEBREW_TAP_TOKEN lacks push access"; exit 1;
}
test "$(GH_TOKEN="$WINGET_CREATE_GITHUB_TOKEN" gh api repos/tamirdresher/winget-pkgs --jq '.permissions.push // false')" = true || {
echo "::error::WINGET_CREATE_GITHUB_TOKEN lacks push access"; exit 1;
}
GH_TOKEN="$WINGET_CREATE_GITHUB_TOKEN" gh api repos/microsoft/winget-pkgs --silent
build:
name: ${{ matrix.target }}
needs: [guard, credential-preflight]
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
- target: linux-x64
platform: linux
arch: x64
runner: ubuntu-latest
- target: linux-arm64
platform: linux
arch: arm64
runner: ubuntu-24.04-arm
- target: darwin-x64
platform: darwin
arch: x64
runner: macos-15-intel
- target: darwin-arm64
platform: darwin
arch: arm64
runner: macos-15
- target: win32-x64
platform: win32
arch: x64
runner: windows-latest
- target: win32-arm64
platform: win32
arch: arm64
runner: windows-11-arm
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
ref: ${{ inputs.source_sha }}
fetch-depth: 0
- name: Verify exact source checkout
env:
SOURCE_SHA: ${{ inputs.source_sha }}
run: |
set -euo pipefail
head_sha="$(git rev-parse HEAD)"
echo "Verified checkout HEAD: ${head_sha}"
test "${head_sha}" = "${SOURCE_SHA}" || {
echo "::error::checkout HEAD ${head_sha} differs from source_sha ${SOURCE_SHA}"
exit 1
}
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 #v6
with:
node-version: '22.23.4'
- name: Ensure signed-checksum verifier is available
run: |
set -euo pipefail
verifier=gpgv
if command -v gpgv >/dev/null 2>&1; then
:
elif [ "${RUNNER_OS}" = Windows ] && [ -x "/c/Program Files/Git/usr/bin/gpgv.exe" ]; then
verifier="/c/Program Files/Git/usr/bin/gpgv.exe"
elif [ "${RUNNER_OS}" = macOS ]; then
brew install gnupg
else
echo "::error::gpgv is required to authenticate Node.js release checksums"
exit 1
fi
"${verifier}" --version | head -n 1
- name: Install workspace dependencies
run: npm ci --no-audit --no-fund
- name: Apply package version override
if: inputs.package_version != ''
env:
PACKAGE_VERSION: ${{ inputs.package_version }}
run: node scripts/release/override-standalone-package-versions.mjs
- name: Build packages
# Root prebuild synchronizes contributor-only .squad sources that are
# intentionally absent from release tags. Package builds consume the
# already-synchronized templates committed with the release.
run: npm -w packages/squad-sdk run build && npm -w packages/squad-cli run build
- name: Build standalone bundle
env:
TARGET_PLATFORM: ${{ matrix.platform }}
TARGET_ARCH: ${{ matrix.arch }}
run: |
node scripts/build-standalone.mjs \
--platform "${TARGET_PLATFORM}" \
--arch "${TARGET_ARCH}" \
--node-version "${NODE_VERSION}"
- name: Package bundle
id: package
working-directory: dist-standalone
env:
TARGET: ${{ matrix.target }}
TARGET_PLATFORM: ${{ matrix.platform }}
run: |
set -euo pipefail
if [ "${TARGET_PLATFORM}" = "win32" ]; then
asset="squad-${TARGET}.zip"
powershell.exe -NoProfile -NonInteractive -Command \
"Compress-Archive -Path 'squad-${TARGET}' -DestinationPath '${asset}' -Force"
else
asset="squad-${TARGET}.tar.gz"
tar -czf "${asset}" "squad-${TARGET}"
fi
sha256sum "${asset}" > "${asset}.sha256"
echo "asset=${asset}" >> "${GITHUB_OUTPUT}"
ls -lh "${asset}"
- name: Root-delete rejection adapter test
if: matrix.target == 'linux-x64' || matrix.target == 'win32-x64'
run: npx vitest run test/state-backend-root-guard.test.ts
- name: Execute bundle and bounded bridge lifecycle smoke
env:
TARGET: ${{ matrix.target }}
ASSET: ${{ steps.package.outputs.asset }}
SOURCE_SHA: ${{ inputs.source_sha }}
ROOT_DELETE_STATUS: "${{ (matrix.target == 'linux-x64' || matrix.target == 'win32-x64') && 'EXECUTED: state-backend-root-guard.test.ts passed' || 'UNEXECUTED on this target; covered on linux-x64 and win32-x64' }}"
run: |
set -euo pipefail
verified_head="$(git rev-parse HEAD)"
test "${verified_head}" = "${SOURCE_SHA}" || {
echo "::error::checkout HEAD ${verified_head} differs from source_sha ${SOURCE_SHA}"
exit 1
}
bundle="dist-standalone/squad-${TARGET}"
cli_version="$(node -p 'require("./packages/squad-cli/package.json").version')"
node scripts/release/validate-standalone-bundle.mjs \
--bundle "${bundle}" \
--archive "dist-standalone/${ASSET}" \
--expected-node "${NODE_VERSION}" \
--expected-cli "${cli_version}" \
--target "${TARGET}" \
--source-sha "${verified_head}" \
--root-delete "${ROOT_DELETE_STATUS}" \
--output "dist-standalone/squad-${TARGET}-validation.json"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 #v7
with:
name: squad-${{ matrix.target }}-${{ inputs.source_sha }}
path: |
dist-standalone/${{ steps.package.outputs.asset }}
dist-standalone/${{ steps.package.outputs.asset }}.sha256
dist-standalone/squad-${{ matrix.target }}-validation.json
retention-days: 7
if-no-files-found: error
publish:
name: Attach bundles to release
needs: build
if: inputs.upload
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
outputs:
checksum_binding: ${{ steps.verify-checksum-binding.outputs.binding }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
ref: ${{ inputs.source_sha }}
fetch-depth: 0
- name: Verify exact source checkout
env:
SOURCE_SHA: ${{ inputs.source_sha }}
run: |
set -euo pipefail
head_sha="$(git rev-parse HEAD)"
echo "Verified checkout HEAD: ${head_sha}"
test "${head_sha}" = "${SOURCE_SHA}" || {
echo "::error::checkout HEAD ${head_sha} differs from source_sha ${SOURCE_SHA}"
exit 1
}
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 #v8
with:
path: artifacts
pattern: squad-*-${{ inputs.source_sha }}
merge-multiple: true
- name: Prepare release assets and SHA256SUMS
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ inputs.release_tag || (github.ref_type == 'tag' && github.ref_name) }}
working-directory: artifacts
run: |
set -euo pipefail
assets=(
squad-linux-x64.tar.gz
squad-linux-arm64.tar.gz
squad-darwin-x64.tar.gz
squad-darwin-arm64.tar.gz
squad-win32-x64.zip
squad-win32-arm64.zip
)
existing_dir="${RUNNER_TEMP}/existing-release-assets"
mkdir -p "${existing_dir}"
gh release view "${TAG}" \
--repo "${GITHUB_REPOSITORY}" \
--json assets \
--jq '.assets[].name' \
> "${existing_dir}/asset-names.txt"
mapfile -t existing_assets < "${existing_dir}/asset-names.txt"
upload_paths=()
reused_count=0
for asset in "${assets[@]}"; do
if [ ! -f "${asset}" ]; then
echo "::error::Build artifacts are missing ${asset}."
exit 1
fi
if printf '%s\n' "${existing_assets[@]}" | grep -Fxq "${asset}"; then
gh release download "${TAG}" \
--repo "${GITHUB_REPOSITORY}" \
--pattern "${asset}" \
--dir "${existing_dir}" \
--clobber
mv -- "${existing_dir}/${asset}" "${asset}"
reused_count=$((reused_count + 1))
else
upload_paths+=("${asset}")
fi
sha256sum "${asset}" > "${asset}.sha256"
done
cat ./*.sha256 > SHA256SUMS.txt
rm -f ./*.sha256
: > upload-paths.txt
if [ "${#upload_paths[@]}" -gt 0 ]; then
printf '%s\n' "${upload_paths[@]}" > upload-paths.txt
fi
printf '%s\n' "${reused_count}" > reused-count.txt
checksum_changed=true
if printf '%s\n' "${existing_assets[@]}" | grep -Fxq SHA256SUMS.txt; then
gh release download "${TAG}" \
--repo "${GITHUB_REPOSITORY}" \
--pattern SHA256SUMS.txt \
--dir "${existing_dir}" \
--clobber
if cmp -s "${existing_dir}/SHA256SUMS.txt" SHA256SUMS.txt; then
checksum_changed=false
fi
fi
printf '%s\n' "${checksum_changed}" > checksum-changed.txt
- name: Verify archive, validation and SHA256SUMS binding
id: verify-checksum-binding
working-directory: artifacts
env:
SOURCE_SHA: ${{ inputs.source_sha }}
run: |
set -euo pipefail
cli_version="$(node -p 'require("../packages/squad-cli/package.json").version')"
node ../scripts/release/verify-standalone-checksums.mjs \
--artifacts . \
--checksums SHA256SUMS.txt \
--expected-source-sha "${SOURCE_SHA}" \
--expected-cli "${cli_version}" \
--expected-node "${NODE_VERSION}" \
--output standalone-checksum-binding.json
echo "binding=VERIFIED" >> "${GITHUB_OUTPUT}"
- name: Upload to release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ inputs.release_tag || (github.ref_type == 'tag' && github.ref_name) }}
working-directory: artifacts
run: |
set -euo pipefail
mapfile -t upload_paths < upload-paths.txt
reused_count="$(cat reused-count.txt)"
checksum_changed="$(cat checksum-changed.txt)"
if [ "${#upload_paths[@]}" -gt 0 ] && [ -n "${upload_paths[0]}" ]; then
node ../scripts/release/assert-publish-identity.mjs --repo .. --source-sha "${{ inputs.source_sha }}" --dispatch-sha "${{ github.sha }}" --workflow-sha "${{ github.workflow_sha }}" --tag "${TAG}"
gh release upload "${TAG}" "${upload_paths[@]}" --repo "${GITHUB_REPOSITORY}"
fi
if [ "${checksum_changed}" = "true" ]; then
node ../scripts/release/assert-publish-identity.mjs --repo .. --source-sha "${{ inputs.source_sha }}" --dispatch-sha "${{ github.sha }}" --workflow-sha "${{ github.workflow_sha }}" --tag "${TAG}"
gh release upload "${TAG}" SHA256SUMS.txt --clobber --repo "${GITHUB_REPOSITORY}"
fi
{
echo "### Standalone release assets"
echo ""
echo "Reused ${reused_count} immutable archive(s) and uploaded ${#upload_paths[@]} missing archive(s)."
} >> "${GITHUB_STEP_SUMMARY}"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 #v7
with:
name: standalone-release-checksums-${{ inputs.source_sha }}
path: |
artifacts/SHA256SUMS.txt
artifacts/standalone-checksum-binding.json
retention-days: 30
if-no-files-found: error
packaging:
name: Generate Homebrew and winget manifests
needs: publish
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
release_tag: ${{ steps.generate.outputs.release_tag }}
release_channel: ${{ steps.generate.outputs.release_channel }}
homebrew_cask: ${{ steps.generate.outputs.homebrew_cask }}
winget_identifier: ${{ steps.generate.outputs.winget_identifier }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
ref: ${{ inputs.source_sha }}
fetch-depth: 0
- name: Verify exact source checkout
env:
SOURCE_SHA: ${{ inputs.source_sha }}
run: |
set -euo pipefail
head_sha="$(git rev-parse HEAD)"
echo "Verified checkout HEAD: ${head_sha}"
test "${head_sha}" = "${SOURCE_SHA}" || {
echo "::error::checkout HEAD ${head_sha} differs from source_sha ${SOURCE_SHA}"
exit 1
}
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 #v6
with:
node-version: '22.23.4'
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 #v8
with:
name: standalone-release-checksums-${{ inputs.source_sha }}
path: release-metadata
- name: Generate manifests
id: generate
env:
TAG: ${{ inputs.release_tag || (github.ref_type == 'tag' && github.ref_name) }}
run: |
set -euo pipefail
if [[ "${TAG}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
channel=stable
homebrew_cask=squad
winget_identifier=bradygaster.Squad
elif [[ "${TAG}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-preview\.(0|[1-9][0-9]*)$ ]]; then
channel=preview
homebrew_cask=squad-preview
winget_identifier=bradygaster.Squad.Preview
elif [[ "${TAG}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-insider\.(0|[1-9][0-9]*)$ ]]; then
channel=insider
homebrew_cask=squad-insider
winget_identifier=bradygaster.Squad.Insider
else
echo "::error::Unsupported release tag '${TAG}'."
exit 1
fi
node scripts/generate-packaging.mjs \
--version "${TAG}" \
--checksums release-metadata/SHA256SUMS.txt \
--out-dir dist-packaging
echo "release_tag=${TAG}" >> "${GITHUB_OUTPUT}"
echo "release_channel=${channel}" >> "${GITHUB_OUTPUT}"
echo "homebrew_cask=${homebrew_cask}" >> "${GITHUB_OUTPUT}"
echo "winget_identifier=${winget_identifier}" >> "${GITHUB_OUTPUT}"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 #v7
with:
name: packaging-manifests-${{ inputs.source_sha }}
path: dist-packaging/
retention-days: 30
if-no-files-found: error
publish-homebrew:
name: Publish Homebrew cask
needs: packaging
if: inputs.publish_package_managers
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
ref: ${{ inputs.source_sha }}
fetch-depth: 0
path: release-source
- name: Verify exact source checkout
working-directory: release-source
env:
SOURCE_SHA: ${{ inputs.source_sha }}
run: |
set -euo pipefail
head_sha="$(git rev-parse HEAD)"
echo "Verified checkout HEAD: ${head_sha}"
test "${head_sha}" = "${SOURCE_SHA}" || {
echo "::error::checkout HEAD ${head_sha} differs from source_sha ${SOURCE_SHA}"
exit 1
}
- name: Require Homebrew tap credential
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
set -euo pipefail
if [ -z "${HOMEBREW_TAP_TOKEN}" ]; then
echo "::error::HOMEBREW_TAP_TOKEN is required. Configure a classic PAT with public_repo from a collaborator with write access to bradygaster/homebrew-squad."
{
echo "### Homebrew publication"
echo ""
echo "❌ Blocked: \`HOMEBREW_TAP_TOKEN\` is not configured."
} >> "${GITHUB_STEP_SUMMARY}"
exit 1
fi
- name: Preflight - verify Homebrew tap token
env:
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
set -euo pipefail
login="$(gh api user --jq '.login')" || {
echo "::error::HOMEBREW_TAP_TOKEN failed to authenticate against the GitHub API. The token is likely invalid, expired, or revoked and must be rotated by a maintainer with write access to bradygaster/homebrew-squad."
exit 1
}
echo "Authenticated as: ${login}"
push_access="$(gh api repos/bradygaster/homebrew-squad --jq '.permissions.push // false')"
echo "Push access to bradygaster/homebrew-squad: ${push_access}"
if [ "${push_access}" != "true" ]; then
echo "::error::HOMEBREW_TAP_TOKEN authenticates as '${login}', but that account/token does not have push access to bradygaster/homebrew-squad."
exit 1
fi
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 #v8
with:
name: packaging-manifests-${{ inputs.source_sha }}
path: packaging
- name: Clone Homebrew tap (anonymous read; bradygaster/homebrew-squad is public)
run: |
set -euo pipefail
git clone --depth 1 --branch main https://github.com/bradygaster/homebrew-squad.git homebrew-tap
- name: Configure Homebrew tap push credential (scoped locally; never passed to the read-only clone)
env:
TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
working-directory: homebrew-tap
run: |
set -euo pipefail
auth_header="Authorization: basic $(printf 'x-access-token:%s' "${TOKEN}" | base64 -w0)"
git config --local http.https://github.com/.extraheader "${auth_header}"
- name: Publish cask to the tap
env:
CASK: ${{ needs.packaging.outputs.homebrew_cask }}
CHANNEL: ${{ needs.packaging.outputs.release_channel }}
TAG: ${{ needs.packaging.outputs.release_tag }}
working-directory: homebrew-tap
run: |
set -euo pipefail
source_cask="../packaging/homebrew/${CASK}.rb"
target_cask="Casks/${CASK}.rb"
cask_url="https://github.com/bradygaster/homebrew-squad/blob/main/${target_cask}"
extract_cask_version() {
local file="$1"
local versions
mapfile -t versions < <(
sed -nE 's/^[[:space:]]*version "([^"]+)"[[:space:]]*$/\1/p' "${file}"
)
if [ "${#versions[@]}" -ne 1 ]; then
echo "::error::Expected exactly one version declaration in ${file}." >&2
return 1
fi
case "${CHANNEL}" in
stable) pattern='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$' ;;
preview) pattern='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-preview\.(0|[1-9][0-9]*)$' ;;
insider) pattern='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-insider\.(0|[1-9][0-9]*)$' ;;
*) echo "::error::Unknown Homebrew release channel '${CHANNEL}'." >&2; return 1 ;;
esac
if [[ ! "${versions[0]}" =~ ${pattern} ]]; then
echo "::error::Cask version '${versions[0]}' in ${file} is not valid for ${CHANNEL}." >&2
return 1
fi
printf '%s' "${versions[0]}"
}
version_is_newer() {
[ "$1" != "$2" ] &&
[ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | tail -n 1)" = "$1" ]
}
if [ ! -f "${source_cask}" ]; then
echo "::error::The packaging-manifests artifact is missing homebrew/${CASK}.rb."
exit 1
fi
candidate_version="$(extract_cask_version "${source_cask}")"
if [ "${candidate_version}" != "${TAG#v}" ]; then
echo "::error::Generated cask version ${candidate_version} does not match release tag ${TAG}."
exit 1
fi
if [ -f "${target_cask}" ]; then
current_version="$(extract_cask_version "${target_cask}")"
if version_is_newer "${current_version}" "${candidate_version}"; then
{
echo "### Homebrew publication"
echo ""
echo "⏭️ Refused to downgrade [\`${target_cask}\`](${cask_url}) from ${current_version} to ${candidate_version}."
} >> "${GITHUB_STEP_SUMMARY}"
exit 0
fi
fi
if [ -n "$(git status --porcelain=v1 --untracked-files=all)" ]; then
echo "::error::The Homebrew tap checkout was not clean before publication."
git status --short
exit 1
fi
if cmp -s "${source_cask}" "${target_cask}"; then
{
echo "### Homebrew publication"
echo ""
echo "⏭️ [\`${target_cask}\`](${cask_url}) already matches ${TAG}; no commit was needed."
} >> "${GITHUB_STEP_SUMMARY}"
exit 0
fi
mkdir -p Casks
cp -- "${source_cask}" "${target_cask}"
status_output="$(git status --porcelain=v1 --untracked-files=all)"
if [ "${status_output}" != " M ${target_cask}" ] && [ "${status_output}" != "?? ${target_cask}" ]; then
echo "::error::Refusing to publish because files other than ${target_cask} changed."
git status --short
exit 1
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -- "${target_cask}"
git commit -m "chore: update Squad cask for ${TAG}"
node ../release-source/scripts/release/assert-publish-identity.mjs --repo ../release-source --source-sha "${{ inputs.source_sha }}" --dispatch-sha "${{ github.sha }}" --workflow-sha "${{ github.workflow_sha }}" --tag "${TAG}"
git push origin HEAD:main
commit_sha="$(git rev-parse HEAD)"
{
echo "### Homebrew publication"
echo ""
echo "✅ Updated [\`${target_cask}\`](${cask_url}) in [\`${commit_sha:0:7}\`](https://github.com/bradygaster/homebrew-squad/commit/${commit_sha})."
} >> "${GITHUB_STEP_SUMMARY}"
- name: Summarize Homebrew failure
if: failure()
run: |
{
echo "### Homebrew publication failed"
echo ""
echo "❌ Inspect the failed step. Target: [bradygaster/homebrew-squad](https://github.com/bradygaster/homebrew-squad)."
} >> "${GITHUB_STEP_SUMMARY}"
publish-winget:
name: Publish WinGet manifests
needs: packaging
if: inputs.publish_package_managers
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
ref: ${{ inputs.source_sha }}
fetch-depth: 0
path: release-source
- name: Verify exact source checkout
working-directory: release-source
env:
SOURCE_SHA: ${{ inputs.source_sha }}
run: |
set -euo pipefail
head_sha="$(git rev-parse HEAD)"
echo "Verified checkout HEAD: ${head_sha}"
test "${head_sha}" = "${SOURCE_SHA}" || {
echo "::error::checkout HEAD ${head_sha} differs from source_sha ${SOURCE_SHA}"
exit 1
}
- name: Require WinGet publication credential
env:
WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }}
run: |
set -euo pipefail
if [ -z "${WINGET_CREATE_GITHUB_TOKEN}" ]; then
echo "::error::WINGET_CREATE_GITHUB_TOKEN is required. Configure a classic PAT with public_repo for tamirdresher/winget-pkgs pushes and microsoft/winget-pkgs pull requests."
{
echo "### WinGet publication"
echo ""
echo "❌ Blocked: \`WINGET_CREATE_GITHUB_TOKEN\` is not configured."
} >> "${GITHUB_STEP_SUMMARY}"
exit 1
fi
- name: Preflight - verify WinGet publish token
env:
GH_TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }}
run: |
set -euo pipefail
login="$(gh api user --jq '.login')" || {
echo "::error::WINGET_CREATE_GITHUB_TOKEN failed to authenticate against the GitHub API. The token is likely invalid, expired, or revoked and must be rotated by a maintainer with push access to tamirdresher/winget-pkgs."
exit 1
}
echo "Authenticated as: ${login}"
push_access="$(gh api repos/tamirdresher/winget-pkgs --jq '.permissions.push // false')"
echo "Push access to tamirdresher/winget-pkgs: ${push_access}"
if [ "${push_access}" != "true" ]; then
echo "::error::WINGET_CREATE_GITHUB_TOKEN authenticates as '${login}', but that account/token does not have push access to tamirdresher/winget-pkgs."
exit 1
fi
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 #v8
with:
name: packaging-manifests-${{ inputs.source_sha }}
path: packaging
- name: Resolve WinGet release metadata
id: release
env:
CHANNEL: ${{ needs.packaging.outputs.release_channel }}
PACKAGE_IDENTIFIER: ${{ needs.packaging.outputs.winget_identifier }}
TAG: ${{ needs.packaging.outputs.release_tag }}
run: |
set -euo pipefail
if [[ ! "${TAG}" =~ ^v((0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(preview|insider)\.(0|[1-9][0-9]*))?)$ ]]; then
echo "::error::WinGet publication requires a stable, preview, or insider release tag; got '${TAG}'."
exit 1
fi
version="${BASH_REMATCH[1]}"
branch="bradygaster-squad-${CHANNEL}-${version}"
package_root="manifests/b/${PACKAGE_IDENTIFIER//./\/}"
expected=(
"${PACKAGE_IDENTIFIER}.installer.yaml"
"${PACKAGE_IDENTIFIER}.locale.en-US.yaml"
"${PACKAGE_IDENTIFIER}.yaml"
)
mapfile -t generated < <(find packaging/winget -mindepth 1 -maxdepth 1 -type f -printf '%f\n' | sort)
if [ "${#generated[@]}" -ne 3 ] || [ "${generated[*]}" != "${expected[*]}" ]; then
echo "::error::The packaging-manifests artifact must contain exactly the three expected WinGet manifests."
printf 'Found: %s\n' "${generated[*]:-(none)}"
exit 1
fi
echo "version=${version}" >> "${GITHUB_OUTPUT}"
echo "branch=${branch}" >> "${GITHUB_OUTPUT}"
echo "package_identifier=${PACKAGE_IDENTIFIER}" >> "${GITHUB_OUTPUT}"
echo "package_root=${package_root}" >> "${GITHUB_OUTPUT}"
- name: Clone WinGet manifests directory (read-only, public repo; no credential needed)
env:
PACKAGE_ROOT: ${{ steps.release.outputs.package_root }}
run: |
set -euo pipefail
git clone --no-checkout --depth 1 --branch master --filter=blob:none https://github.com/microsoft/winget-pkgs.git winget-base
git -C winget-base sparse-checkout set "${PACKAGE_ROOT}"
git -C winget-base checkout master
- name: Check WinGet publication state
id: guard
env:
BRANCH: ${{ steps.release.outputs.branch }}
GH_TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }}
PACKAGE_IDENTIFIER: ${{ steps.release.outputs.package_identifier }}
PACKAGE_ROOT: ${{ steps.release.outputs.package_root }}
VERSION: ${{ steps.release.outputs.version }}
run: |
set -euo pipefail
manifest_dir="${PACKAGE_ROOT}/${VERSION}"
version_url="https://github.com/microsoft/winget-pkgs/tree/master/${manifest_dir}"
if [ -d "winget-base/${manifest_dir}" ]; then
echo "skip=true" >> "${GITHUB_OUTPUT}"
{
echo "### WinGet publication"
echo ""
echo "⏭️ Version ${VERSION} is already present in [microsoft/winget-pkgs](${version_url})."
} >> "${GITHUB_STEP_SUMMARY}"
exit 0
fi
pr_url="$(gh api \
--method GET \
repos/microsoft/winget-pkgs/pulls \
-f state=open \
-f "head=tamirdresher:${BRANCH}" \
--jq '.[0].html_url // ""')"
if [ -n "${pr_url}" ]; then
echo "skip=true" >> "${GITHUB_OUTPUT}"
{
echo "### WinGet publication"
echo ""
echo "⏭️ [An open WinGet PR already exists](${pr_url}) for \`${BRANCH}\`."
} >> "${GITHUB_STEP_SUMMARY}"
exit 0
fi
set +e
git ls-remote --exit-code --heads \
https://github.com/tamirdresher/winget-pkgs.git \
"refs/heads/${BRANCH}" >/dev/null
branch_status=$?
set -e
case "${branch_status}" in
0) branch_exists=true ;;
2) branch_exists=false ;;
*)
echo "::error::Could not determine whether tamirdresher/winget-pkgs branch ${BRANCH} exists."
exit "${branch_status}"
;;
esac
if [ "${branch_exists}" = "true" ]; then
manifest_paths=(
"${manifest_dir}/${PACKAGE_IDENTIFIER}.installer.yaml"
"${manifest_dir}/${PACKAGE_IDENTIFIER}.locale.en-US.yaml"
"${manifest_dir}/${PACKAGE_IDENTIFIER}.yaml"
)
changed_files="$(gh api \
"repos/microsoft/winget-pkgs/compare/master...tamirdresher:${BRANCH}" \
--paginate \
--jq '.files[].filename')"
while IFS= read -r changed_file; do
[ -z "${changed_file}" ] && continue
allowed=false
for manifest_path in "${manifest_paths[@]}"; do
if [ "${changed_file}" = "${manifest_path}" ]; then
allowed=true
break
fi
done
if [ "${allowed}" != "true" ]; then
echo "::error::Refusing to reuse ${BRANCH}; it changes unrelated path ${changed_file}."
exit 1
fi
done <<< "${changed_files}"
fi
echo "skip=false" >> "${GITHUB_OUTPUT}"
echo "branch_exists=${branch_exists}" >> "${GITHUB_OUTPUT}"
- name: Check out existing WinGet version branch (anonymous read; tamirdresher/winget-pkgs is public)
if: steps.guard.outputs.skip == 'false' && steps.guard.outputs.branch_exists == 'true'
env:
BRANCH: ${{ steps.release.outputs.branch }}
PACKAGE_ROOT: ${{ steps.release.outputs.package_root }}
run: |
set -euo pipefail
git clone --no-checkout --depth 1 --branch "${BRANCH}" --filter=blob:none \
https://github.com/tamirdresher/winget-pkgs.git winget-pkgs
git -C winget-pkgs sparse-checkout set "${PACKAGE_ROOT}"
git -C winget-pkgs checkout "${BRANCH}"
- name: Configure existing-branch push credential (scoped locally; never passed to the read-only clone)
if: steps.guard.outputs.skip == 'false' && steps.guard.outputs.branch_exists == 'true'
env:
TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }}
working-directory: winget-pkgs
run: |
set -euo pipefail
auth_header="Authorization: basic $(printf 'x-access-token:%s' "${TOKEN}" | base64 -w0)"
git config --local http.https://github.com/.extraheader "${auth_header}"
- name: Clone WinGet master for a new version branch (credential scoped locally for the later push)
if: steps.guard.outputs.skip == 'false' && steps.guard.outputs.branch_exists == 'false'
env:
TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }}
PACKAGE_ROOT: ${{ steps.release.outputs.package_root }}
run: |
set -euo pipefail
git clone --no-checkout --depth 1 --branch master --filter=blob:none https://github.com/microsoft/winget-pkgs.git winget-pkgs
git -C winget-pkgs sparse-checkout set "${PACKAGE_ROOT}"
git -C winget-pkgs checkout master
auth_header="Authorization: basic $(printf 'x-access-token:%s' "${TOKEN}" | base64 -w0)"
git -C winget-pkgs config --local http.https://github.com/.extraheader "${auth_header}"
- name: Push manifests and open upstream PR
if: steps.guard.outputs.skip == 'false'
env:
BRANCH: ${{ steps.release.outputs.branch }}
BRANCH_EXISTS: ${{ steps.guard.outputs.branch_exists }}
GH_TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }}
PACKAGE_IDENTIFIER: ${{ steps.release.outputs.package_identifier }}
PACKAGE_ROOT: ${{ steps.release.outputs.package_root }}
TAG: ${{ needs.packaging.outputs.release_tag }}
VERSION: ${{ steps.release.outputs.version }}
working-directory: winget-pkgs
run: |
set -euo pipefail
if [ -n "$(git status --porcelain=v1 --untracked-files=all)" ]; then
echo "::error::The WinGet checkout was not clean before publication."
git status --short