Skip to content

Commit 4d50869

Browse files
committed
chore: add npm publish workflow
1 parent 0a3d6f6 commit 4d50869

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

.github/workflows/publish.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Publish to NPM
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
id-token: write
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '24'
23+
registry-url: 'https://registry.npmjs.org'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run tests
29+
run: npm test
30+
31+
- name: Extract version from tag
32+
id: version
33+
run: |
34+
TAG=${GITHUB_REF#refs/tags/v}
35+
echo "version=$TAG" >> $GITHUB_OUTPUT
36+
echo "Version: $TAG"
37+
38+
# - name: Update package.json version
39+
# run: |
40+
# npm version ${{ steps.version.outputs.version }} --no-git-tag-version
41+
42+
- name: Verify version matches tag
43+
run: |
44+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
45+
TAG_VERSION=${{ steps.version.outputs.version }}
46+
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
47+
echo "Error: Package version ($PACKAGE_VERSION) doesn't match tag version ($TAG_VERSION)"
48+
exit 1
49+
fi
50+
echo "Version verification passed: $PACKAGE_VERSION"
51+
52+
- name: Publish to NPM
53+
run: npm publish
54+
env:
55+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
56+
57+
- name: Create GitHub Release
58+
uses: softprops/action-gh-release@v1
59+
with:
60+
name: Release v${{ steps.version.outputs.version }}
61+
body: |
62+
## Release v${{ steps.version.outputs.version }}
63+
64+
🎉 This version has been automatically published to NPM!
65+
66+
📦 **NPM Package**: https://www.npmjs.com/package/hyper-marked/v/${{ steps.version.outputs.version }}
67+
68+
### Installation
69+
```bash
70+
npm install hyper-marked@${{ steps.version.outputs.version }}
71+
```
72+
draft: false
73+
prerelease: false
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
.github
12
test

0 commit comments

Comments
 (0)