Skip to content

Commit 7658343

Browse files
author
strausr
committed
chore: add npm publish workflow with trusted publishing and release automation
1 parent 865b5da commit 7658343

4 files changed

Lines changed: 86 additions & 30 deletions

File tree

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Code Owners - Only these people can approve pull requests
2+
# All files in the repository require Code Owner approval
3+
4+
* @strausr

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish Package
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
id-token: write # Required for OIDC
8+
contents: read
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Verify admin permissions
15+
run: |
16+
# Check if the actor is a repository admin
17+
PERMISSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
18+
"https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission" \
19+
| grep -o '"permission":"[^"]*"' | cut -d'"' -f4)
20+
21+
if [ "$PERMISSION" != "admin" ]; then
22+
echo "Error: Only repository admins can trigger publishing. Current permission: $PERMISSION"
23+
exit 1
24+
fi
25+
26+
echo "✓ Verified admin permission for ${{ github.actor }}"
27+
28+
- uses: actions/checkout@v4
29+
30+
- name: Display version to publish
31+
run: |
32+
VERSION=$(node -p "require('./package.json').version")
33+
echo "📦 Publishing version: $VERSION"
34+
echo "version=$VERSION" >> $GITHUB_ENV
35+
36+
- uses: actions/setup-node@v4
37+
with:
38+
node-version: '18'
39+
registry-url: 'https://registry.npmjs.org'
40+
41+
- run: npm ci
42+
43+
- run: npm test --if-present
44+
45+
- run: npm publish
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release Please
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
release-please:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: google-github-actions/release-please-action@v4
17+
id: release
18+
with:
19+
config-file: release-please-config.json
20+
manifest-file: .release-please-manifest.json
21+
22+
- uses: actions/checkout@v4
23+
if: steps.release.outputs.release_created
24+
25+
- uses: actions/setup-node@v4
26+
if: steps.release.outputs.release_created
27+
with:
28+
node-version: '18'
29+
30+
- name: Install dependencies
31+
if: steps.release.outputs.release_created
32+
run: npm ci
33+
34+
- name: Run post-release tasks
35+
if: steps.release.outputs.release_created
36+
run: |
37+
echo "Release PR created: ${{ steps.release.outputs.pr }}"

README.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,3 @@ This project uses [Conventional Commits](https://www.conventionalcommits.org/) f
6666
- `perf`: Performance improvements
6767
- `chore`: Other changes
6868

69-
### Version Management
70-
71-
This project uses [release-please](https://github.com/googleapis/release-please) for automated version management.
72-
73-
```bash
74-
# Install dependencies (includes husky setup)
75-
npm install
76-
77-
# Update release-please manifest (analyzes commits and updates manifest)
78-
npm run release
79-
80-
# Create release PR (creates PR with version bump and changelog)
81-
npm run release:pr
82-
```
83-
84-
**How it works:**
85-
1. Make commits with conventional format (`feat:`, `fix:`, etc.)
86-
2. Run `npm run release` to update the manifest based on commits
87-
3. Run `npm run release:pr` to create a release PR
88-
4. Merge the PR to create the release tag
89-
90-
**Version bumps are automatic based on commit types:**
91-
- `feat:` → minor version (1.0.0 → 1.1.0)
92-
- `fix:` → patch version (1.0.0 → 1.0.1)
93-
- `BREAKING CHANGE:` or `feat!:` → major version (1.0.0 → 2.0.0)
94-
95-
**Note:**
96-
- Update the `repo-url` in `package.json` scripts with your actual GitHub repo
97-
- For beta releases, you can manually edit the version in the manifest or PR
98-
- Alternatively, use `npm version` commands for manual versioning

0 commit comments

Comments
 (0)