Skip to content

Commit 9f8be84

Browse files
authored
ci: automate npm release flow (verify -> bump/tag -> publish) (#2)
* ci: automate release tagging and npm publish * ci: align pnpm version with packageManager
1 parent 4949b73 commit 9f8be84

4 files changed

Lines changed: 182 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
verify:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup pnpm
17+
uses: pnpm/action-setup@v4
18+
with:
19+
version: 10.28.2
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 22
25+
cache: pnpm
26+
27+
- name: Install dependencies
28+
run: pnpm install --frozen-lockfile
29+
30+
- name: Lint
31+
run: pnpm lint
32+
33+
- name: Typecheck
34+
run: pnpm typecheck
35+
36+
- name: Build
37+
run: pnpm build
38+
39+
- name: Test
40+
run: pnpm test

.github/workflows/publish.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v4
21+
with:
22+
version: 10.28.2
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 22
28+
registry-url: https://registry.npmjs.org
29+
cache: pnpm
30+
31+
- name: Install dependencies
32+
run: pnpm install --frozen-lockfile
33+
34+
- name: Lint
35+
run: pnpm lint
36+
37+
- name: Typecheck
38+
run: pnpm typecheck
39+
40+
- name: Build
41+
run: pnpm build
42+
43+
- name: Test
44+
run: pnpm test
45+
46+
- name: Publish package
47+
run: npm publish --provenance
48+
env:
49+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release-tag.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Release Tag
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
bump:
7+
description: Version bump type
8+
required: true
9+
default: patch
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
release:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Ensure main branch
24+
run: test "${{ github.ref_name }}" = "main"
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Setup pnpm
31+
uses: pnpm/action-setup@v4
32+
with:
33+
version: 10.28.2
34+
35+
- name: Setup Node.js
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: 22
39+
cache: pnpm
40+
41+
- name: Install dependencies
42+
run: pnpm install --frozen-lockfile
43+
44+
- name: Verify (lint, typecheck, build, test)
45+
run: |
46+
pnpm lint
47+
pnpm typecheck
48+
pnpm build
49+
pnpm test
50+
51+
- name: Configure git author
52+
run: |
53+
git config user.name "github-actions[bot]"
54+
git config user.email "github-actions[bot]@users.noreply.github.com"
55+
56+
- name: Bump version and create tag
57+
id: bump
58+
run: |
59+
NEW_VERSION=$(npm version ${{ github.event.inputs.bump }} -m "chore(release): %s [skip ci]")
60+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
61+
62+
- name: Push release commit and tag
63+
run: git push origin HEAD:${{ github.ref_name }} --follow-tags
64+
65+
- name: Release summary
66+
run: echo "Created and pushed ${{ steps.bump.outputs.version }}"

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,33 @@ codebase-visualizer <path>
227227
- File + exported function granularity (no internal function calls)
228228
- Client-side 3D requires WebGL
229229

230+
## Release
231+
232+
Publishing is automated and **only happens on `v*` tags**.
233+
234+
### One-time setup
235+
236+
1. Create an npm automation token (npmjs.com → Access Tokens).
237+
2. Add it to GitHub repository secrets as `NPM_TOKEN`.
238+
239+
### Normal CI (before release)
240+
241+
- `CI` workflow runs on every PR and push to `main`:
242+
- lint → typecheck → build → test
243+
244+
### Create a release (auto bump + auto tag)
245+
246+
1. Open GitHub Actions → `Release Tag`.
247+
2. Click **Run workflow** on `main`.
248+
3. Select bump type: `patch` | `minor` | `major`.
249+
250+
`Release Tag` will:
251+
- run lint → typecheck → build → test
252+
- bump `package.json` version
253+
- create and push `vX.Y.Z` tag
254+
255+
Pushing that tag triggers `Publish to npm`, which runs checks again and publishes.
256+
230257
## Contributing
231258

232259
Contributions are welcome. Please open an issue first to discuss what you'd like to change.

0 commit comments

Comments
 (0)