fix(ci): add provenance flag and fix package.json #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to npm (on tag) | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| - '*.*.*' | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: npm ci --prefer-offline --no-audit | |
| - name: Build | |
| run: npm run build | |
| - name: Run tests | |
| run: npm test | |
| continue-on-error: true | |
| - name: Verify package.json version matches tag | |
| run: | | |
| TAG_NAME=${GITHUB_REF#refs/tags/} | |
| TAG_VERSION=${TAG_NAME#v} # Remove 'v' prefix if exists | |
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
| if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then | |
| echo "Error: Tag version ($TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)" | |
| exit 1 | |
| fi | |
| echo "Version check passed: $TAG_VERSION" | |
| - name: Publish to npm | |
| run: npm publish --access public --provenance | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| release_name: Release ${{ github.ref_name }} | |
| draft: false | |
| prerelease: false |