Skip to content

Commit 954746d

Browse files
committed
ci(npm): publish on version tags
- Add GitHub Actions workflow for tag releases (vX.Y.Z) and guard against tag/version mismatch - Support npm Trusted Publishing (OIDC) with NPM_TOKEN fallback - Add package-lock.json for deterministic npm ci in CI - Exclude .github/ from npm package tarball and document automated releases
1 parent 799bb0d commit 954746d

4 files changed

Lines changed: 98 additions & 0 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Input — GitHub Actions runner, npm registry, git tags
2+
# Output — Publishes `dagain` package to npm on version tags
3+
# Position — CI/CD workflow; if this file changes, update this header and folder Markdown.
4+
5+
name: Publish to npm
6+
7+
on:
8+
push:
9+
tags:
10+
- "v*.*.*"
11+
workflow_dispatch: {}
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
id-token: write
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 24
27+
cache: "npm"
28+
29+
- name: Install
30+
run: npm ci --no-audit --no-fund
31+
32+
- name: Test
33+
run: npm test
34+
35+
- name: Verify tag matches package.json version
36+
if: startsWith(github.ref, 'refs/tags/v')
37+
run: |
38+
TAG="${GITHUB_REF_NAME#v}"
39+
PKG="$(node -p "require('./package.json').version")"
40+
echo "tag=$TAG pkg=$PKG"
41+
if [ "$TAG" != "$PKG" ]; then
42+
echo "::error::Tag ($TAG) does not match package.json version ($PKG)"
43+
exit 1
44+
fi
45+
46+
- name: Publish (npm Trusted Publishing)
47+
if: ${{ secrets.NPM_TOKEN == '' }}
48+
run: npm publish --provenance --access public
49+
50+
- name: Publish (npm token)
51+
if: ${{ secrets.NPM_TOKEN != '' }}
52+
env:
53+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
54+
run: |
55+
npm config set //registry.npmjs.org/:_authToken "${NODE_AUTH_TOKEN}"
56+
npm publish --provenance --access public

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.taskgraph/
33
.choreo/
44
.worktrees/
5+
.github/
56

67
*.tgz
78
GOAL.md

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ Then transfer via GitHub UI: **Settings → General → Transfer ownership**.
161161

162162
### npm + npx
163163

164+
#### Automated publish (recommended)
165+
166+
Publishing is automated via GitHub Actions on version tags (`vX.Y.Z`). The tag must match `package.json.version`.
167+
168+
1) Configure npm Trusted Publishing (OIDC) for `knot0-com/dagain` and workflow filename `npm-publish.yml` (npmjs.com → package Settings → Trusted Publisher).
169+
170+
2) Cut a release:
171+
172+
```bash
173+
npm version patch
174+
git push --follow-tags
175+
```
176+
177+
3) Verify:
178+
179+
```bash
180+
npx dagain --help
181+
```
182+
183+
#### Manual publish
184+
164185
1) Ensure you’re logged in:
165186

166187
```bash

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)