-
Notifications
You must be signed in to change notification settings - Fork 42
103 lines (92 loc) · 3.49 KB
/
Copy pathnpm-publish.yml
File metadata and controls
103 lines (92 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Release — Core (npm + GitHub Packages)
on:
push:
tags:
- 'v[0-9]*'
permissions:
contents: write # create GitHub Releases
id-token: write # npm provenance
packages: write # GitHub Packages
jobs:
# ── 1. Gate: all tests must pass ─────────────────────────────────────────
test:
name: Test (Node 20)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Run test suite
run: node test/run.js
# ── 2. Publish to npmjs.com ───────────────────────────────────────────────
publish-npm:
name: Publish → npmjs.com
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Verify package version matches tag
run: |
PKG_VERSION="v$(node -p "require('./package.json').version")"
TAG_VERSION="${GITHUB_REF_NAME}"
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
echo "ERROR: package.json version ($PKG_VERSION) does not match tag ($TAG_VERSION)"
exit 1
fi
echo "✓ version check passed: $PKG_VERSION"
- name: Verify npm registry and token
run: |
echo "NPM Registry: $(npm config get registry)"
echo "Token set: $([ -n "$NODE_AUTH_TOKEN" ] && echo 'yes' || echo 'no')"
echo "Token length: ${#NODE_AUTH_TOKEN}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm
run: |
# NPM_TOKEN must be an 'Automation' token from npmjs.org settings
# (not requiring 2FA in CI/CD environments)
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ── 3. Publish to GitHub Packages (scoped) ───────────────────────────────
publish-github:
name: Publish → GitHub Packages
needs: test
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://npm.pkg.github.com'
scope: '@manojmallick'
- name: Publish to GitHub Packages
run: |
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.name = '@manojmallick/sigmap';
pkg.publishConfig = { registry: 'https://npm.pkg.github.com' };
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ── 4. Create GitHub Release (npm only) ──────────────────────────────────
release:
name: Create GitHub Release
needs: [publish-npm, publish-github]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
make_latest: true