From 1747d5f023fd78d8ef309a19561aa1330dc4d10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgardo=20Obreg=C3=B3n?= Date: Fri, 26 Dec 2025 20:16:28 -0500 Subject: [PATCH] ci: add release pr strategy --- .github/workflows/release-finalize.yml | 54 ++++++++++++++++++++++++ .github/workflows/release.yml | 57 ++++++++++++++++++-------- 2 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/release-finalize.yml diff --git a/.github/workflows/release-finalize.yml b/.github/workflows/release-finalize.yml new file mode 100644 index 0000000..328f366 --- /dev/null +++ b/.github/workflows/release-finalize.yml @@ -0,0 +1,54 @@ +name: Finalize Release + +on: + push: + branches: + - main + paths: + - 'pyproject.toml' + +jobs: + finalize: + # Only run if this is a version bump commit + if: contains(github.event.head_commit.message, 'Bump version to') + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get version from pyproject.toml + id: get_version + run: | + VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2) + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Create annotated tag + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "v${{ steps.get_version.outputs.version }}" \ + -m "Release version ${{ steps.get_version.outputs.version }}" + + - name: Push tag + run: | + git push origin refs/tags/v${{ steps.get_version.outputs.version }} + + - name: Create GitHub Release + env: + GH_TOKEN: ${{ github.token }} + run: | + gh release create "v${{ steps.get_version.outputs.version }}" \ + --title "Release v${{ steps.get_version.outputs.version }}" \ + --notes "Release v${{ steps.get_version.outputs.version }}" \ + --latest + + - name: Delete release branch + continue-on-error: true + run: | + BRANCH_NAME="release/v${{ steps.get_version.outputs.version }}" + git push origin --delete "$BRANCH_NAME" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 221cbc4..2a9ff14 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Create Release +name: Create Release PR on: workflow_dispatch: @@ -28,6 +28,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: write # Needed to push commits and tags + pull-requests: write # Needed to create pull requests steps: - name: Checkout code @@ -64,25 +65,45 @@ jobs: git add pyproject.toml git commit -m "Bump version to ${{ steps.bump_version.outputs.new_version }}" - - name: Create annotated tag + - name: Create release branch + id: create_branch run: | - git tag -a "v${{ steps.bump_version.outputs.new_version }}" \ - -m "Release version ${{ steps.bump_version.outputs.new_version }}" + BRANCH_NAME="release/v${{ steps.bump_version.outputs.new_version }}" + git checkout -b "$BRANCH_NAME" + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT - - name: Push changes and tag + - name: Push release branch run: | - git push origin main - git push origin refs/tags/v${{ steps.bump_version.outputs.new_version }} + git push origin ${{ steps.create_branch.outputs.branch_name }} - - name: Create GitHub Release - uses: actions/create-release@v1 + - name: Create Pull Request env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Auto-provided by GitHub - with: - tag_name: v${{ steps.bump_version.outputs.new_version }} - release_name: Release v${{ steps.bump_version.outputs.new_version }} - body: | - Version bumped from ${{ steps.current_version.outputs.version }} - to ${{ steps.bump_version.outputs.new_version }} - draft: false - prerelease: false + GH_TOKEN: ${{ github.token }} + run: | + gh pr create \ + --base main \ + --head ${{ steps.create_branch.outputs.branch_name }} \ + --title "Release v${{ steps.bump_version.outputs.new_version }}" \ + --body "## Release v${{ steps.bump_version.outputs.new_version }} + + This PR bumps the version from ${{ steps.current_version.outputs.version }} to ${{ steps.bump_version.outputs.new_version }}. + + ### Pre-merge Checklist + - [ ] All tests pass + - [ ] All lint checks pass + - [ ] Version bump is correct + + ### Post-merge Actions + Once merged, the following will happen automatically: + 1. Git tag \`v${{ steps.bump_version.outputs.new_version }}\` will be created + 2. GitHub release will be published + 3. PyPI publish workflow will trigger + + --- + 🤖 This PR was created automatically by the release workflow" \ + --label "release" + + - name: Output PR info + run: | + echo "✅ Release PR created successfully!" + echo "Review and merge the PR to finalize the release."