Skip to content

Commit 2b0f401

Browse files
committed
Publish workflow
1 parent 6b949f4 commit 2b0f401

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ jobs:
2828
run: npm run lint
2929
- name: Test
3030
run: npm run test
31+
- name: Verify dual module compatibility
32+
run: |
33+
node -e "require('./dist/index.js')" # Test CJS
34+
node --input-type=module -e "import * as mod from './dist/index.mjs'; console.log(typeof mod)" # Test ESM

.github/workflows/publish.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish Package to NPM
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Use Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: '20.x'
18+
registry-url: 'https://registry.npmjs.org'
19+
cache: 'npm'
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Verify package version matches release tag
25+
run: |
26+
PKG_VERSION=$(node -p "require('./package.json').version")
27+
GITHUB_REF_NAME=${GITHUB_REF#refs/tags/}
28+
GITHUB_TAG=${GITHUB_REF_NAME#v}
29+
echo "Package version: $PKG_VERSION"
30+
echo "GitHub tag (without v): $GITHUB_TAG"
31+
if [ "$PKG_VERSION" != "$GITHUB_TAG" ] && [ "$PKG_VERSION" != "${GITHUB_TAG#v}" ]; then
32+
echo "⚠️ WARNING: GitHub release tag ($GITHUB_REF_NAME) doesn't match package.json version ($PKG_VERSION)"
33+
echo "The package will be published with the version from package.json: $PKG_VERSION"
34+
fi
35+
36+
- name: Build
37+
run: npm run build
38+
39+
- name: Test
40+
run: npm test
41+
42+
- name: Verify dual module compatibility
43+
run: |
44+
node -e "require('./dist/index.js')" # Test CJS
45+
node --input-type=module -e "import * as mod from './dist/index.mjs'; console.log(typeof mod)" # Test ESM
46+
47+
- name: Publish to NPM
48+
run: npm publish
49+
env:
50+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)