check package.json version #1
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: | |
| push: | |
| tags: | |
| - "v[0-9]+.[0-9]+.[0-9]+" | |
| - "v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+" | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| registry-url: "https://registry.npmjs.org/" | |
| - name: Determine pre-release tag | |
| run: | | |
| TAG_NAME=${GITHUB_REF_NAME} | |
| echo "Detected tag: $TAG_NAME" | |
| if [[ "$TAG_NAME" == *-alpha.* ]]; then | |
| echo "tag=alpha" >> $GITHUB_ENV | |
| else | |
| echo "tag=latest" >> $GITHUB_ENV | |
| fi | |
| - name: Verify version matches tag | |
| run: | | |
| PKG_VERSION=$(node -p "require('./package.json').version") | |
| TAG_VERSION=${GITHUB_REF_NAME#v} | |
| if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then | |
| echo "::error::package.json version ($PKG_VERSION) does not match tag ($TAG_VERSION)" | |
| exit 1 | |
| fi | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test | |
| - name: Build | |
| run: npm run build | |
| - name: Publish | |
| run: npm publish --access public --tag ${{ env.tag }} | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |