-
Notifications
You must be signed in to change notification settings - Fork 1
delete merged branch #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
delete merged branch #131
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds automatic cleanup of release branches after they are merged. The workflow now includes a step to delete the release branch once the auto-merge is confirmed complete.
Key Changes
- Added a new workflow step that executes after PR auto-merge is enabled
- Implements branch deletion with safety checks to verify the PR was actually merged
| # Wait for PR to be merged | ||
| pr_number="$(gh pr view "$BRANCH" --json number -q .number)" | ||
| # Confirm PR is merged before deleting branch | ||
| merged="$(gh pr view "$pr_number" --json merged -q .merged)" | ||
| if [ "$merged" = "true" ]; then | ||
| git push origin --delete "$BRANCH" | ||
| echo "Deleted branch $BRANCH after successful merge." | ||
| else | ||
| echo "PR not merged, branch not deleted." | ||
| fi |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 118 is misleading - the code doesn't actually wait for the PR to be merged. Since auto-merge was just enabled in the previous step (line 110), the PR may not be merged yet when this step runs. This could result in the branch not being deleted even though the PR will eventually merge. Consider adding a polling loop with timeout to actually wait for the merge, or use GitHub's branch protection settings to automatically delete branches after merge instead.
| # Wait for PR to be merged | |
| pr_number="$(gh pr view "$BRANCH" --json number -q .number)" | |
| # Confirm PR is merged before deleting branch | |
| merged="$(gh pr view "$pr_number" --json merged -q .merged)" | |
| if [ "$merged" = "true" ]; then | |
| git push origin --delete "$BRANCH" | |
| echo "Deleted branch $BRANCH after successful merge." | |
| else | |
| echo "PR not merged, branch not deleted." | |
| fi | |
| # Poll for PR to be merged (max 5 minutes, check every 10 seconds) | |
| pr_number="$(gh pr view "$BRANCH" --json number -q .number)" | |
| timeout=300 | |
| interval=10 | |
| elapsed=0 | |
| while true; do | |
| merged="$(gh pr view "$pr_number" --json merged -q .merged)" | |
| if [ "$merged" = "true" ]; then | |
| git push origin --delete "$BRANCH" | |
| echo "Deleted branch $BRANCH after successful merge." | |
| break | |
| fi | |
| if [ "$elapsed" -ge "$timeout" ]; then | |
| echo "Timeout waiting for PR to be merged. Branch not deleted." | |
| break | |
| fi | |
| echo "PR not merged yet, waiting..." | |
| sleep "$interval" | |
| elapsed=$((elapsed + interval)) | |
| done |
| run: | | ||
| set -euo pipefail | ||
| # Wait for PR to be merged | ||
| pr_number="$(gh pr view "$BRANCH" --json number -q .number)" |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR number is already retrieved in the previous step and could be passed to this step to avoid redundant API calls. Consider storing the PR number in an output variable in the 'Create pull request' step and referencing it here using steps.create_pr.outputs.pr_number instead of making another API call.
No description provided.