diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3f83dc4..2cf583a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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: @@ -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 }} \ No newline at end of file