Repository navigation
305 lines (293 loc) · 14.6 KB
/
Copy pathrelease-npm.yml
File metadata and controls
305 lines (293 loc) · 14.6 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
# Publish the Node bindings (crates/areev-js) to npm. Reads its target name
# from package.json — currently `@areev/areev` (unscoped `areev` is pending
# an npm similarity-filter exception; see CLAUDE.md's Status section).
#
# napi-rs ships a native addon per platform. This builds the `.node` for each
# target, then publishes one small platform package per target
# (`<name>-<platform>`) plus the thin main package that loads the right one at
# runtime via optionalDependencies (the layout the review flagged as missing).
#
# Trigger: on a published GitHub Release (tag `vX.Y.Z`) or manual dispatch.
#
# Authentication is npm TRUSTED PUBLISHING (OIDC), not a token. There is no
# npm secret: the publish job's `id-token: write` lets npm verify that the
# upload came from THIS workflow file in THIS repository. Prerequisite, once
# per package on npmjs.com: a GitHub Actions trusted publisher with
# owner `AreevAI`, repository `areev`, workflow `release-npm.yml`, no
# environment, and DIRECT `npm publish` allowed (configs created after
# 2026-09-03 default to staged publish only, which would park every upload
# behind a human 2FA approval). Each package's `repository.url` must match
# this repo exactly — napi copies it into the platform packages. A package
# NAME that has never been published cannot be configured beforehand; its
# first publish needs an interactive (2FA) login, then add the publisher.
# Why: npm is retiring bypass-2FA tokens for direct publishing (~January
# 2027), and the token this replaced silently expired mid-release on 1.14.4.
#
# NOTE: native cross-platform CI is finicky — watch the first release run and
# adjust the target matrix / napi flags to your installed @napi-rs/cli (v3) if a
# leg fails. The set of targets here must match `napi.targets` in package.json.
name: release-npm
on:
release:
types: [published]
workflow_dispatch:
inputs:
preview:
description: publish a prerelease from this branch under the preview channel
type: boolean
default: false
defaults:
run:
working-directory: crates/areev-js
permissions:
contents: read
concurrency:
group: release-npm-${{ github.event.release.tag_name || github.ref }}
cancel-in-progress: false
jobs:
# index.js is GENERATED and hard-codes the expected version in every
# platform arm. Bumping package.json without re-running `napi build` leaves
# it asserting the previous version, and any consumer with
# NAPI_RS_ENFORCE_VERSION_CHECK set then fails at require() against a
# correctly installed package — this is exactly how 1.0.3 shipped stuck at
# 1.0.1. Seconds here, versus a broken package on the registry.
preflight:
name: preflight (versions agree)
runs-on: ubuntu-latest
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/stamp-preview
with:
preview: ${{ inputs.preview }}
- name: Check every version site agrees
run: |
python3 scripts/check_versions.py \
${{ inputs.preview && '--preview' || '' }} \
${{ github.event_name == 'release' && format('--tag {0}', github.ref_name) || '' }}
build:
name: build ${{ matrix.settings.target }}
needs: preflight
runs-on: ${{ matrix.settings.host }}
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
build: npx napi build --platform --release --target x86_64-apple-darwin -- --locked
- host: macos-latest
target: aarch64-apple-darwin
build: npx napi build --platform --release --target aarch64-apple-darwin -- --locked
# Both Linux legs build NATIVELY, INSIDE a Debian 11 container:
# * in a container, because the *build host's* glibc becomes the
# addon's runtime floor. Built straight on ubuntu-latest (24.04,
# glibc 2.39) the addon installs fine on Debian 12 / Raspberry Pi
# OS Bookworm and then dies at require() with napi's misleading
# "Cannot find native binding … npm optional dependencies bug"
# (the real error is `GLIBC_2.39 not found`). Bullseye's 2.31
# floor covers Debian 11+/Ubuntu 20.04+/RPi OS Bullseye+. This is
# the npm-side equivalent of release-pypi.yml's manylinux images.
# * natively rather than cross-compiled, because turso's C deps
# (mimalloc/zstd) don't build under an old cross-gcc — the free
# arm64 runner removes the need to cross at all (same move as
# release-pypi.yml).
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
container: node:20-bullseye
- host: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
container: node:20-bullseye
- host: windows-latest
target: x86_64-pc-windows-msvc
build: npx napi build --platform --release --target x86_64-pc-windows-msvc -- --locked
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/stamp-preview
with:
preview: ${{ inputs.preview }}
- uses: actions/setup-node@v7
if: ${{ !matrix.settings.container }}
with:
node-version: 20
- uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.container }}
with:
targets: ${{ matrix.settings.target }}
- uses: Swatinem/rust-cache@v2
if: ${{ !matrix.settings.container }}
- run: npm ci
if: ${{ !matrix.settings.container }}
- name: Build
if: ${{ !matrix.settings.container }}
run: ${{ matrix.settings.build }}
# Linux: same build, run inside the old-glibc image. The non-slim node
# image is buildpack-deps-based, so node + gcc + curl are already there
# and nothing needs apt (Debian 11 leaves LTS in 2026 and its repos will
# move to archive.debian.org — an `apt-get update` here would rot).
# Root-owned outputs are fine; later steps only read them.
- name: Build in ${{ matrix.settings.container }}
if: ${{ matrix.settings.container }}
working-directory: ${{ github.workspace }}
run: |
docker run --rm -v "$PWD":/build -w /build/crates/areev-js \
-e TARGET=${{ matrix.settings.target }} \
${{ matrix.settings.container }} bash -c '
set -eux
curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
. "$HOME/.cargo/env"
npm ci
npx napi build --platform --release --target "$TARGET" -- --locked
'
# A too-new glibc floor is invisible until a user require()s the addon on
# an older distro, and napi reports it as a missing binding. Fail here
# instead. Plain grep, so it works on a foreign-arch ELF too.
- name: Assert the glibc floor
if: ${{ matrix.settings.container }}
run: |
need=$(grep -aoh 'GLIBC_[0-9]\+\.[0-9]\+' ./*.node | sort -uV | tail -1)
echo "highest glibc symbol required: ${need:-none}"
if [ "$(printf '%s\nGLIBC_2.31\n' "${need:-GLIBC_2.0}" | sort -V | tail -1)" != "GLIBC_2.31" ]; then
echo "::error::addon requires $need, above the GLIBC_2.31 floor — it will fail to load on Debian 11/12 and Raspberry Pi OS"
exit 1
fi
- uses: actions/upload-artifact@v7
with:
name: bindings-${{ matrix.settings.target }}
path: crates/areev-js/*.node
if-no-files-found: error
publish:
name: publish to npm
needs: build
# Only a real release publishes — see the same guard in release-cli.yml.
# Without it a `workflow_dispatch` ships whatever version is in
# package.json to the registry, from any branch.
if: github.event_name == 'release' || inputs.preview
runs-on: ubuntu-latest
permissions:
# The npm trusted-publishing identity (no token), build provenance
# and the SBOM asset (#81).
id-token: write
attestations: write
contents: write
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/stamp-preview
with:
preview: ${{ inputs.preview }}
- uses: actions/setup-node@v7
with:
# Trusted publishing needs Node >= 22.14.0 and npm >= 11.5.1.
node-version: 24
registry-url: https://registry.npmjs.org
# Pin npm 11, not `latest`: npm 12 turns dependency install scripts,
# git and remote deps off by default, which is a separate migration.
- name: npm 11 (trusted publishing needs >= 11.5.1)
run: |
npm install -g npm@11
node -e 'const [a,b,c]=process.argv[1].split(".").map(Number); if (a<11||(a===11&&(b<5||(b===5&&c<1)))) { console.error("npm "+process.argv[1]+" < 11.5.1: trusted publishing would fall back to no auth"); process.exit(1) }' "$(npm --version)"
- run: npm ci
- uses: actions/download-artifact@v8
with:
path: crates/areev-js/artifacts
- name: Create platform package dirs
run: npx napi create-npm-dirs
- name: Collect per-platform binaries into npm/ dirs
run: npx napi artifacts
# Attest before publishing: an artifact on the registry that no
# attestation covers is worse than one with none, because the security
# model claims every artifact is attested. This one DOES gate the
# publish — it is a security claim, not paperwork.
- name: Attest build provenance for the native addons
uses: actions/attest-build-provenance@v4
with:
subject-path: crates/areev-js/npm/*/*.node
- name: Publish platform packages + main to npm
# We do NOT use `napi prepublish` here: it publishes every platform
# package in one shot, and we want the main package to go out LAST so
# a half-published release never advertises a platform that is not on
# the registry yet.
#
# `prepare-npm.mjs` asserts that every target in `napi.targets` built,
# stamps versions, wires optionalDependencies, and prints the dirs to
# publish. Publishes skip anything already on the registry, so re-runs
# are idempotent.
#
# The main package and per-platform packages publish under whatever
# name is currently in package.json (`@areev/areev` + scoped platform
# names as of 1.6.0 — unscoped `areev` still 403s npm's similarity
# filter; see CLAUDE.md's Status section for where that stands). Any
# OTHER 403 here is a real failure (auth/2FA/ownership); do NOT warn
# past it. A 404 on the PUT of a package that exists means npm found
# no credentials: the package's trusted publisher is missing or does
# not match this workflow (owner/repo/filename are case-sensitive), so
# don't chase the registry for it — a manifest that promises a package npm refused breaks
# `require()` on that platform (the pre-1.2.3 Windows incident).
run: |
set -euo pipefail
NPM_TAG=""
if [ "${{ inputs.preview }}" = "true" ]; then
NPM_TAG="--tag preview"
echo "preview build of $GITHUB_SHA — publishing under the 'preview' dist-tag"
fi
publish_if_absent() { # $1 = package name, $2 = version, $3 = dir
if [ "$(npm view "$1@$2" version 2>/dev/null || true)" = "$2" ]; then
echo "$1@$2 already on npm — skipping"
else
echo "Publishing $1@$2"
# --provenance (#81): npm's own registry-visible attestation,
# generated from this workflow's OIDC identity. Trusted
# publishing would attach it anyway; the flag keeps that
# explicit and fails loudly if it ever cannot. It is separate
# from the GitHub attestation above and worth having both — this
# is the one a consumer sees on the package page, and the one
# `npm audit signatures` checks.
(cd "$3" && npm publish --access public --provenance $NPM_TAG)
fi
}
mapfile -t DIRS < <(node scripts/prepare-npm.mjs)
for dir in "${DIRS[@]}"; do
name=$(node -p "require('./$dir/package.json').name")
ver=$(node -p "require('./$dir/package.json').version")
publish_if_absent "$name" "$ver" "$dir"
done
main_name=$(node -p "require('./package.json').name")
main_ver=$(node -p "require('./package.json').version")
publish_if_absent "$main_name" "$main_ver" "."
# No NODE_AUTH_TOKEN on purpose: npm uses the OIDC identity first and
# only falls back to a token, and a stale one would mask a broken
# trusted-publisher config behind a confusing auth error.
# Two SBOMs, because the package has two dependency graphs and only one
# of them is visible to npm: `npm sbom` describes the JS tree, while
# everything the addon actually links is Cargo's. Publishing only the
# npm one would describe a package with almost no dependencies.
#
# AFTER the publish, and `continue-on-error`: a bill of materials is
# documentation about a build, not the build, and it must never be able
# to withhold a release from users. On the 1.5.2 tag it did exactly that
# — a wrong flag here meant npm never got the packages at all.
- name: Generate and attach the SBOMs
continue-on-error: true
working-directory: ${{ github.workspace }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME#v}"
mkdir -p sbom
(cd crates/areev-js && npm sbom --sbom-format cyclonedx --omit dev) \
> "sbom/areev-${VERSION}-npm.cdx.json"
rustup update stable
cargo install cargo-cyclonedx --version 0.5.7 --locked
# areev-js is NOT a workspace member, so it carries its own lockfile
# and is described from its own manifest. cargo-cyclonedx takes
# NEITHER `--locked` nor `-p`, ignores `--override-filename`, and
# writes `<package>.cdx.json` beside the manifest; `--top-level` is
# deliberately absent because it truncates to DIRECT dependencies.
cargo cyclonedx --manifest-path crates/areev-js/Cargo.toml \
--format json --spec-version 1.5
cp crates/areev-js/areev-js.cdx.json "sbom/areev-${VERSION}-node-cargo.cdx.json"
test -s "sbom/areev-${VERSION}-node-cargo.cdx.json"
gh release upload "$GITHUB_REF_NAME" sbom/*.cdx.json --clobber --repo "$GITHUB_REPOSITORY"