Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,79 @@ permissions:
jobs:
release:
runs-on: ubuntu-latest
# Skip if this is a version bump commit
if: |
!contains(github.event.head_commit.message, 'chore: bump version') &&
!contains(github.event.head_commit.message, '[skip release]')
steps:
- name: Check if should skip
id: check
run: |
if [ -z "${{ github.event.head_commit.message }}" ]; then
echo "should_skip=true" >> $GITHUB_OUTPUT
echo "Skipping: head_commit.message is empty"
exit 0
fi

if [[ "${{ github.event.head_commit.message }}" == *"chore: bump version"* ]] || \
[[ "${{ github.event.head_commit.message }}" == *"[skip release]"* ]]; then
echo "should_skip=true" >> $GITHUB_OUTPUT
echo "Skipping: version bump or skip release commit"
else
echo "should_skip=false" >> $GITHUB_OUTPUT
fi

- uses: actions/checkout@v4
if: steps.check.outputs.should_skip != 'true'
with:
fetch-depth: 0
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
if: steps.check.outputs.should_skip != 'true'
with:
node-version: '24'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
if: steps.check.outputs.should_skip != 'true'
run: npm ci

- name: Get current version and bump
if: steps.check.outputs.should_skip != 'true'
id: version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
NEW_VERSION=$(node -e "
const v = '$CURRENT_VERSION'.split('.');
v[2] = parseInt(v[2]) + 1;
v[2] = String(parseInt(v[2]) + 1);
console.log(v.join('.'));
")
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Current: $CURRENT_VERSION → New: $NEW_VERSION"

- name: Update package.json version (in memory only)
if: steps.check.outputs.should_skip != 'true'
run: |
npm version ${{ steps.version.outputs.version }} --no-git-tag-version --no-commit-hooks

- name: Create tag from current commit
if: steps.check.outputs.should_skip != 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
TAG_NAME="v${{ steps.version.outputs.version }}"

# Check if tag already exists
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists, skipping tag creation"
exit 0
fi

git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
git push origin "$TAG_NAME"

- name: Generate release notes
if: steps.check.outputs.should_skip != 'true'
id: release-notes
uses: actions/github-script@v7
with:
Expand All @@ -77,6 +108,7 @@ jobs:
core.setOutput('body', notes || 'See commit history for details.');

- name: Create GitHub Release
if: steps.check.outputs.should_skip != 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
Expand All @@ -91,4 +123,5 @@ jobs:
prerelease: false

- name: Publish to npm
if: steps.check.outputs.should_skip != 'true'
run: npm publish