Skip to content

Commit cf818cf

Browse files
ci: add automatic NPM publishing workflow (#1)
- Publishes to NPM when version changes in package.json - Creates GitHub releases automatically - Skips publishing for doc-only changes - Free for public repositories
1 parent 410b7fb commit cf818cf

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Publish to NPM
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '**.md'
9+
- 'example/**'
10+
- 'assets/**'
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '18'
26+
registry-url: 'https://registry.npmjs.org'
27+
28+
- name: Install dependencies
29+
run: yarn install --frozen-lockfile
30+
31+
- name: Build package
32+
run: yarn prepare
33+
34+
- name: Check if version changed
35+
id: version_check
36+
run: |
37+
CURRENT_VERSION=$(node -p "require('./package.json').version")
38+
PUBLISHED_VERSION=$(npm view react-native-store-age-signals-native-modules version 2>/dev/null || echo "0.0.0")
39+
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
40+
echo "published=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT
41+
if [ "$CURRENT_VERSION" != "$PUBLISHED_VERSION" ]; then
42+
echo "changed=true" >> $GITHUB_OUTPUT
43+
else
44+
echo "changed=false" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Publish to NPM
48+
if: steps.version_check.outputs.changed == 'true'
49+
run: npm publish --access public
50+
env:
51+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
52+
53+
- name: Create GitHub Release
54+
if: steps.version_check.outputs.changed == 'true'
55+
uses: actions/create-release@v1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
with:
59+
tag_name: v${{ steps.version_check.outputs.current }}
60+
release_name: Release v${{ steps.version_check.outputs.current }}
61+
draft: false
62+
prerelease: false

0 commit comments

Comments
 (0)