From 6be635f5aa07482d50a37cdb17b21695c2fdbfce Mon Sep 17 00:00:00 2001 From: Ryan Anderson Date: Tue, 23 Dec 2025 15:05:52 -0600 Subject: [PATCH] fix: handle null head_commit and add error handling - Add null check for head_commit.message - Fix version bumping logic (use String() for patch version) - Add check for existing tags before creating - Make all steps conditional to prevent errors - Better error handling throughout --- .github/workflows/release.yml | 47 +++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index db4bd27..af3542e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 }} @@ -91,4 +123,5 @@ jobs: prerelease: false - name: Publish to npm + if: steps.check.outputs.should_skip != 'true' run: npm publish