Skip to content

Commit 24d6664

Browse files
committed
ci: add PR test workflow; harden npm publish (idempotent, provenance, auth)
The repo had no CI on pull requests at all — only the convert workflow (instruction-file paths) and the tag publish. Adds a Node 20/22/24 matrix running build + tests + pack dry-run on every PR and main push. Publish hardening: skip when the version already exists on the registry (safe re-runs), enable --provenance (id-token permission was already declared but unused), wire NODE_AUTH_TOKEN explicitly, add npm cache, concurrency group, and a timeout.
1 parent 1fa45dd commit 24d6664

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ci-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
test:
18+
name: Node ${{ matrix.node }}
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 10
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
node: [20, 22, 24]
25+
steps:
26+
- uses: actions/checkout@v6
27+
28+
- uses: actions/setup-node@v6
29+
with:
30+
node-version: ${{ matrix.node }}
31+
cache: npm
32+
33+
- run: npm ci
34+
- run: npm run build
35+
- run: npm test
36+
- run: npm pack --dry-run

.github/workflows/publish-npm.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ permissions:
99
contents: read
1010
id-token: write
1111

12+
concurrency:
13+
group: publish-${{ github.ref }}
14+
cancel-in-progress: false
15+
1216
jobs:
1317
publish:
1418
runs-on: ubuntu-latest
19+
timeout-minutes: 10
1520
steps:
1621
- uses: actions/checkout@v6
1722

1823
- uses: actions/setup-node@v6
1924
with:
2025
node-version: "24"
2126
registry-url: "https://registry.npmjs.org"
27+
cache: npm
2228

2329
- name: Verify tag matches package version
2430
run: |
@@ -32,4 +38,18 @@ jobs:
3238
- run: npm run build
3339
- run: npm test
3440
- run: npm pack --dry-run
35-
- run: npm publish
41+
42+
- name: Publish (idempotent, with provenance)
43+
run: |
44+
set -euo pipefail
45+
name=$(node -p "require('./package.json').name")
46+
version=$(node -p "require('./package.json').version")
47+
# Re-running the workflow for an already-published tag should be a
48+
# no-op, not a 409 failure.
49+
if npm view "${name}@${version}" version >/dev/null 2>&1; then
50+
echo "${name}@${version} already published — skipping"
51+
else
52+
npm publish --provenance
53+
fi
54+
env:
55+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)