ci: add npm publish workflow triggered on push to main

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
a1518 2026-07-01 01:04:20 -07:00
parent 1b3a6d5a4a
commit 2dd744de0f

44
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,44 @@
name: Publish to npm
on:
push:
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
concurrency:
group: npm-publish
cancel-in-progress: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build
run: npm run build
- name: Check version is not already published
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
NPM_VERSION=$(npm view react-native-mask-segment-canvas version 2>/dev/null || echo "0.0.0")
if [ "$PKG_VERSION" = "$NPM_VERSION" ]; then
echo "Error: version $PKG_VERSION already exists on npm. Please bump the version in package.json."
exit 1
fi
echo "Publishing version $PKG_VERSION (npm latest: $NPM_VERSION)"
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}