Skip to content

Commit 80c6dc0

Browse files
authored
chore: add npm trusted publishing workflow
1 parent d7dd441 commit 80c6dc0

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

.github/workflows/publish-npm.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish npm
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- "v*"
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: publish-npm
14+
cancel-in-progress: false
15+
16+
jobs:
17+
publish:
18+
name: Publish tokenleak to npm
19+
if: github.repository == 'ya-nsh/tokenleak' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
20+
runs-on: ubuntu-latest
21+
environment: npm-publish
22+
permissions:
23+
contents: read
24+
id-token: write
25+
steps:
26+
- name: Check out repository
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: "24"
33+
registry-url: "https://registry.npmjs.org"
34+
35+
- name: Set up Bun
36+
uses: oven-sh/setup-bun@v2
37+
with:
38+
bun-version: "1.3.10"
39+
40+
- name: Install dependencies
41+
run: bun install --frozen-lockfile
42+
43+
- name: Run checks
44+
run: bun run check
45+
46+
- name: Prepare npm package
47+
run: bun run prepublish
48+
49+
- name: Publish to npm
50+
working-directory: dist
51+
run: npm publish

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,38 @@ bun run format
6161

6262
5. Never commit directly to `main`.
6363

64+
## Release Publishing
65+
66+
Tokenleak publishes to npm from GitHub Actions with npm Trusted Publishing. The publish workflow does not store an npm token and does not run for pull requests.
67+
68+
Configure the package once from an npm account with publish access:
69+
70+
```bash
71+
npm trust github tokenleak --repo ya-nsh/tokenleak --file publish-npm.yml --env npm-publish
72+
```
73+
74+
Use these trusted publisher fields if configuring in npmjs.com instead:
75+
76+
- Provider: GitHub Actions
77+
- Organization or user: `ya-nsh`
78+
- Repository: `tokenleak`
79+
- Workflow file: `publish-npm.yml`
80+
- Environment: `npm-publish`
81+
- Allowed action: `npm publish`
82+
83+
After a release PR is merged and the version is ready, publish with one of:
84+
85+
```bash
86+
# Manual release from the default branch
87+
gh workflow run publish-npm.yml --ref main
88+
89+
# Tag-triggered release
90+
git tag v<version>
91+
git push origin v<version>
92+
```
93+
94+
Only users with write access to the repository can manually trigger the workflow or push release tags. Forks and pull requests cannot publish because the workflow has no `pull_request` trigger, and the publish job is restricted to `ya-nsh/tokenleak` on `main` or `v*` tags.
95+
6496
## Code Style
6597

6698
- **Strict TypeScript**: No `any` types. Use `unknown` and narrow properly.

0 commit comments

Comments
 (0)