Skip to content

v2.12.11

v2.12.11 #82

Workflow file for this run

# This workflow will run tests using node and then publish a package to npm when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
name: npm publish
on:
release:
types: [published]
env:
TAG: '${{ github.event.release.tag_name }}'
jobs:
validate-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate version tag pattern
run: |
if [[ ! "${{ env.TAG }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version tag ${{ env.TAG }} invalid."
exit 1
fi
- name: Verify the tag is based off the main branch
run: |
if [[ "${{ github.event.release.target_commitish }}" != "main" ]]; then
echo "Release is not based on main branch but ${{ github.event.release.target_commitish }}"
exit 1
fi
- name: Make sure tag matches package.json version
run: |
PACKAGE_VERSION=$(node -e "console.log(require('./package.json').version);")
VERSION=$(echo "$TAG" | sed 's/v//g')
if [ "$PACKAGE_VERSION" != "$VERSION" ]; then
echo "Different versions between package.json ($PACKAGE_VERSION) and release tag ($VERSION)"
exit 1
fi
test:
runs-on: ubuntu-latest
needs: validate-release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npm run eslint
- run: npm test
build-and-publish:
runs-on: ubuntu-latest
needs: test
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org/
cache: 'npm'
- run: npm install -g npm
- run: npm ci
- run: npm run build
- name: Publish package
run: npm publish --provenance --tag ${{ github.event.release.prerelease && 'next' || 'latest' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_SECRET }}