From 35445c3208ce8ada71f759614148f9ba76967bfc Mon Sep 17 00:00:00 2001 From: Abimael Martell Date: Tue, 14 Apr 2026 13:12:55 -0700 Subject: [PATCH] Auto-publish npm package when version changes in package.json (#33) Replace tag-based trigger with push-to-main trigger that detects version changes in napi/package.json, removing the need for manual git tags to publish new npm releases. Co-authored-by: Claude Opus 4.6 (1M context) --- .github/workflows/publish.yml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3e0d2a3..91581cf 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,14 +2,41 @@ name: Publish npm package on: push: - tags: ['v*'] + branches: [main] + paths: ['napi/package.json'] permissions: contents: read id-token: write jobs: + check-version: + name: Check version change + runs-on: ubuntu-latest + outputs: + changed: ${{ steps.check.outputs.changed }} + version: ${{ steps.check.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Check if version changed + id: check + run: | + NEW_VERSION=$(node -p "require('./napi/package.json').version") + OLD_VERSION=$(git show HEAD~1:napi/package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version") + echo "old=$OLD_VERSION new=$NEW_VERSION" + if [ "$NEW_VERSION" != "$OLD_VERSION" ]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT" + else + echo "changed=false" >> "$GITHUB_OUTPUT" + fi + build: + needs: check-version + if: needs.check-version.outputs.changed == 'true' name: Build ${{ matrix.target }} runs-on: ${{ matrix.os }} strategy: @@ -68,7 +95,7 @@ jobs: publish: name: Publish to npm - needs: build + needs: [check-version, build] runs-on: ubuntu-latest permissions: contents: read