diff --git a/.github/workflows/create-tag-and-exit.yml b/.github/workflows/create-tag-and-exit.yml index a00fde1c..50b77600 100644 --- a/.github/workflows/create-tag-and-exit.yml +++ b/.github/workflows/create-tag-and-exit.yml @@ -9,6 +9,7 @@ on: permissions: contents: write + pull-requests: write jobs: tag: @@ -73,7 +74,9 @@ jobs: echo "" done >> CHANGELOG.md - - name: Commit and push CHANGELOG.md + - name: Create PR for CHANGELOG.md update + env: + GH_TOKEN: ${{ github.token }} run: | git config user.name "github-actions" git config user.email "github-actions@github.com" @@ -82,25 +85,19 @@ jobs: echo "No changelog changes to commit" exit 0 fi + + BRANCH_NAME="chore/update-changelog-${{ steps.version.outputs.tag }}" + git checkout -B "$BRANCH_NAME" git commit -m "chore: update changelog for ${{ steps.version.outputs.tag }}" + git push --force-with-lease origin "$BRANCH_NAME" - # Pull with rebase and push, with retry on failure - max_retries=3 - for i in $(seq 1 $max_retries); do - git fetch origin main - if ! git rebase origin/main; then - if git diff --name-only --diff-filter=U | grep -q .; then - echo "Rebase failed due to conflicts; aborting." - git rebase --abort - exit 1 - fi - echo "Rebase failed; aborting." - git rebase --abort || true - exit 1 - fi - git push origin main && exit 0 - echo "Push attempt $i failed, retrying..." - sleep 2 - done - echo "Failed to push after $max_retries attempts" - exit 1 + # Create PR only if one doesn't already exist for this branch + if gh pr view "$BRANCH_NAME" --json state -q '.state' 2>/dev/null | grep -q "OPEN"; then + echo "PR already exists for $BRANCH_NAME; skipping creation." + else + gh pr create \ + --title "chore: update changelog for ${{ steps.version.outputs.tag }}" \ + --body "Automated changelog update for release ${{ steps.version.outputs.tag }}" \ + --base main \ + --head "$BRANCH_NAME" + fi