Skip to content

Commit 0cafb40

Browse files
committed
Change to use OIDC GitHub Actions publishing
1 parent 5cf0212 commit 0cafb40

File tree

2 files changed

+146
-6
lines changed

2 files changed

+146
-6
lines changed

.github/workflows/npm-publish.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2-
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
1+
# This workflow will run tests using node and then publish a package to npm when a release is created
2+
# Uses OIDC trusted publishing - no npm token required!
3+
# For more information see: https://docs.npmjs.com/trusted-publishers/
34

45
name: Node.js Package
56

@@ -21,13 +22,14 @@ jobs:
2122
publish-npm:
2223
needs: build
2324
runs-on: ubuntu-latest
25+
permissions:
26+
id-token: write # Required for OIDC authentication
27+
contents: read
2428
steps:
2529
- uses: actions/checkout@v4
2630
- uses: actions/setup-node@v4
2731
with:
28-
node-version: 20
32+
node-version: 24
2933
registry-url: https://registry.npmjs.org/
3034
- run: npm ci
31-
- run: npm publish
32-
env:
33-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
35+
- run: npm publish --provenance --access public

PUBLISHING.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Publishing @servicestack/react v2.0.0 to npm
2+
3+
## Overview
4+
5+
This package is configured to publish to npm using **OIDC Trusted Publishing** via GitHub Actions. This is more secure than using npm tokens because:
6+
7+
- ✅ No secrets to manage or rotate
8+
- ✅ Automatic authentication via GitHub's OIDC provider
9+
- ✅ Includes provenance attestation for supply chain security
10+
- ✅ Scoped to specific repository and workflow
11+
12+
## Prerequisites
13+
14+
### 1. Configure Trusted Publishing on npm
15+
16+
Before you can publish, you need to set up trusted publishing on npmjs.com:
17+
18+
1. **Go to your package settings on npm:**
19+
- Visit: https://www.npmjs.com/package/@servicestack/react/access
20+
- Or navigate to: Your package → Settings → Publishing Access
21+
22+
2. **Add a Trusted Publisher:**
23+
- Click "Add Trusted Publisher"
24+
- Select "GitHub Actions"
25+
- Fill in the details:
26+
- **Repository owner:** `ServiceStack` (or your GitHub org/username)
27+
- **Repository name:** `servicestack-react`
28+
- **Workflow name:** `npm-publish.yml`
29+
- **Environment name:** (leave blank unless you use GitHub Environments)
30+
31+
3. **Save the configuration**
32+
33+
> **Note:** For first-time packages that don't exist yet on npm, you may need to publish a dummy version first using a traditional npm token, then configure trusted publishing. Alternatively, npm now supports configuring trusted publishing for packages that don't exist yet.
34+
35+
### 2. Verify Your Workflow
36+
37+
The workflow file `.github/workflows/npm-publish.yml` has been updated with:
38+
39+
```yaml
40+
permissions:
41+
id-token: write # Required for OIDC authentication
42+
contents: read
43+
```
44+
45+
And the publish command now includes:
46+
```yaml
47+
npm publish --provenance --access public
48+
```
49+
50+
The `--provenance` flag generates a signed attestation linking the package to your source code and build.
51+
52+
## Publishing Steps
53+
54+
### Option 1: Create a GitHub Release (Recommended)
55+
56+
1. **Ensure your code is ready:**
57+
```bash
58+
npm run build
59+
npm test
60+
```
61+
62+
2. **Commit and push all changes:**
63+
```bash
64+
git add .
65+
git commit -m "Release v2.0.0"
66+
git push origin main
67+
```
68+
69+
3. **Create and push a git tag:**
70+
```bash
71+
git tag v2.0.0
72+
git push origin v2.0.0
73+
```
74+
75+
4. **Create a GitHub Release:**
76+
- Go to: https://github.com/ServiceStack/servicestack-react/releases/new
77+
- Choose tag: `v2.0.0`
78+
- Release title: `v2.0.0`
79+
- Add release notes describing what's new
80+
- Click "Publish release"
81+
82+
5. **GitHub Actions will automatically:**
83+
- ✅ Run tests
84+
- ✅ Build the package
85+
- ✅ Authenticate via OIDC
86+
- ✅ Publish to npm with provenance
87+
- ✅ No npm token needed!
88+
89+
### Option 2: Manual Publishing (Fallback)
90+
91+
If you need to publish manually (not recommended for production):
92+
93+
1. **Create an npm access token** (classic automation token)
94+
2. **Publish locally:**
95+
```bash
96+
npm publish --access public
97+
```
98+
99+
## Verifying the Publication
100+
101+
After publishing, verify:
102+
103+
1. **Check npm:** https://www.npmjs.com/package/@servicestack/react
104+
2. **Verify provenance:** Look for the "Provenance" badge on the npm package page
105+
3. **Check GitHub Actions:** Review the workflow run for any issues
106+
107+
## Troubleshooting
108+
109+
### "OIDC token not found" error
110+
111+
- Ensure `permissions.id-token: write` is set in the workflow
112+
- Verify the workflow is triggered by a release event
113+
- Check that you're using npm CLI version 11.5.1 or later
114+
115+
### "Trusted publisher not configured" error
116+
117+
- Complete the trusted publishing setup on npmjs.com (see Prerequisites)
118+
- Ensure the repository owner, name, and workflow match exactly
119+
120+
### "Package already exists" error
121+
122+
- If this is the first publish, you may need to use `--access public` for scoped packages
123+
- The workflow already includes this flag
124+
125+
## Additional Resources
126+
127+
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/trusted-publishers/)
128+
- [GitHub OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
129+
- [npm Provenance Documentation](https://docs.npmjs.com/generating-provenance-statements)
130+
131+
## Current Package Configuration
132+
133+
- **Package name:** `@servicestack/react`
134+
- **Version:** `2.0.0`
135+
- **Registry:** https://registry.npmjs.org/
136+
- **Access:** Public
137+
- **Provenance:** Enabled
138+

0 commit comments

Comments
 (0)