Repository navigation
913 lines (811 loc) · 39 KB
/
Copy pathrelease.yml
File metadata and controls
913 lines (811 loc) · 39 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
# Publish to npm and JSR.
#
# This workflow exists in isolation from `ci.yml` for one reason:
# `id-token: write` is the credential the TanStack 2026-05-11 attackers
# extracted from runner memory after poisoning a CI cache. By keeping
# the token-minting workflow completely separate from anything triggered
# by fork PRs, a cache-poisoning chain cannot reach it.
#
# Hard rules for this file:
# * Triggered ONLY by a tag push (`v*`) or manual dispatch by a maintainer.
# * Runs in a protected GitHub Environment (`npm-publish`) that REQUIRES
# a maintainer approval before any step executes.
# * `id-token: write` is granted on the publish job only — never to
# `verify`, never to anything that runs untrusted code.
# * Builds and tests run BEFORE the publish job, in a job with no token.
# The token-less `pack` job runs install, build, SBOM generation and
# `npm pack`, then records each tarball's SHA-256. The publish jobs install
# and build nothing: they download the tarball, verify the hash against the
# pack job's output, and stage exactly those bytes.
# * Publish uses npm staged publishing + `--provenance` (npm trusted
# publishing via OIDC). CI can only stage a release; a separate npm
# MFA approval is required before the version becomes installable.
# `npm stage` requires npm CLI 11.15.0+, so the protected publish
# jobs pin that CLI before staging.
# Each npm package's Trusted Publisher must allow the `npm stage publish`
# action for repository `daloyjs/daloy`, workflow `release.yml`, and
# environment `npm-publish`; older Trusted Publisher configs default to
# `npm publish` only and fail with "OIDC permission denied for this action".
# No long-lived NPM_TOKEN is stored in repo secrets.
# * The same tag push also publishes the JSR package `@daloyjs/daloy`
# (raw `src/*.ts`, no build step) via JSR's GitHub Actions OIDC flow.
# There is likewise no long-lived JSR token in repo secrets; the job
# runs in the same protected `npm-publish` environment, and a JSR
# hiccup does NOT block the npm publishes or the GitHub Release.
# * No GitHub Actions cache is read or written. Cold installs only.
# * `actions/checkout` uses `persist-credentials: false`.
#
# To roll a release:
# 1. Bump version in package.json and (if applicable) packages/*/package.json.
# 2. `git tag v<version> -s` (signed) and `git push --tags`.
# 3. Approve the pending workflow in the `npm-publish` environment.
# 4. Approve the staged release in npm with MFA.
name: Publish
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
package:
description: "Package to publish"
required: true
type: choice
options:
- "@daloyjs/core"
- "create-daloy"
- "jsr"
- "all"
default: "@daloyjs/core"
permissions: {}
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: false
jobs:
verify:
name: Verify before publish
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
steps:
- name: Harden runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2
with:
egress-policy: audit
disable-sudo: true
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
show-progress: false
- name: Set up pnpm
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6
with:
run_install: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
- name: Install (no scripts)
run: pnpm install --frozen-lockfile --ignore-scripts
env:
npm_config_ignore_scripts: "true"
- name: Verify lockfile sources
run: pnpm verify:lockfile
- name: Verify zero runtime dependencies
run: pnpm verify:no-runtime-deps
- name: Verify no install-time lifecycle scripts (Aikido Package Health "Supply-Chain Scripts" gate)
run: pnpm verify:no-lifecycle-scripts
- name: Verify no committed npm-shrinkwrap.json (Socket npm-shrinkwrap gate)
run: pnpm verify:no-shrinkwrap
- name: Verify no bin script shadowing (Socket bin-script-confusion gate)
run: pnpm verify:no-bin-shadowing
- name: Verify secret-comparison single source of truth
run: pnpm verify:secret-comparisons
- name: Verify no unsafe Buffer APIs (Snyk "exploiting Buffer" gate)
run: pnpm verify:no-unsafe-buffer
- name: Verify no runtime remote-exec primitives (Aikido BlokTrooper gate)
run: pnpm verify:no-remote-exec
- name: Verify no runtime registry-exfiltration primitives (Socket GemStuffer gate)
run: pnpm verify:no-registry-exfiltration
- name: Verify no hijacked-CDN host references (Aikido / Sansec Funnull cluster gate)
run: pnpm verify:no-polyfill-cdns
- name: Verify no ToxicSkills patterns in shipped agent skills (Snyk Labs ToxicSkills gate)
run: pnpm verify:no-toxic-skills
- name: Verify no weak-randomness primitives in core (Aikido Python Top 10 #10 gate)
run: pnpm verify:no-weak-random
- name: Verify GitHub Actions are SHA-pinned (Socket tj-actions/changed-files CVE-2025-30066 gate)
run: pnpm verify:actions-pinned
- name: Verify no vulnerable JS sandbox dependencies (Socket vm2 CVE-2026-26956 gate)
run: pnpm verify:no-vulnerable-sandboxes
- name: Verify no native C/C++ add-on dependencies (Snyk NodeJS add-on extensions gate)
run: pnpm verify:no-native-addons
- name: Verify pattern-agnostic parity audits
run: pnpm verify:parity-audits
- name: Verify zero-runtime-deps + governance audits
run: pnpm verify:governance-audits
- name: Verify multi-runtime parity audits
run: pnpm verify:runtime-parity-audits
- name: Verify routing-hardening audits
run: pnpm verify:routing-hardening-audits
- name: Verify top-level dependency names against slopsquatting allowlist (Aikido AI package hallucination gate)
run: pnpm verify:known-dep-names
# A tag push does not run ci.yml, so every gate CI enforces is repeated
# here; these four used to run on pull requests only.
- name: Verify no ReDoS-prone regex patterns in core
run: pnpm verify:no-redos-patterns
- name: Verify dev-dependency license posture
run: pnpm verify:dep-licenses
- name: Verify no toxic agent skills in shipped SKILL.md / AGENTS.md
run: pnpm verify:no-toxic-agent-skills
- name: Typecheck
run: pnpm typecheck
- name: Verify apps on TypeScript 6 can consume the TypeScript 7 build
run: pnpm verify:ts-consumer-compat
- name: Build
run: pnpm build
- name: Generate CycloneDX 1.5 + SPDX 2.3 SBOMs (Aikido SBOM-standards gate)
run: pnpm gen:sbom
- name: Test
run: pnpm test
- name: Coverage
run: pnpm coverage
- name: Branch coverage gate (compiled JS)
run: pnpm coverage:branches
- name: Verify SBOMs match published manifests (Aikido SBOM-standards gate)
run: pnpm verify:sbom
- name: Verify no leaked credentials in publishable tarball contents (Snyk "leaked credentials in packages" gate)
run: pnpm verify:no-leaked-credentials
- name: Verify no leaky agent skills in shipped SKILL.md / AGENTS.md (Snyk OpenClaw "leaky skills" gate)
run: pnpm verify:no-leaky-agent-skills
- name: Verify no AI-agent / editor config auto-run wiring (Miasma worm config-injection gate)
run: pnpm verify:no-agent-config-autorun
- name: Verify no invisible Unicode carriers (Aikido GlassWorm gate)
run: pnpm verify:no-invisible-unicode
- name: Verify no encoded-payload literals (Socket Obfuscation 101 gate)
run: pnpm verify:no-encoded-payloads
# JSR packaging must be proven BEFORE any publish job runs. publish-jsr
# does its own dry-run, but it runs in parallel with the npm staging jobs,
# so a JSR-only packaging error (e.g. a "slow type" in the public API)
# left v1.0.0-rc.7 half-released: both npm packages staged and a GitHub
# Release created, with no JSR version. Gating it here in the token-less
# verify job means that class of failure blocks the whole release with no
# side effects to unwind. Dry-run needs no credentials.
- name: JSR packaging gate (slow types + publish dry-run)
run: pnpm verify:jsr-packaging
- name: Audit production dependencies
run: pnpm audit --prod
# ---------------------------------------------------------------------------
# Build and pack both npm packages WITHOUT any publish credential.
#
# Everything that executes dependency code (install, tsc, tsx SBOM generation,
# tests) runs here, with no `id-token`, so a malicious devDependency that
# slipped past the release-age cooldown cannot mint an OIDC token or publish.
# The tarballs and their SHA-256 hashes are handed to the publish jobs, which
# verify the hash and stage exactly those bytes.
# ---------------------------------------------------------------------------
pack:
name: Build and pack tarballs (no publish credentials)
needs: verify
if: |
github.event_name == 'push' ||
github.event.inputs.package == '@daloyjs/core' ||
github.event.inputs.package == 'create-daloy' ||
github.event.inputs.package == 'all'
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
outputs:
core_file: ${{ steps.pack.outputs.core_file }}
core_sha256: ${{ steps.pack.outputs.core_sha256 }}
create_file: ${{ steps.pack.outputs.create_file }}
create_sha256: ${{ steps.pack.outputs.create_sha256 }}
steps:
- name: Harden runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2
with:
egress-policy: audit
disable-sudo: true
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
show-progress: false
- name: Set up pnpm
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6
with:
run_install: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
- name: Install (no scripts)
run: pnpm install --frozen-lockfile --ignore-scripts
env:
npm_config_ignore_scripts: "true"
- name: Verify tag matches package versions
if: github.event_name == 'push'
run: |
set -eu
tag_version="${GITHUB_REF_NAME#v}"
for manifest in package.json packages/create-daloy/package.json; do
pkg_version="$(node -p "require('./$manifest').version")"
if [ "$tag_version" != "$pkg_version" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match $manifest version $pkg_version"
exit 1
fi
done
- name: Build
run: pnpm build
- name: Test create-daloy
run: pnpm --filter create-daloy test
- name: Generate CycloneDX 1.5 + SPDX 2.3 SBOMs for publishable tarballs
run: pnpm gen:sbom
- name: Verify SBOMs match published manifests before tarballs are sealed
run: pnpm verify:sbom
- name: Verify no leaked credentials in publishable tarball contents (Snyk "leaked credentials in packages" gate)
run: pnpm verify:no-leaked-credentials
- name: Verify no leaky agent skills in shipped SKILL.md / AGENTS.md (Snyk OpenClaw "leaky skills" gate)
run: pnpm verify:no-leaky-agent-skills
- name: Verify no AI-agent / editor config auto-run wiring (Miasma worm config-injection gate)
run: pnpm verify:no-agent-config-autorun
# `--ignore-scripts`: the build already ran above; `prepublishOnly` and
# any other lifecycle script must not run again at pack time. The JSON
# parse accepts npm 11 (an array) and npm 12 (an object keyed by name).
- name: Pack tarballs and record their SHA-256
id: pack
run: |
set -eu
mkdir -p tarballs
core_file="$(npm pack --ignore-scripts --pack-destination tarballs --json | node -e 'const j=JSON.parse(require("fs").readFileSync(0,"utf8"));process.stdout.write((Array.isArray(j)?j[0]:Object.values(j)[0]).filename)')"
create_file="$(cd packages/create-daloy && npm pack --ignore-scripts --pack-destination ../../tarballs --json | node -e 'const j=JSON.parse(require("fs").readFileSync(0,"utf8"));process.stdout.write((Array.isArray(j)?j[0]:Object.values(j)[0]).filename)')"
core_sha256="$(sha256sum "tarballs/$core_file" | cut -d' ' -f1)"
create_sha256="$(sha256sum "tarballs/$create_file" | cut -d' ' -f1)"
{
echo "core_file=$core_file"
echo "core_sha256=$core_sha256"
echo "create_file=$create_file"
echo "create_sha256=$create_sha256"
} >> "$GITHUB_OUTPUT"
(cd tarballs && sha256sum ./*.tgz)
# The `./` prefix matters: a bare `dir/file.tgz` is npm's GitHub
# shorthand (`owner/repo`), so npm would try to clone it.
- name: Packaging signal (npm publish dry-run of the exact tarballs)
env:
CORE_FILE: ${{ steps.pack.outputs.core_file }}
CREATE_FILE: ${{ steps.pack.outputs.create_file }}
run: |
set -eu
npm publish "./tarballs/$CORE_FILE" --dry-run --access public --tag latest --ignore-scripts
npm publish "./tarballs/$CREATE_FILE" --dry-run --access public --tag latest --ignore-scripts
- name: Upload tarballs for the publish jobs
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: npm-tarballs
path: tarballs/*.tgz
if-no-files-found: error
retention-days: 1
publish-core:
name: Publish @daloyjs/core
needs: [verify, pack]
if: |
github.event_name == 'push' ||
github.event.inputs.package == '@daloyjs/core' ||
github.event.inputs.package == 'all'
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: ${{ vars.NPM_PUBLISH_ENVIRONMENT || 'npm-publish' }}
url: https://www.npmjs.com/package/@daloyjs/core
permissions:
contents: read
# `id-token: write` is required by npm trusted publishing (OIDC). This
# job installs nothing and builds nothing: it verifies the tarball the
# token-less `pack` job produced and stages exactly those bytes.
id-token: write
steps:
- name: Harden runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2
with:
# Lock egress to the registry, Sigstore, and the artifact store the
# tarball is downloaded from. Anything else is dropped.
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
results-receiver.actions.githubusercontent.com:443
*.blob.core.windows.net:443
registry.npmjs.org:443
fulcio.sigstore.dev:443
rekor.sigstore.dev:443
tuf-repo-cdn.sigstore.dev:443
disable-sudo: true
- name: Checkout (SECURITY-CONTACTS.md only; no install, no build)
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
show-progress: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- name: Set up npm CLI with staged publishing
run: |
set -eu
npm install -g npm@11.15.0 --ignore-scripts --no-audit --no-fund
npm --version
npm stage --help >/dev/null
env:
npm_config_ignore_scripts: "true"
- name: Verify the commit is on the default branch
# A tag or dispatch ref can point at a commit that never went through
# review on the default branch. Refuse to publish from one.
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -eu
ref="refs/remotes/origin/${DEFAULT_BRANCH}"
git fetch --no-tags --unshallow origin "+refs/heads/${DEFAULT_BRANCH}:${ref}" \
|| git fetch --no-tags origin "+refs/heads/${DEFAULT_BRANCH}:${ref}"
if ! git merge-base --is-ancestor "$GITHUB_SHA" "$ref"; then
echo "::error::$GITHUB_SHA is not on ${DEFAULT_BRANCH}; refusing to publish."
exit 1
fi
- name: Verify actor is on SECURITY-CONTACTS rotation
# The rotation is read from the default branch (fetched above), never
# from the ref being published: otherwise a tag that adds its own
# author to the list would approve itself.
env:
ACTOR: ${{ github.actor }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -eu
git show "refs/remotes/origin/${DEFAULT_BRANCH}:SECURITY-CONTACTS.md" > "$RUNNER_TEMP/security-contacts.md"
CONTACTS="$RUNNER_TEMP/security-contacts.md" node -e '
const fs = require("node:fs");
const text = fs.readFileSync(process.env.CONTACTS, "utf8");
const m = text.match(/<!--\s*BEGIN ACTIVE\s*-->([\s\S]*?)<!--\s*END ACTIVE\s*-->/);
if (!m) { console.error("::error::SECURITY-CONTACTS.md is missing the ACTIVE block."); process.exit(1); }
const handles = [...m[1].matchAll(/^\s*-\s*handle:\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*$/gm)].map(x => x[1]);
const actor = process.env.ACTOR;
if (!handles.includes(actor)) {
console.error(`::error::Actor "${actor}" is not on the SECURITY-CONTACTS active rotation. Active: ${handles.join(", ")}.`);
process.exit(1);
}
console.log(`Actor "${actor}" is on the SECURITY-CONTACTS active rotation.`);
'
- name: Download the tarball built by the token-less pack job
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: npm-tarballs
path: tarballs
- name: Verify the tarball hash matches the pack job's record
env:
FILE: ${{ needs.pack.outputs.core_file }}
EXPECTED: ${{ needs.pack.outputs.core_sha256 }}
run: |
set -eu
case "$FILE" in
*/* | ..* | "") echo "::error::Unexpected tarball name: $FILE"; exit 1 ;;
esac
actual="$(sha256sum "tarballs/$FILE" | cut -d' ' -f1)"
if [ "$actual" != "$EXPECTED" ]; then
echo "::error::Tarball $FILE hash $actual does not match the pack job's $EXPECTED"
exit 1
fi
echo "Verified $FILE sha256=$actual"
# npm refuses to publish a prerelease version (e.g. 1.0.0-beta.0) without
# an explicit --tag; stable releases pass `--tag latest` as a no-op.
- name: Stage the verified tarball on npm with provenance
env:
FILE: ${{ needs.pack.outputs.core_file }}
NPM_CONFIG_PROVENANCE: "true"
run: npm stage publish "./tarballs/$FILE" --access public --provenance --tag latest --ignore-scripts
publish-create-daloy:
name: Publish create-daloy
needs: [verify, pack]
if: |
github.event_name == 'push' ||
github.event.inputs.package == 'create-daloy' ||
github.event.inputs.package == 'all'
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: ${{ vars.NPM_PUBLISH_ENVIRONMENT || 'npm-publish' }}
url: https://www.npmjs.com/package/create-daloy
permissions:
contents: read
# `id-token: write` is required by npm trusted publishing (OIDC). This
# job installs nothing and builds nothing: it verifies the tarball the
# token-less `pack` job produced and stages exactly those bytes.
id-token: write
steps:
- name: Harden runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2
with:
# Lock egress to the registry, Sigstore, and the artifact store the
# tarball is downloaded from. Anything else is dropped.
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
results-receiver.actions.githubusercontent.com:443
*.blob.core.windows.net:443
registry.npmjs.org:443
fulcio.sigstore.dev:443
rekor.sigstore.dev:443
tuf-repo-cdn.sigstore.dev:443
disable-sudo: true
- name: Checkout (SECURITY-CONTACTS.md only; no install, no build)
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
show-progress: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- name: Set up npm CLI with staged publishing
run: |
set -eu
npm install -g npm@11.15.0 --ignore-scripts --no-audit --no-fund
npm --version
npm stage --help >/dev/null
env:
npm_config_ignore_scripts: "true"
- name: Verify the commit is on the default branch
# A tag or dispatch ref can point at a commit that never went through
# review on the default branch. Refuse to publish from one.
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -eu
ref="refs/remotes/origin/${DEFAULT_BRANCH}"
git fetch --no-tags --unshallow origin "+refs/heads/${DEFAULT_BRANCH}:${ref}" \
|| git fetch --no-tags origin "+refs/heads/${DEFAULT_BRANCH}:${ref}"
if ! git merge-base --is-ancestor "$GITHUB_SHA" "$ref"; then
echo "::error::$GITHUB_SHA is not on ${DEFAULT_BRANCH}; refusing to publish."
exit 1
fi
- name: Verify actor is on SECURITY-CONTACTS rotation
# The rotation is read from the default branch (fetched above), never
# from the ref being published: otherwise a tag that adds its own
# author to the list would approve itself.
env:
ACTOR: ${{ github.actor }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -eu
git show "refs/remotes/origin/${DEFAULT_BRANCH}:SECURITY-CONTACTS.md" > "$RUNNER_TEMP/security-contacts.md"
CONTACTS="$RUNNER_TEMP/security-contacts.md" node -e '
const fs = require("node:fs");
const text = fs.readFileSync(process.env.CONTACTS, "utf8");
const m = text.match(/<!--\s*BEGIN ACTIVE\s*-->([\s\S]*?)<!--\s*END ACTIVE\s*-->/);
if (!m) { console.error("::error::SECURITY-CONTACTS.md is missing the ACTIVE block."); process.exit(1); }
const handles = [...m[1].matchAll(/^\s*-\s*handle:\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*$/gm)].map(x => x[1]);
const actor = process.env.ACTOR;
if (!handles.includes(actor)) {
console.error(`::error::Actor "${actor}" is not on the SECURITY-CONTACTS active rotation. Active: ${handles.join(", ")}.`);
process.exit(1);
}
console.log(`Actor "${actor}" is on the SECURITY-CONTACTS active rotation.`);
'
- name: Download the tarball built by the token-less pack job
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: npm-tarballs
path: tarballs
- name: Verify the tarball hash matches the pack job's record
env:
FILE: ${{ needs.pack.outputs.create_file }}
EXPECTED: ${{ needs.pack.outputs.create_sha256 }}
run: |
set -eu
case "$FILE" in
*/* | ..* | "") echo "::error::Unexpected tarball name: $FILE"; exit 1 ;;
esac
actual="$(sha256sum "tarballs/$FILE" | cut -d' ' -f1)"
if [ "$actual" != "$EXPECTED" ]; then
echo "::error::Tarball $FILE hash $actual does not match the pack job's $EXPECTED"
exit 1
fi
echo "Verified $FILE sha256=$actual"
# npm refuses to publish a prerelease version (e.g. 1.0.0-beta.0) without
# an explicit --tag; stable releases pass `--tag latest` as a no-op.
- name: Stage the verified tarball on npm with provenance
env:
FILE: ${{ needs.pack.outputs.create_file }}
NPM_CONFIG_PROVENANCE: "true"
run: npm stage publish "./tarballs/$FILE" --access public --provenance --tag latest --ignore-scripts
# ---------------------------------------------------------------------------
# Publish the JSR package `@daloyjs/daloy`.
#
# JSR ships the RAW `src/*.ts` source (see `jsr.json` exports) — there is no
# build or tarball, so this job has no SBOM/`dist` steps. It authenticates
# with JSR via GitHub Actions OIDC (`id-token: write`): JSR trades the
# short-lived OIDC token for a single-use publish credential, so there is no
# long-lived JSR token in repo secrets, mirroring the npm trusted-publishing
# jobs above.
#
# It runs on the same triggers as `@daloyjs/core` (the JSR package is the same
# source) plus a dedicated `jsr` dispatch option for backfilling JSR on its
# own. It is INDEPENDENT of `github-release` (not in its `needs:`), so a JSR
# outage never blocks the npm publishes or the GitHub Release.
# ---------------------------------------------------------------------------
publish-jsr:
name: Publish @daloyjs/daloy to JSR
needs: verify
if: |
github.event_name == 'push' ||
github.event.inputs.package == '@daloyjs/core' ||
github.event.inputs.package == 'jsr' ||
github.event.inputs.package == 'all'
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: ${{ vars.NPM_PUBLISH_ENVIRONMENT || 'npm-publish' }}
url: https://jsr.io/@daloyjs/daloy
permissions:
contents: read
# `id-token: write` is required by JSR's GitHub Actions publishing (OIDC).
# It is granted ONLY here, ONLY after the protected environment approval,
# and the job runs no third-party scripts.
id-token: write
steps:
- name: Harden runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2
with:
# Lock egress to exactly what a JSR OIDC publish needs:
# registry.npmjs.org — frozen dependency installation
# github.com — checksum-pinned Deno release archive
# objects.githubusercontent.com /
# release-assets.githubusercontent.com
# — GitHub release-asset CDN that
# github.com redirects to for the Deno binary.
# jsr.io / api.jsr.io — the JSR registry + publish API
# *.actions.githubusercontent.com — the GitHub OIDC token endpoint
# ($ACTIONS_ID_TOKEN_REQUEST_URL lives on a dynamic subdomain),
# which JSR exchanges for a single-use publish credential.
# fulcio.sigstore.dev /
# rekor.sigstore.dev /
# tuf-repo-cdn.sigstore.dev — Sigstore public-good infra that
# `jsr publish` contacts to attach a provenance attestation to the
# published version: fulcio mints the short-lived signing cert,
# rekor records the transparency-log entry, tuf-repo-cdn serves the
# trust-root metadata. These are REQUIRED — without them `jsr
# publish` creates the version and THEN fails signing provenance
# ("Connection refused" to fulcio), leaving a published-but-red run.
# If a future runner image serves the OIDC token, the Deno binary, or a
# Sigstore host from a new address and the publish is blocked, widen this
# allowlist — do NOT drop to audit.
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
*.actions.githubusercontent.com:443
objects.githubusercontent.com:443
release-assets.githubusercontent.com:443
dl.deno.land:443
api.jsr.io:443
jsr.io:443
registry.npmjs.org:443
fulcio.sigstore.dev:443
rekor.sigstore.dev:443
tuf-repo-cdn.sigstore.dev:443
disable-sudo: true
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
show-progress: false
- name: Set up pnpm
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6
with:
run_install: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
- name: Install (no scripts)
run: pnpm install --frozen-lockfile --ignore-scripts
env:
npm_config_ignore_scripts: "true"
- name: Verify the commit is on the default branch
# A tag or dispatch ref can point at a commit that never went through
# review on the default branch. Refuse to publish from one.
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -eu
ref="refs/remotes/origin/${DEFAULT_BRANCH}"
git fetch --no-tags --unshallow origin "+refs/heads/${DEFAULT_BRANCH}:${ref}" \
|| git fetch --no-tags origin "+refs/heads/${DEFAULT_BRANCH}:${ref}"
if ! git merge-base --is-ancestor "$GITHUB_SHA" "$ref"; then
echo "::error::$GITHUB_SHA is not on ${DEFAULT_BRANCH}; refusing to publish."
exit 1
fi
- name: Verify actor is on SECURITY-CONTACTS rotation
# The rotation is read from the default branch (fetched above), never
# from the ref being published: otherwise a tag that adds its own
# author to the list would approve itself.
env:
ACTOR: ${{ github.actor }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -eu
git show "refs/remotes/origin/${DEFAULT_BRANCH}:SECURITY-CONTACTS.md" > "$RUNNER_TEMP/security-contacts.md"
CONTACTS="$RUNNER_TEMP/security-contacts.md" node -e '
const fs = require("node:fs");
const text = fs.readFileSync(process.env.CONTACTS, "utf8");
const m = text.match(/<!--\s*BEGIN ACTIVE\s*-->([\s\S]*?)<!--\s*END ACTIVE\s*-->/);
if (!m) { console.error("::error::SECURITY-CONTACTS.md is missing the ACTIVE block."); process.exit(1); }
const handles = [...m[1].matchAll(/^\s*-\s*handle:\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*$/gm)].map(x => x[1]);
const actor = process.env.ACTOR;
if (!handles.includes(actor)) {
console.error(`::error::Actor "${actor}" is not on the SECURITY-CONTACTS active rotation. Active: ${handles.join(", ")}.`);
process.exit(1);
}
console.log(`Actor "${actor}" is on the SECURITY-CONTACTS active rotation.`);
'
- name: Verify tag matches jsr.json version
if: github.event_name == 'push'
run: |
set -eu
tag_version="${GITHUB_REF_NAME#v}"
jsr_version="$(node -p "require('./jsr.json').version")"
if [ "$tag_version" != "$jsr_version" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match jsr.json version $jsr_version"
exit 1
fi
# JSR versions are immutable: once @daloyjs/daloy@<version> exists, a
# re-publish of the same version errors as a duplicate (it cannot be
# re-run for the same version). Skip the publish when the version is
# already live so a re-tag / backfill run stays green instead of dup-
# failing on a version that already shipped. api.jsr.io is in the egress
# allowlist above.
- name: Check whether this JSR version already exists
id: jsr_exists
run: |
set -eu
version="$(node -p "require('./jsr.json').version")"
code="$(curl -sS -o /dev/null -w '%{http_code}' \
"https://api.jsr.io/scopes/daloyjs/packages/daloy/versions/${version}")"
if [ "$code" = "200" ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "::notice::@daloyjs/daloy@${version} is already on JSR; skipping publish."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Install checksum-pinned Deno publisher
if: steps.jsr_exists.outputs.exists != 'true'
run: |
set -eu
publisher_dir="$(mktemp -d "${RUNNER_TEMP}/daloy-deno.XXXXXX")"
curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' \
'https://github.com/denoland/deno/releases/download/v2.9.6/deno-x86_64-unknown-linux-gnu.zip' \
--output "${publisher_dir}/deno.zip"
echo '394f07f4da2bebe6ce6f1e7ce0fa16429b29b08c35e3fac3fe25972676dff4b2'" ${publisher_dir}/deno.zip" | sha256sum --check --strict
unzip -q "${publisher_dir}/deno.zip" -d "${publisher_dir}"
chmod +x "${publisher_dir}/deno"
echo "${publisher_dir}" >> "$GITHUB_PATH"
- name: Packaging signal (deno publish dry-run)
if: steps.jsr_exists.outputs.exists != 'true'
env:
DENO_NO_UPDATE_CHECK: "1"
DENO_DISABLE_PEDANTIC_NODE_WARNINGS: "true"
run: deno publish --unstable-bare-node-builtins --unstable-sloppy-imports --unstable-byonm --no-check --dry-run
- name: Publish @daloyjs/daloy to JSR (OIDC)
if: steps.jsr_exists.outputs.exists != 'true'
env:
DENO_NO_UPDATE_CHECK: "1"
DENO_DISABLE_PEDANTIC_NODE_WARNINGS: "true"
run: deno publish --unstable-bare-node-builtins --unstable-sloppy-imports --unstable-byonm --no-check
# ---------------------------------------------------------------------------
# Publish the GitHub Release object for the pushed tag.
#
# A git tag and a GitHub Release are two different things: pushing `vX.Y.Z`
# triggers the npm publish jobs above, but it does NOT populate the "Releases"
# panel on the repo page. This job closes that gap automatically so the
# Release (and its "Latest" badge) always tracks the published version.
#
# It runs ONLY on tag pushes and ONLY after BOTH npm publish jobs succeed, so
# it inherits their protected-environment approval: no Release is created
# unless a human approved the npm publish and both packages went out.
# ---------------------------------------------------------------------------
github-release:
name: Publish GitHub Release
needs: [publish-core, publish-create-daloy]
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
# `contents: write` is required to create the Release. It is granted ONLY
# here, ONLY after the npm publishes succeeded, and the job runs no
# third-party scripts.
contents: write
steps:
- name: Harden runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2
with:
# `gh release create` only talks to the GitHub API.
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
disable-sudo: true
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
show-progress: false
# Full history + tags so we can compute the previous release tag for
# the compare link in the generated notes.
fetch-depth: 0
fetch-tags: true
- name: Verify tag matches package.json version
run: |
set -eu
tag_version="${GITHUB_REF_NAME#v}"
pkg_version="$(node -p "require('./package.json').version")"
if [ "$tag_version" != "$pkg_version" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $pkg_version"
exit 1
fi
- name: Extract release notes from CHANGELOG.md
run: |
set -eu
version="${GITHUB_REF_NAME#v}"
# Previous semver tag (excluding the current one), newest first.
previous_ref="$(git tag --list 'v*' --sort=-version:refname \
| grep -v -x "${GITHUB_REF_NAME}" | head -n 1 || true)"
export PREVIOUS_REF="$previous_ref"
node -e '
const fs = require("node:fs");
const version = process.argv[1];
const text = fs.readFileSync("CHANGELOG.md", "utf8");
const lines = text.split(/\r?\n/);
const start = lines.findIndex((l) => l.startsWith(`## [${version}]`));
if (start === -1) {
console.error(`::error::CHANGELOG.md has no "## [${version}]" section.`);
process.exit(1);
}
let end = lines.length;
for (let i = start + 1; i < lines.length; i++) {
if (lines[i].startsWith("## ")) { end = i; break; }
}
const body = lines.slice(start + 1, end).join("\n").trim();
const repo = process.env.GITHUB_REPOSITORY;
const prev = process.env.PREVIOUS_REF;
const current = process.env.GITHUB_REF_NAME;
const compare = prev
? `\n\n**Full changelog:** https://github.com/${repo}/compare/${prev}...${current}`
: "";
fs.writeFileSync("RELEASE_NOTES.md", `${body}${compare}\n`);
' "$version"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -eu
# `--verify-tag` attaches to the already-pushed tag; `--latest`
# moves the "Latest" badge to this release. Idempotent: if a release
# for the tag already exists, edit it instead of failing the job.
if gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1; then
gh release edit "${GITHUB_REF_NAME}" \
--title "${GITHUB_REF_NAME}" \
--notes-file RELEASE_NOTES.md \
--latest
else
gh release create "${GITHUB_REF_NAME}" \
--title "${GITHUB_REF_NAME}" \
--notes-file RELEASE_NOTES.md \
--latest \
--verify-tag
fi