diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..d384872 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,49 @@ +name: Publish to npm + +on: + push: + tags: ['v*'] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: '22' + cache: npm + - run: npm ci + - run: npm run lint + - run: npm test + + publish: + needs: test + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: '22' + cache: npm + registry-url: 'https://registry.npmjs.org' + - run: npm ci + - name: Verify tag matches package.json version + env: + TAG_REF: ${{ github.ref_name }} + run: | + TAG_VERSION="${TAG_REF#v}" + PKG_VERSION=$(node -p "require('./package.json').version") + if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then + echo "Tag $TAG_VERSION does not match package.json version $PKG_VERSION" + exit 1 + fi + - run: npm publish --provenance --access public + - name: Create GitHub release + env: + GH_TOKEN: ${{ github.token }} + TAG_REF: ${{ github.ref_name }} + run: gh release create "$TAG_REF" --generate-notes