Publish #9
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 | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Tag to publish (e.g., v2.2.1)' | |
| required: true | |
| type: string | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.tag || github.ref }} | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.19.0 | |
| registry-url: https://registry.npmjs.org | |
| cache: npm | |
| - name: Install deps | |
| run: npm install | |
| - name: Verify versions aligned | |
| run: npm run sync:versions:check | |
| - name: Verify tag matches package version | |
| run: | | |
| TAG_INPUT="${{ inputs.tag }}" | |
| if [ -n "$TAG_INPUT" ]; then | |
| TAG="${TAG_INPUT#v}" | |
| else | |
| TAG="${GITHUB_REF_NAME#v}" | |
| fi | |
| VERSION="$(node -p "require('./package.json').version")" | |
| if [ "$TAG" != "$VERSION" ]; then | |
| echo "Tag ($TAG) does not match package.json version ($VERSION)" | |
| exit 1 | |
| fi | |
| - name: Build package | |
| run: npm run build | |
| - name: Build types | |
| run: npm run build:types | |
| - name: Test package | |
| run: npm test | |
| - name: Verify changelog exists | |
| run: | | |
| if [ ! -s CHANGELOG.md ]; then | |
| echo "CHANGELOG.md is empty. Run npm run changelog before tagging." | |
| exit 1 | |
| fi | |
| - name: Verify changelog version matches package | |
| run: | | |
| VERSION="$(node -p "require('./package.json').version")" | |
| CHANGELOG_VERSION="$(node -e "const fs=require('fs');const m=fs.readFileSync('CHANGELOG.md','utf8').match(/## \\[(\\d+\\.\\d+\\.\\d+(?:-[^\\]]+)?)\\]/);console.log(m?m[1]:'')")" | |
| if [ "$VERSION" != "$CHANGELOG_VERSION" ]; then | |
| echo "CHANGELOG.md latest version ($CHANGELOG_VERSION) does not match package.json ($VERSION)" | |
| exit 1 | |
| fi | |
| - name: Publish to npm | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |