Skip to content

Commit 1b0fa3e

Browse files
committed
ci: add GitHub Packages publish job alongside npmjs.com
1 parent 92aae55 commit 1b0fa3e

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish to npm
1+
name: Publish to npm + GitHub Packages
22

33
on:
44
push:
@@ -8,6 +8,7 @@ on:
88
permissions:
99
contents: write # needed for creating GitHub Releases
1010
id-token: write # needed for npm provenance
11+
packages: write # needed for GitHub Packages
1112

1213
jobs:
1314
test:
@@ -24,7 +25,7 @@ jobs:
2425
- name: Run test suite
2526
run: node test/run.js
2627

27-
publish:
28+
publish-npm:
2829
name: Publish to npm
2930
needs: test
3031
runs-on: ubuntu-latest
@@ -52,6 +53,42 @@ jobs:
5253
env:
5354
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5455

56+
publish-github:
57+
name: Publish to GitHub Packages
58+
needs: test
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: '20'
67+
registry-url: 'https://npm.pkg.github.com'
68+
scope: '@manojmallick'
69+
70+
- name: Publish to GitHub Packages
71+
run: |
72+
# GitHub Packages requires a scoped name — publish as @manojmallick/sigmap
73+
# without altering the canonical package.json (which stays as "sigmap" for npmjs.com)
74+
node -e "
75+
const fs = require('fs');
76+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
77+
pkg.name = '@manojmallick/sigmap';
78+
pkg.publishConfig = { registry: 'https://npm.pkg.github.com' };
79+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
80+
"
81+
npm publish --access public
82+
env:
83+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
85+
release:
86+
name: Create GitHub Release
87+
needs: [publish-npm, publish-github]
88+
runs-on: ubuntu-latest
89+
steps:
90+
- uses: actions/checkout@v4
91+
5592
- name: Create GitHub Release
5693
uses: softprops/action-gh-release@v2
5794
with:

0 commit comments

Comments
 (0)