From 9b1e4eb8ba0b6ef6a4f04187825c2334d73e2e3b Mon Sep 17 00:00:00 2001 From: Tym Rabchuk Date: Mon, 6 Apr 2026 15:04:22 -0400 Subject: [PATCH] Auto-bump patch version on PR merge with deploy key --- .github/workflows/release.yml | 61 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e8f0014..7272fbe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,13 @@ name: Release on: - push: + pull_request: + types: [closed] branches: [main] jobs: release: + if: github.event.pull_request.merged == true runs-on: ubuntu-latest permissions: contents: write @@ -13,29 +15,31 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + ssh-key: ${{ secrets.VERSION_BUMP_KEY }} - - name: Get version from package.json - id: version + - name: Bump patch version + id: bump run: | - VERSION=$(jq -r '.version // empty' package.json) - if [[ -z "$VERSION" ]]; then - echo "No version in package.json, skipping release" - echo "skip=true" >> "$GITHUB_OUTPUT" - exit 0 - fi - TAG="v$VERSION" - if git rev-parse "$TAG" >/dev/null 2>&1; then - echo "Tag $TAG already exists, skipping release" - echo "skip=true" >> "$GITHUB_OUTPUT" - exit 0 - fi - echo "version=$VERSION" >> "$GITHUB_OUTPUT" - echo "tag=$TAG" >> "$GITHUB_OUTPUT" - echo "skip=false" >> "$GITHUB_OUTPUT" + CURRENT=$(jq -r '.version' package.json) + MAJOR=$(echo "$CURRENT" | cut -d. -f1) + MINOR=$(echo "$CURRENT" | cut -d. -f2) + PATCH=$(echo "$CURRENT" | cut -d. -f3) + NEW_PATCH=$((PATCH + 1)) + NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" + echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT" + echo "Bumping $CURRENT → $NEW_VERSION" + jq --arg v "$NEW_VERSION" '.version = $v' package.json > tmp.json && mv tmp.json package.json - - name: Generate changelog - if: steps.version.outputs.skip == 'false' - id: changelog + - name: Commit version bump + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add package.json + git commit -m "bump to v${{ steps.bump.outputs.version }}" + git push + + - name: Generate release notes + id: notes run: | PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") if [[ -n "$PREV_TAG" ]]; then @@ -44,6 +48,9 @@ jobs: RANGE="HEAD" fi NOTES=$(git log "$RANGE" --oneline --no-merges 2>/dev/null | head -50) + if [[ -z "$NOTES" ]]; then + NOTES="Merged: ${{ github.event.pull_request.title }}" + fi { echo "notes<> "$GITHUB_OUTPUT" - name: Create tag and release - if: steps.version.outputs.skip == 'false' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git tag "${{ steps.version.outputs.tag }}" - git push origin "${{ steps.version.outputs.tag }}" - gh release create "${{ steps.version.outputs.tag }}" \ - --title "${{ steps.version.outputs.tag }}" \ - --notes "${{ steps.changelog.outputs.notes }}" + TAG="v${{ steps.bump.outputs.version }}" + git tag "$TAG" + git push origin "$TAG" + gh release create "$TAG" \ + --title "$TAG" \ + --notes "${{ steps.notes.outputs.notes }}"