Skip to content

Commit d8fc281

Browse files
ci: add publish.yml — auto-publish to npm on v* tag push (#48)
Mirrors the tangle-network/agent-runtime publish workflow. Tag push fires verify (typecheck+test+build+version-lock check), then publish (idempotent — skips if version already on npm registry). Requires NPM_TOKEN repo secret. Co-authored-by: Drew Stone <drewstone329@gmail.com>
1 parent cce5fce commit d8fc281

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
verify:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: pnpm/action-setup@v4
16+
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: 22
20+
cache: pnpm
21+
registry-url: https://registry.npmjs.org
22+
23+
- name: Install deps
24+
run: pnpm install --frozen-lockfile
25+
26+
- name: Typecheck
27+
run: pnpm run typecheck
28+
29+
- name: Test
30+
run: pnpm run test
31+
32+
- name: Build
33+
run: pnpm run build
34+
35+
- name: Verify tag/version lock
36+
run: |
37+
NPM_VERSION=$(node -p "require('./package.json').version")
38+
if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then
39+
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
40+
if [ "$TAG_VERSION" != "$NPM_VERSION" ]; then
41+
echo "::error::Tag/version mismatch: tag=$TAG_VERSION package=$NPM_VERSION."
42+
exit 1
43+
fi
44+
fi
45+
echo "Version locked: $NPM_VERSION"
46+
47+
publish-npm:
48+
needs: verify
49+
if: startsWith(github.ref, 'refs/tags/v')
50+
runs-on: ubuntu-latest
51+
permissions:
52+
contents: read
53+
id-token: write
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- uses: pnpm/action-setup@v4
58+
59+
- uses: actions/setup-node@v4
60+
with:
61+
node-version: 22
62+
cache: pnpm
63+
registry-url: https://registry.npmjs.org
64+
65+
- run: pnpm install --frozen-lockfile
66+
- run: pnpm run build
67+
68+
# Idempotent: re-running a tag whose npm version is already published
69+
# must not fail the workflow.
70+
- name: Publish to npm (skip if already published)
71+
run: |
72+
NAME=$(node -p "require('./package.json').name")
73+
VERSION=$(node -p "require('./package.json').version")
74+
if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then
75+
echo "$NAME@$VERSION already on registry; skipping publish"
76+
else
77+
pnpm publish --no-git-checks --access public
78+
fi
79+
env:
80+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)