Repository navigation
273 lines (251 loc) · 10.3 KB
/
Copy pathrelease.yml
File metadata and controls
273 lines (251 loc) · 10.3 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
# SPDX-License-Identifier: Apache-2.0
# Managed by github.com/igorjs-iac/repo-config
#
# Templated by repo-config/modules/hardened-repo/main.tf (variable
# manage_workflow_release). Direct edits in the consuming repo are
# overwritten on the next `terraform apply` against repo-config.
#
# SLSA L3 build + attest pipeline for npm-shaped JavaScript packages.
# Triggered on `v*` tag push (the convention `scripts/release.mjs`
# follows). Produces:
#
# 1. An `npm pack` tarball (the artifact npm publish would receive).
# 2. A per-file in-toto attestation from actions/attest-build-provenance,
# signed by Sigstore (Fulcio + Rekor).
# 3. A combined SLSA v1 provenance attestation from
# slsa-framework/slsa-github-generator, run in an isolated workflow
# context the caller cannot inject into — this is the L2 -> L3 gap
# closer; the build environment the attestation describes is the
# reusable workflow's own runner, not this one.
# 4. A GitHub Release with all three attached (tarball, .sha256
# sidecar, .intoto.jsonl provenance).
#
# When the publish event for the release fires, publish.javascript.yml
# verifies the provenance against the tarball before pushing to npm
# and/or JSR (whichever the package targets via file presence).
#
# Co-existence with scripts/release.mjs:
# - The local script may run `gh release create` to publish notes
# before this workflow attaches artifacts. softprops/action-gh-release
# below matches by tag_name and updates the existing release in place
# rather than colliding. If the script is later migrated to create a
# draft release (recommended in the follow-up), this workflow will
# flip it to published, which is what triggers publish.yml.
name: release
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: "Synthesised dev tag for testing without cutting a real release."
required: false
type: string
default: ""
permissions:
contents: write
jobs:
# ── Resolve tag + version once ─────────────────────────────────────
resolve:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
tag: ${{ steps.r.outputs.tag }}
version: ${{ steps.r.outputs.version }}
steps:
- uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
codeload.github.com:443
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- id: r
env:
INPUT_TAG: ${{ inputs.tag }}
EVENT_NAME: ${{ github.event_name }}
HEAD_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [[ "$$EVENT_NAME" == "push" ]]; then
TAG="${GITHUB_REF##refs/tags/}"
VERSION="${TAG#v}"
elif [[ -n "$$INPUT_TAG" ]]; then
TAG="$$INPUT_TAG"
VERSION="${TAG#v}"
else
SHORT_SHA="$(echo "$$HEAD_SHA" | cut -c1-7)"
TAG="dev-${SHORT_SHA}"
VERSION="0.0.0-${SHORT_SHA}"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "::notice::Resolved tag=${TAG} version=${VERSION}"
# ── Build the npm tarball + attest provenance ──────────────────────
build:
needs: [resolve]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
outputs:
digest: ${{ steps.hash.outputs.digest }}
filename: ${{ steps.pack.outputs.filename }}
steps:
- uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: block
# Allowlist: GitHub API + git transport, npm registry (pnpm
# install), Node.js binaries (setup-node), Sigstore endpoints
# (fulcio for cert issuance, rekor for transparency log,
# tuf-repo-cdn for trust roots). registry.yarnpkg.com kept
# because pnpm fetches some packages from the Yarn mirror.
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
release-assets.githubusercontent.com:443
codeload.github.com:443
registry.npmjs.org:443
registry.yarnpkg.com:443
nodejs.org:443
raw.githubusercontent.com:443
ghcr.io:443
pkg-containers.githubusercontent.com:443
fulcio.sigstore.dev:443
rekor.sigstore.dev:443
tuf-repo-cdn.sigstore.dev:443
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ needs.resolve.outputs.tag }}
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '26'
- name: Enable corepack
run: corepack enable
- run: pnpm install --frozen-lockfile
- name: Build
run: pnpm run build
- id: pack
name: Pack tarball
run: |
set -euo pipefail
mkdir -p dist-pack
npm pack --pack-destination=./dist-pack
FILENAME=$(ls dist-pack/*.tgz | head -1)
echo "filename=${FILENAME}" >> "$GITHUB_OUTPUT"
# Cross-platform sha256 (sha256sum on Linux; this job is
# ubuntu-latest so GNU coreutils are present).
sha256sum "${FILENAME}" > "${FILENAME}.sha256"
echo "::group::Tarball + sha256"
ls -la dist-pack/
cat "${FILENAME}.sha256"
echo "::endgroup::"
- id: hash
name: Compute base64-encoded digest for SLSA generator
run: |
set -euo pipefail
DIGEST=$(cd dist-pack && sha256sum ./*.tgz \
| awk '{print $1" "$NF}' | base64 -w0)
echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT"
- name: Generate SBOM
uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
with:
path: ./
output-file: dist-pack/sbom.cdx.json
format: cyclonedx-json
upload-artifact: false
upload-release-assets: false
- name: Attest per-file build provenance
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
with:
subject-path: dist-pack/*.tgz
- name: Upload artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: package
path: |
dist-pack/*.tgz
dist-pack/*.tgz.sha256
dist-pack/sbom.cdx.json
if-no-files-found: error
retention-days: 14
# ── SLSA L3 provenance via the framework's reusable workflow ───────
# Runs in an isolated job context the caller workflow cannot inject
# into; this is the property that closes the L2 -> L3 gap. The build
# environment the attestation describes is the reusable workflow's
# own runner, not ours. End users verify with either:
# gh attestation verify <file> --owner <owner>
# slsa-verifier verify-artifact --provenance-path <intoto>
# --source-uri github.com/<owner>/<repo> <file>
slsa_provenance:
needs: [resolve, build]
permissions:
id-token: write
contents: write
actions: read
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
with:
base64-subjects: ${{ needs.build.outputs.digest }}
upload-assets: true
upload-tag-name: ${{ needs.resolve.outputs.tag }}
provenance-name: provenance-${{ needs.resolve.outputs.version }}.intoto.jsonl
# ── Attach tarball + sha256 + provenance to the GH release ─────────
# Uses softprops/action-gh-release with tag_name matching: if
# scripts/release.mjs has already created the release (with the
# generated changelog as notes), this UPDATES that release in place
# rather than colliding. If no release exists yet (workflow_dispatch
# or a hand-pushed tag), it creates one.
publish-gh:
needs: [resolve, build, slsa_provenance]
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
steps:
- uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
objects.githubusercontent.com:443
release-assets.githubusercontent.com:443
uploads.github.com:443
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: package
path: dist-release
- name: Summarise release contents
run: |
{
echo "## Release ${{ needs.resolve.outputs.tag }}"
echo ""
echo "**Tarball + checksum + provenance attached.** Verify with:"
echo ""
echo '```bash'
echo "gh attestation verify dist-release/*.tgz --owner ${{ github.repository_owner }}"
echo "slsa-verifier verify-artifact dist-release/*.tgz \\"
echo " --provenance-path *.intoto.jsonl \\"
echo " --source-uri github.com/${{ github.repository }} \\"
echo " --source-tag ${{ needs.resolve.outputs.tag }}"
echo '```'
echo ""
echo '```'
cat dist-release/*.sha256 | sort
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- name: Attach assets to GitHub release
uses: softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b # v3.0.1
with:
tag_name: ${{ needs.resolve.outputs.tag }}
files: |
dist-release/*.tgz
dist-release/*.tgz.sha256
dist-release/sbom.cdx.json
fail_on_unmatched_files: true
prerelease: ${{ contains(needs.resolve.outputs.tag, 'dev-') || contains(needs.resolve.outputs.tag, '-alpha') || contains(needs.resolve.outputs.tag, '-beta') || contains(needs.resolve.outputs.tag, '-rc') }}