Repository navigation
426 lines (418 loc) · 25.7 KB
/
Copy pathpublish.yml
File metadata and controls
426 lines (418 loc) · 25.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
name: Publish to npm
on:
release:
types: [published]
workflow_dispatch:
# The default for this workflow is read-only. Each job that needs more re-declares exactly that (id-token: write for npm provenance in the publish job, id-token and attestations for the Linux attestation job), so nothing else here can inherit that privilege.
permissions:
contents: read
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true'
jobs:
# Everything that executes dependency code lives here, and nothing here can reach the registry token. `npm ci` installs a tree of ~490 packages and `npm test` runs all of them; the current generation of npm supply-chain attacks installs cleanly and fires from inside a function the host calls during normal operation, so a compromised dependency executes in this job as a matter of course. What it must not also get is a job holding the credential: when build and publish shared one, dependency code ran on the same filesystem as the publish step and could rewrite `dist/`, or add a `prepublishOnly` to package.json that npm would then execute with NODE_AUTH_TOKEN in scope. Splitting the jobs closes both of those. It does not make the release untamperable, and nothing here pretends otherwise: `npm run build` *is* esbuild, so dependency code always runs upstream of the artifact this hands over. What the split buys is that artifacts are the only thing that crosses, rather than a whole writable checkout plus a token; the publish job replaces this artifact's dist/native with the signed and attested binaries.
build:
name: Build and verify
runs-on: ubuntu-latest
# A manual workflow_dispatch run must come off main -- otherwise anyone with write access could publish an arbitrary feature-branch commit under the next npm version.
if: github.event_name == 'release' || github.ref == 'refs/heads/main'
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Full history, so the ancestry check below has something to check against.
fetch-depth: 0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
- run: npm ci
- name: Verify release tag matches package.json version
if: github.event_name == 'release'
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME#v}"
PKG_VERSION="$(node -p "require('./package.json').version")"
if [ "$TAG" != "$PKG_VERSION" ]; then
echo "::error::Release tag v$TAG does not match package.json version $PKG_VERSION"
exit 1
fi
# The workflow_dispatch route is pinned to main by the job-level `if`, but the release route was not pinned to anything: a GitHub release can be cut from any commit on any branch, and the tag-name check above only compares the tag to package.json. Someone with write access could tag a feature-branch commit `v9.9.9`, bump package.json to match on that branch, and publish it to npm under the project's name with provenance attached.
- name: Verify the released commit is on main
if: github.event_name == 'release'
run: |
set -euo pipefail
git fetch --no-tags origin main
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "::error::Release commit $GITHUB_SHA is not an ancestor of origin/main; refusing to publish"
exit 1
fi
# The suite's globalSetup (tests/setup/build-bundle.ts) builds native/tg-hook once and the native test files fail, rather than skip, where it cannot. Run inside the crate, `rustup toolchain install` with no argument installs the toolchain native/tg-hook/rust-toolchain.toml pins; explicit, because rustup 1.28 stopped installing it implicitly on first use. The glibc binary that build leaves in dist/native is never published: the publish job deletes dist/native and rebuilds it from the native release artifacts.
- name: Install the pinned Rust toolchain
shell: bash
working-directory: native/tg-hook
run: |
rustup toolchain install
rustup show active-toolchain
- name: Test
run: npm test
- name: Build
run: npm run build
- name: Tarball smoke test
run: |
set -euo pipefail
PACK_DIR="$RUNNER_TEMP/pack"
INSTALL_DIR="$RUNNER_TEMP/smoke-install"
DATA_DIR="$RUNNER_TEMP/smoke-data"
mkdir -p "$PACK_DIR" "$INSTALL_DIR" "$DATA_DIR"
# --ignore-scripts skips the prepack gate on purpose: the test run left its own glibc tg-hook in dist/native, which that gate refuses, and this tarball only feeds the smoke install below; the publish job assembles dist/native afresh and checks it against the recorded hashes.
TARBALL="$(npm pack --ignore-scripts --pack-destination "$PACK_DIR" | tail -1)"
npm install -g "$PACK_DIR/$TARBALL" --prefix "$INSTALL_DIR"
BIN="$INSTALL_DIR/bin/token-goat"
"$BIN" --version
# Index this checked-out repo through the installed tarball binary, then look up a real symbol, so the smoke test exercises the shipped critical path (parse -> index -> surgical read), not just the CLI entrypoint.
export XDG_DATA_HOME="$DATA_DIR"
"$BIN" index .
"$BIN" symbol indexFileSync
shell: bash
- name: Upload the built bundle
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist
path: dist/
retention-days: 1
if-no-files-found: error
# One native hook client per shipped target, each built on a runner of its own architecture so it can run its self-test before it is uploaded; win32-arm64 uses the Windows arm64 runner rather than a cross build from x64 for that reason, since a cross-built binary would ship having never executed. Linux targets are musl-static, so one binary serves glibc and musl distributions, and install under the directory name the installer computes (linux-x64, linux-arm64). No `npm ci` here: scripts/build-native.mjs imports only Node builtins, so the only third-party code these jobs run is the crates Cargo.lock pins. The flags that make the build reproducible live in that script, not in this file.
native:
name: Build tg-hook (${{ matrix.platform-arch }})
if: github.event_name == 'release' || github.ref == 'refs/heads/main'
strategy:
fail-fast: true
matrix:
include:
- platform-arch: win32-x64
runner: windows-latest
target: x86_64-pc-windows-msvc
exe: tg-hook.exe
- platform-arch: win32-arm64
runner: windows-11-arm
target: aarch64-pc-windows-msvc
exe: tg-hook.exe
- platform-arch: linux-x64
runner: ubuntu-latest
target: x86_64-unknown-linux-musl
exe: tg-hook
- platform-arch: linux-arm64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-musl
exe: tg-hook
runs-on: ${{ matrix.runner }}
permissions:
contents: read
env:
TARGET: ${{ matrix.target }}
PLATFORM_ARCH: ${{ matrix.platform-arch }}
EXE: ${{ matrix.exe }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
- name: Install the pinned Rust toolchain and the target
shell: bash
working-directory: native/tg-hook
run: |
set -euo pipefail
rustup toolchain install
rustup target add "$TARGET"
rustup show active-toolchain
- name: Build
shell: bash
run: node scripts/build-native.mjs --target "$TARGET"
# The self-test reports the platform and architecture the binary was compiled for, so a binary filed under the wrong directory fails here instead of on a user's machine.
- name: Self-test on the architecture it ships for
shell: bash
run: |
set -euo pipefail
out="$("dist/native/$PLATFORM_ARCH/$EXE" --selftest)"
echo "$out"
reported="$(node -p 'const s = JSON.parse(process.argv[1]); s.ok === true ? `${s.platform}-${s.arch}` : "not ok"' "$out")"
if [ "$reported" != "$PLATFORM_ARCH" ]; then
echo "::error::tg-hook built for $TARGET reports $reported, expected $PLATFORM_ARCH"
exit 1
fi
- name: Record the sha256
shell: bash
working-directory: dist/native
run: sha256sum "$PLATFORM_ARCH/$EXE" | tee "$PLATFORM_ARCH.sha256"
- name: Upload the binary
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: native-${{ matrix.platform-arch }}
path: |
dist/native/${{ matrix.platform-arch }}/${{ matrix.exe }}
dist/native/${{ matrix.platform-arch }}.sha256
retention-days: 1
if-no-files-found: error
# Authenticode-signs both Windows binaries with a certificate held in a cloud HSM, through jsign, which speaks to either provider: SSL.com eSigner or DigiCert KeyLocker, chosen by the WINDOWS_SIGNING_STORETYPE variable (ESIGNER or DIGICERTONE). The provider's credentials live in the `signing` environment, so a protection rule there can require approval, and no other job in this workflow can read them. This job checks out nothing and installs no npm or Cargo package: it runs jsign and osslsigncode, each downloaded from a pinned URL and checked against a pinned sha256 before use, over the two binaries the native jobs uploaded. With WINDOWS_SIGNING_STORETYPE unset it signs nothing and reports `signed` as false, so the release ships the Linux binaries alone and Windows installs keep the Node hook rather than an unsigned executable that SmartScreen or Smart App Control would block; a storetype that is set but unknown, or missing one of its secrets, still fails here and stops the release.
sign-windows:
name: Sign the Windows binaries
needs: native
# An explicit image rather than ubuntu-latest: the osslsigncode package below is built for Ubuntu 24.04's libraries.
runs-on: ubuntu-24.04
# Repeated rather than inherited through `needs`, because this job holds the signing credentials and should refuse a non-main ref on its own terms.
if: github.event_name == 'release' || github.ref == 'refs/heads/main'
environment:
name: signing
permissions:
contents: read
outputs:
signed: ${{ steps.cfg.outputs.configured }}
env:
JSIGN_URL: https://github.com/ebourg/jsign/releases/download/7.5/jsign-7.5.jar
JSIGN_SHA256: 602a51c3545a6dc4fb99bd2ea7152b26d1345916d0c93ddfbd5936cb735af91c
# The same .deb from two hosts, tried in order under the one sha256 below, so one unresolvable host cannot fail a publish (archive.ubuntu.com did not resolve for run 43052808452).
OSSLSIGNCODE_URLS: https://azure.archive.ubuntu.com/ubuntu/pool/universe/o/osslsigncode/osslsigncode_2.8-2_amd64.deb https://archive.ubuntu.com/ubuntu/pool/universe/o/osslsigncode/osslsigncode_2.8-2_amd64.deb
OSSLSIGNCODE_SHA256: 1aee7be603102633e80b4c67cd939bba2e16a62813e4a3035696727783f632b0
steps:
- name: Require the signing configuration
id: cfg
env:
WINDOWS_SIGNING_STORETYPE: ${{ vars.WINDOWS_SIGNING_STORETYPE }}
WINDOWS_SIGNING_ALIAS: ${{ vars.WINDOWS_SIGNING_ALIAS }}
ESIGNER_USERNAME: ${{ secrets.ESIGNER_USERNAME }}
ESIGNER_PASSWORD: ${{ secrets.ESIGNER_PASSWORD }}
ESIGNER_TOTP_SECRET: ${{ secrets.ESIGNER_TOTP_SECRET }}
DIGICERT_API_KEY: ${{ secrets.DIGICERT_API_KEY }}
DIGICERT_CLIENT_CERT_P12_BASE64: ${{ secrets.DIGICERT_CLIENT_CERT_P12_BASE64 }}
DIGICERT_CLIENT_CERT_PASSWORD: ${{ secrets.DIGICERT_CLIENT_CERT_PASSWORD }}
run: |
set -euo pipefail
case "${WINDOWS_SIGNING_STORETYPE:-}" in
'')
echo "::notice::Windows signing is not configured, so this release ships no Windows binaries and Windows installs keep the Node hook. To ship signed ones, set the WINDOWS_SIGNING_STORETYPE variable to ESIGNER (SSL.com eSigner) or DIGICERTONE (DigiCert KeyLocker) and add that provider's secrets to the signing environment."
echo "configured=false" >> "$GITHUB_OUTPUT"
exit 0
;;
ESIGNER) required=(WINDOWS_SIGNING_ALIAS ESIGNER_USERNAME ESIGNER_PASSWORD ESIGNER_TOTP_SECRET) ;;
DIGICERTONE) required=(WINDOWS_SIGNING_ALIAS DIGICERT_API_KEY DIGICERT_CLIENT_CERT_P12_BASE64 DIGICERT_CLIENT_CERT_PASSWORD) ;;
*)
echo "::error::WINDOWS_SIGNING_STORETYPE is '$WINDOWS_SIGNING_STORETYPE'; it must be ESIGNER (SSL.com eSigner) or DIGICERTONE (DigiCert KeyLocker), or unset to release without Windows binaries."
exit 1
;;
esac
missing=()
for name in "${required[@]}"; do
if [ -z "${!name:-}" ]; then missing+=("$name"); fi
done
if [ "${#missing[@]}" -gt 0 ]; then
echo "::error::Windows signing with $WINDOWS_SIGNING_STORETYPE is missing: ${missing[*]}. Add them to the signing environment (WINDOWS_SIGNING_ALIAS is a variable, the rest are secrets), or unset WINDOWS_SIGNING_STORETYPE to release without Windows binaries."
exit 1
fi
echo "configured=true" >> "$GITHUB_OUTPUT"
- name: Download the win32-x64 binary
if: steps.cfg.outputs.configured == 'true'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-win32-x64
path: unsigned/
- name: Download the win32-arm64 binary
if: steps.cfg.outputs.configured == 'true'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-win32-arm64
path: unsigned/
# Signs exactly the bytes the build jobs recorded, not whatever reached this job under their names.
- name: Check the binaries against the hashes their build recorded
if: steps.cfg.outputs.configured == 'true'
working-directory: unsigned
run: sha256sum -c win32-x64.sha256 win32-arm64.sha256
- name: Install jsign and osslsigncode
if: steps.cfg.outputs.configured == 'true'
run: |
set -euo pipefail
curl -sSfL -o "$RUNNER_TEMP/jsign.jar" "$JSIGN_URL"
echo "$JSIGN_SHA256 $RUNNER_TEMP/jsign.jar" | sha256sum -c -
for url in $OSSLSIGNCODE_URLS; do
curl -sSfL --max-time 60 -o "$RUNNER_TEMP/osslsigncode.deb" "$url" || continue
echo "$OSSLSIGNCODE_SHA256 $RUNNER_TEMP/osslsigncode.deb" | sha256sum -c - && break
done
# Fails closed: after the loop the file must still match the pin, whichever source it came from.
echo "$OSSLSIGNCODE_SHA256 $RUNNER_TEMP/osslsigncode.deb" | sha256sum -c -
# Unpacked rather than installed, so no package maintainer script runs.
dpkg-deb -x "$RUNNER_TEMP/osslsigncode.deb" "$RUNNER_TEMP/osslsigncode"
java -version
"$RUNNER_TEMP/osslsigncode/usr/bin/osslsigncode" --version
# Every signature carries an RFC 3161 timestamp from the provider's authority, so it stays valid after the certificate expires. Credentials reach jsign through `env:` references rather than its command line. WINDOWS_SIGNING_KEYSTORE is optional and overrides the provider's default endpoint (a regional DigiCert host, for example).
- name: Sign
if: steps.cfg.outputs.configured == 'true'
env:
WINDOWS_SIGNING_STORETYPE: ${{ vars.WINDOWS_SIGNING_STORETYPE }}
WINDOWS_SIGNING_ALIAS: ${{ vars.WINDOWS_SIGNING_ALIAS }}
WINDOWS_SIGNING_KEYSTORE: ${{ vars.WINDOWS_SIGNING_KEYSTORE }}
ESIGNER_USERNAME: ${{ secrets.ESIGNER_USERNAME }}
ESIGNER_PASSWORD: ${{ secrets.ESIGNER_PASSWORD }}
ESIGNER_TOTP_SECRET: ${{ secrets.ESIGNER_TOTP_SECRET }}
DIGICERT_API_KEY: ${{ secrets.DIGICERT_API_KEY }}
DIGICERT_CLIENT_CERT_P12_BASE64: ${{ secrets.DIGICERT_CLIENT_CERT_P12_BASE64 }}
DIGICERT_CLIENT_CERT_PASSWORD: ${{ secrets.DIGICERT_CLIENT_CERT_PASSWORD }}
run: |
set -euo pipefail
p12="$RUNNER_TEMP/signing-client.p12"
trap 'rm -f "$p12"' EXIT
extra=()
case "$WINDOWS_SIGNING_STORETYPE" in
ESIGNER)
export JSIGN_STOREPASS="$ESIGNER_USERNAME|$ESIGNER_PASSWORD"
export JSIGN_KEYPASS="$ESIGNER_TOTP_SECRET"
extra+=(--keypass env:JSIGN_KEYPASS)
tsa=http://ts.ssl.com
;;
DIGICERTONE)
(umask 077 && printf '%s' "$DIGICERT_CLIENT_CERT_P12_BASE64" | base64 -d > "$p12")
export JSIGN_STOREPASS="$DIGICERT_API_KEY|$p12|$DIGICERT_CLIENT_CERT_PASSWORD"
tsa=http://timestamp.digicert.com
;;
esac
if [ -n "${WINDOWS_SIGNING_KEYSTORE:-}" ]; then extra+=(--keystore "$WINDOWS_SIGNING_KEYSTORE"); fi
for pa in win32-x64 win32-arm64; do
mkdir -p "signed/$pa"
cp "unsigned/$pa/tg-hook.exe" "signed/$pa/tg-hook.exe"
java -jar "$RUNNER_TEMP/jsign.jar" --storetype "$WINDOWS_SIGNING_STORETYPE" --storepass env:JSIGN_STOREPASS "${extra[@]}" --alias "$WINDOWS_SIGNING_ALIAS" --alg SHA-256 --tsaurl "$tsa" --tsmode RFC3161 --tsretries 5 --tsretrywait 15 --name token-goat --url https://www.npmjs.com/package/token-goat "signed/$pa/tg-hook.exe"
done
# A cryptographic check of what was just signed: the signed digest must match the file, the certificate chain must reach a trusted root, and the timestamp must verify. The runner's CA bundle is the trust store; WINDOWS_SIGNING_ROOT_CA_PEM (a variable, since a root certificate is public) adds the issuing root if the provider's code-signing root is not in that bundle.
- name: Verify the signatures
if: steps.cfg.outputs.configured == 'true'
env:
WINDOWS_SIGNING_ROOT_CA_PEM: ${{ vars.WINDOWS_SIGNING_ROOT_CA_PEM }}
run: |
set -euo pipefail
ca="$RUNNER_TEMP/signing-ca.pem"
cat /etc/ssl/certs/ca-certificates.crt > "$ca"
if [ -n "${WINDOWS_SIGNING_ROOT_CA_PEM:-}" ]; then printf '%s\n' "$WINDOWS_SIGNING_ROOT_CA_PEM" >> "$ca"; fi
for pa in win32-x64 win32-arm64; do
report="$RUNNER_TEMP/verify-$pa.txt"
if ! "$RUNNER_TEMP/osslsigncode/usr/bin/osslsigncode" verify -in "signed/$pa/tg-hook.exe" -CAfile "$ca" -TSA-CAfile "$ca" > "$report" 2>&1; then
cat "$report"
echo "::error::The $pa signature does not verify. If the certificate chain is the failure, set WINDOWS_SIGNING_ROOT_CA_PEM to the provider's code-signing root."
exit 1
fi
if ! grep -q '^Timestamp Server Signature verification: ok' "$report"; then
cat "$report"
echo "::error::The $pa signature carries no verified RFC 3161 timestamp"
exit 1
fi
grep -E '^(Signature verification|Timestamp Server Signature verification|Timestamp time)' "$report" || true
done
- name: Record the signed hashes
if: steps.cfg.outputs.configured == 'true'
working-directory: signed
run: sha256sum win32-x64/tg-hook.exe win32-arm64/tg-hook.exe | tee SHA256SUMS
- name: Upload the signed binaries
if: steps.cfg.outputs.configured == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: native-windows-signed
path: signed/
retention-days: 1
if-no-files-found: error
# Sigstore build provenance for the two Linux binaries, published to this repository's attestations, so `gh attestation verify` can tie a binary to the workflow run that built it. The only job besides publish granted id-token: write, and the only one granted attestations: write; it runs no repository code.
attest-linux:
name: Attest the Linux binaries
needs: native
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.ref == 'refs/heads/main'
permissions:
contents: read
id-token: write
attestations: write
steps:
- name: Download the linux-x64 binary
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-linux-x64
path: native/
- name: Download the linux-arm64 binary
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-linux-arm64
path: native/
- name: Check the binaries against the hashes their build recorded
working-directory: native
run: sha256sum -c linux-x64.sha256 linux-arm64.sha256
- name: Attest build provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-path: |
native/linux-x64/tg-hook
native/linux-arm64/tg-hook
# The only job that can reach the registry. It installs nothing: `npm publish` packs the `files` allowlist and uploads it, which needs the checkout and `dist/` and no dependency tree at all. `--ignore-scripts` then makes "no dependency code runs here" a property of the command rather than of what happens to be on disk, so the lifecycle hooks npm would otherwise fire on publish cannot run either. Held by tests/guards/publish_job_runs_no_dependency_code.test.ts.
publish:
name: Publish to npm
needs: [build, native, sign-windows, attest-linux]
runs-on: ubuntu-latest
# Repeated from the build job rather than inherited through `needs`, because this is the job that holds the token: it should refuse a non-main ref on its own terms, not because an upstream job happened to be skipped.
if: github.event_name == 'release' || github.ref == 'refs/heads/main'
environment:
name: npm
url: https://www.npmjs.com/package/token-goat
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Download the built bundle
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/
- name: Download the linux-x64 binary
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-linux-x64
path: ${{ runner.temp }}/native/
- name: Download the linux-arm64 binary
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-linux-arm64
path: ${{ runner.temp }}/native/
- name: Download the signed Windows binaries
if: needs.sign-windows.outputs.signed == 'true'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: native-windows-signed
path: ${{ runner.temp }}/native-signed/
# dist/native is rebuilt from the release artifacts alone. The bundle's copy is deleted first, because the build job's test run builds a glibc binary into dist/native/linux-x64 for its own tests, and that one must never ship. Artifact downloads do not keep the executable bit, so the Linux binaries get it back here. The Windows binaries are copied only when sign-windows signed them; otherwise the package carries none and Windows installs use the Node hook.
- name: Assemble dist/native from the release artifacts
env:
WINDOWS_SIGNED: ${{ needs.sign-windows.outputs.signed }}
run: |
set -euo pipefail
rm -rf dist/native
mkdir -p dist/native/linux-x64 dist/native/linux-arm64
cp "$RUNNER_TEMP/native/linux-x64/tg-hook" dist/native/linux-x64/tg-hook
cp "$RUNNER_TEMP/native/linux-arm64/tg-hook" dist/native/linux-arm64/tg-hook
chmod 755 dist/native/linux-x64/tg-hook dist/native/linux-arm64/tg-hook
if [ "$WINDOWS_SIGNED" = true ]; then
mkdir -p dist/native/win32-x64 dist/native/win32-arm64
cp "$RUNNER_TEMP/native-signed/win32-x64/tg-hook.exe" dist/native/win32-x64/tg-hook.exe
cp "$RUNNER_TEMP/native-signed/win32-arm64/tg-hook.exe" dist/native/win32-arm64/tg-hook.exe
fi
# The publish gate: exactly the release binaries, each matching the hash the job that produced it recorded, and both Windows files signed when there are any. Without signing, --without-windows makes any Windows file at all a refusal, so an unsigned executable cannot ride along. scripts/verify-native-dist.mjs imports only Node builtins, so this runs no dependency code beside the token.
- name: Refuse unsigned or substituted native binaries
env:
WINDOWS_SIGNED: ${{ needs.sign-windows.outputs.signed }}
run: |
set -euo pipefail
if [ "$WINDOWS_SIGNED" = true ]; then
node scripts/verify-native-dist.mjs dist/native "$RUNNER_TEMP/native-signed/SHA256SUMS" "$RUNNER_TEMP/native/linux-x64.sha256" "$RUNNER_TEMP/native/linux-arm64.sha256"
else
node scripts/verify-native-dist.mjs --without-windows dist/native "$RUNNER_TEMP/native/linux-x64.sha256" "$RUNNER_TEMP/native/linux-arm64.sha256"
fi
- name: Publish
run: npm publish --provenance --access public --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}