Skip to content

Commit 6c25e70

Browse files
authored
Merge pull request #1 from preshin/ci/npm-publish
Add CI workflow to auto-publish to npm on version bump
2 parents 474e7dc + c74379d commit 6c25e70

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

.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 to npm
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
# Only publish when the version in package.json changed
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 22
17+
registry-url: https://registry.npmjs.org
18+
19+
- name: Install dependencies
20+
run: npm ci
21+
22+
- name: Build
23+
run: npm run build
24+
25+
- name: Check if version changed
26+
id: version
27+
run: |
28+
LOCAL=$(node -p "require('./package.json').version")
29+
PUBLISHED=$(npm view react-formio-engine version 2>/dev/null || echo "0.0.0")
30+
echo "local=$LOCAL" >> $GITHUB_OUTPUT
31+
echo "published=$PUBLISHED" >> $GITHUB_OUTPUT
32+
if [ "$LOCAL" != "$PUBLISHED" ]; then
33+
echo "changed=true" >> $GITHUB_OUTPUT
34+
else
35+
echo "changed=false" >> $GITHUB_OUTPUT
36+
fi
37+
38+
- name: Publish to npm
39+
if: steps.version.outputs.changed == 'true'
40+
run: npm publish
41+
env:
42+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
43+
44+
- name: Tag release
45+
if: steps.version.outputs.changed == 'true'
46+
run: |
47+
git config user.name "github-actions"
48+
git config user.email "github-actions@github.com"
49+
git tag "v${{ steps.version.outputs.local }}"
50+
git push origin "v${{ steps.version.outputs.local }}"

0 commit comments

Comments
 (0)