Skip to content

chore: Add safety check for release action #6

chore: Add safety check for release action

chore: Add safety check for release action #6

Workflow file for this run

name: Release npm package
on:
push:
branches:
- main
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm install
- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Generate release version
run: npm run release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }}
- name: Check if version was bumped
run: |
LAST_TAG=$(git describe --tags --abbrev=0)
HEAD_TAG=$(git describe --tags)
if [ "$LAST_TAG" == "$HEAD_TAG" ]; then
echo "No new version detected, skipping push and publish."
exit 0
fi
- name: Push version changes
run: |
git push --follow-tags origin main
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Publish package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }}