Skip to content

Commit 148575d

Browse files
authored
Add npm publishing metadata and release workflow (#3)
* Add npm publishing metadata and release workflow - Fill in package.json author/repository/bugs/homepage so the published tarball links back to the repo for discovery and issue filing. - Add .github/workflows/release.yml that publishes to npm on v* tag push with provenance. Verifies the tag matches package.json version before publishing; requires NPM_TOKEN in Actions secrets. - Update CONTRIBUTING.md release section to describe the workflow instead of the "run npm publish manually" stopgap. * Add npm run release script for bump-and-push flow npm run release -- <patch|minor|major> runs typecheck + tests via the preversion hook, then npm version bumps package.json and tags, then postversion does git push --follow-tags so the commit and tag land together. That tag push is what triggers the release workflow to publish to npm.
1 parent c02fbc2 commit 148575d

3 files changed

Lines changed: 64 additions & 9 deletions

File tree

.github/workflows/release.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
id-token: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version-file: .nvmrc
19+
cache: npm
20+
registry-url: https://registry.npmjs.org
21+
22+
- run: npm ci
23+
24+
- run: npm run typecheck
25+
26+
- run: npm test
27+
28+
- run: npm run build
29+
30+
- name: Verify tag matches package.json version
31+
run: |
32+
tag="${GITHUB_REF_NAME#v}"
33+
pkg="$(node -p "require('./package.json').version")"
34+
if [ "$tag" != "$pkg" ]; then
35+
echo "Tag $GITHUB_REF_NAME ($tag) does not match package.json version $pkg" >&2
36+
exit 1
37+
fi
38+
39+
- run: npm publish --provenance --access public
40+
env:
41+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

CONTRIBUTING.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ Out of scope without an ADR:
112112

113113
## Releasing (maintainers)
114114

115-
1. Bump `package.json` version.
116-
2. Update `CHANGELOG.md` with the new section.
117-
3. `git commit -m "Release vX.Y.Z"`
118-
4. `git tag vX.Y.Z && git push --tags`
119-
5. The `release.yml` workflow publishes to npm on tag push and
120-
creates the GitHub release. (Until that workflow lands, run
121-
`npm publish` manually.)
115+
1. Update `CHANGELOG.md` with the new section and commit it.
116+
2. `npm run release -- <patch|minor|major>` (or an explicit version
117+
like `0.2.0`). This runs typecheck + tests, bumps
118+
`package.json`, creates the `vX.Y.Z` commit and tag, and pushes
119+
both with `git push --follow-tags`.
120+
3. The `release.yml` workflow publishes to npm on tag push.
121+
Requires `NPM_TOKEN` in the repo's GitHub Actions secrets; the
122+
workflow also verifies the tag matches `package.json` before
123+
publishing with provenance.
122124

123125
## Code of conduct
124126

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"typecheck": "tsc --noEmit",
2121
"test": "node --import tsx --test 'test/**/*.test.ts'",
2222
"test:watch": "node --import tsx --test --watch 'test/**/*.test.ts'",
23-
"prepublishOnly": "npm run typecheck && npm test && npm run build"
23+
"prepublishOnly": "npm run typecheck && npm test && npm run build",
24+
"preversion": "npm run typecheck && npm test",
25+
"postversion": "git push --follow-tags",
26+
"release": "npm version"
2427
},
2528
"dependencies": {
2629
"commander": "^12.1.0"
@@ -32,5 +35,14 @@
3235
"undici": "^6.20.0"
3336
},
3437
"keywords": ["userback", "cli", "feedback"],
35-
"license": "MIT"
38+
"license": "MIT",
39+
"author": "Jim Remsik <jim@beflagrant.com>",
40+
"repository": {
41+
"type": "git",
42+
"url": "git+https://github.com/beflagrant/userback-cli.git"
43+
},
44+
"bugs": {
45+
"url": "https://github.com/beflagrant/userback-cli/issues"
46+
},
47+
"homepage": "https://github.com/beflagrant/userback-cli#readme"
3648
}

0 commit comments

Comments
 (0)