Skip to content

Commit ef23383

Browse files
Copilotempeje
andauthored
Configure NPM publishing with OIDC trusted publishers (#28)
* Initial plan * Configure NPM publishing with OIDC trusted publishers Co-authored-by: empeje <[email protected]> * Add documentation for NPM trusted publisher setup Co-authored-by: empeje <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: empeje <[email protected]>
1 parent c950c52 commit ef23383

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

.github/PUBLISHING.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# NPM Publishing Setup
2+
3+
This repository is configured to use NPM's [Trusted Publishers](https://docs.npmjs.com/trusted-publishers) feature with OIDC authentication via GitHub Actions.
4+
5+
## How It Works
6+
7+
When a new release is created on GitHub, the workflow automatically publishes the package to NPM using short-lived OIDC tokens instead of long-lived NPM tokens. This provides better security and includes cryptographic provenance attestations.
8+
9+
## Setup Instructions
10+
11+
To complete the trusted publisher configuration, a package maintainer needs to:
12+
13+
1. Go to [npmjs.com](https://www.npmjs.com) and log in
14+
2. Navigate to the package: [@kulkul/tinyurl-client](https://www.npmjs.com/package/@kulkul/tinyurl-client)
15+
3. Go to **Settings****Publishing** (or access directly at: `https://www.npmjs.com/package/@kulkul/tinyurl-client/access`)
16+
4. Click **"Add trusted publisher"**
17+
5. Configure with these details:
18+
- **Provider**: GitHub Actions
19+
- **Organization**: `kulkultech`
20+
- **Repository**: `tinyurl-client`
21+
- **Workflow**: `test-and-publish.yml`
22+
- **Environment**: Leave blank (not using deployment environments)
23+
24+
## Publishing a New Version
25+
26+
1. Update the version in `package.json`
27+
2. Commit the change
28+
3. Create a new release on GitHub with a tag (e.g., `v1.0.9`)
29+
4. The GitHub Actions workflow will automatically:
30+
- Run tests
31+
- Build the package
32+
- Publish to NPM with provenance attestations
33+
34+
## Benefits
35+
36+
- 🔒 **Enhanced Security**: No long-lived NPM tokens stored as secrets
37+
-**Provenance**: Cryptographic proof of where and how the package was built
38+
- 🤖 **Automated**: Fully automated publishing on release creation
39+
- 🔍 **Transparent**: Build logs and provenance are publicly verifiable
40+
41+
## Troubleshooting
42+
43+
If publishing fails:
44+
1. Ensure the trusted publisher is configured on npmjs.com
45+
2. Verify the repository, workflow name, and organization match exactly
46+
3. Check that the release was created (not just a tag)
47+
4. Review the GitHub Actions logs for detailed error messages

.github/workflows/test-and-publish.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
needs: test
3636
runs-on: ubuntu-latest
3737
if: github.event_name == 'release' && github.event.action == 'created'
38+
permissions:
39+
contents: read
40+
id-token: write
3841
steps:
3942
- uses: actions/checkout@v3
4043

@@ -52,6 +55,4 @@ jobs:
5255
run: yarn build
5356

5457
- name: Publish to NPM
55-
run: yarn publish --access public --non-interactive
56-
env:
57-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
58+
run: npm publish --provenance --access public

0 commit comments

Comments
 (0)