Skip to content

Commit

Permalink
feat(ci): enhance npm publish workflow
Browse files Browse the repository at this point in the history
- Update Node.js to v18.x
- Add package version validation
- Add testing trigger for main branch
- Add conditional steps for release vs push events

The workflow now validates package versions against release tags
and includes a temporary push trigger for testing purposes.
  • Loading branch information
ergut committed Dec 4, 2024
1 parent 0a50a72 commit fedb716
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Publish Package to npm

on:
release:
types: [created]
push:
branches: [ main ] # Added for testing - you can remove this later

jobs:
build:
Expand All @@ -10,10 +13,21 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
- run: npm publish
- name: Check package version
if: github.event_name == 'release' # Only check version on releases
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
GITHUB_REF_VERSION=${GITHUB_REF#refs/tags/v}
if [ "$PKG_VERSION" != "$GITHUB_REF_VERSION" ]; then
echo "Package version ($PKG_VERSION) does not match tag version ($GITHUB_REF_VERSION)"
exit 1
fi
- name: Publish to npm
if: github.event_name == 'release' # Only publish on releases
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 comments on commit fedb716

Please sign in to comment.