Skip to content

Commit fe49884

Browse files
authored
chore: Delete copilot/* branches in E2E test workflow (#19)
- [x] Update "Clean up issues and pull requests" step in main branch's test.yml to delete PR branches - [x] Test bash logic for correctness and edge cases - [x] Code review completed and addressed - [x] Address feedback: - Move branch extraction after `gh pr close` (closer to where it's used) - Move `|| true` inside `$()` for proper error handling - Add `TESTING_REPOSITORY` environment variable to avoid hardcoding - Use environment variable in both the scan step and branch deletion - Use `gh api` instead of `git push` for consistent authentication context The implementation: - Extracts branch name from each PR using `gh pr view "$URL" --json headRefName -q .headRefName || true` - Deletes the branch after closing the PR using `gh api -X DELETE "repos/${{ env.TESTING_REPOSITORY }}/git/refs/heads/$branch"` - Handles failures gracefully with `|| true` inside command substitution - Uses centralized `TESTING_REPOSITORY` environment variable for consistency - Uses `gh api` for branch deletion to maintain consistent authentication context with other `gh` CLI commands Note: Similar changes will need to be applied to v1 and v2 branches separately after this PR is merged. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[Task] Delete `copilot/*` branches in E2E test workflow</issue_title> > <issue_description>### Problem > > Before transferring the action to [github/accessibility-scanner](https://github.com/github/accessibility-scanner), I deleted thousands of `copilot/*` branches by running `git branch -r | grep -Eo 'copilot/.*' | xargs -I {} git push origin :{}`. This took more than 30 minutes to complete. > > Because of github-community-projects/continuous-ai-for-accessibility-scanner#2202 [^1], the new `github/accessibility-scanner` repo will never have thousands of defunct `copilot/*` branches…but `github/accessibility-scanner-testing` will. It’s [already starting](https://github.com/github/accessibility-scanner-testing/branches/all?query=copilot%2F). > > ### Solution > > - In [`main`’s test.yml](https://github.com/github/accessibility-scanner/blob/main/.github/workflows/test.yml#L95-L121), [`v2`’s test.yml](https://github.com/github/accessibility-scanner/blob/v2/.github/workflows/test.yml#L95-L121), and [`v1`’s test.yml](https://github.com/github/accessibility-scanner/blob/v1/.github/workflows/test.yml#L137-L163) update the “Clean up issues and pull requests” step to also delete the branch for each PR it deletes. > - Do not use `git branch -r | grep -Eo 'copilot/.*' | xargs -I {} git push origin :{}` to delete all Copilot branches—that is too broad, and it could delete branches unrelated to E2E testing (i.e. branches we want to keep). > - The `gh` CLI doesn’t have a command or flag for deleting branches alongside PRs, but something like this should work: `branch="$(gh pr view <PR-number> --json headRefName -q .headRefName)" && [ -n "$branch" ] && git push origin --delete "$branch" || true`. > > [^1]: And https://github.com/github/accessibility-scanner/pull/7/files#diff-faff1af3d8ff408964a57b2e475f69a6b7c7b71c9978cccc8f471798caac2c88 and https://github.com/github/accessibility-scanner/pull/8/files#diff-faff1af3d8ff408964a57b2e475f69a6b7c7b71c9978cccc8f471798caac2c88</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> Fixes github/continuous-ai-for-accessibility#76 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/github/accessibility-scanner/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
2 parents bdf0e23 + 8f459be commit fe49884

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ concurrency:
1717
group: ${{ github.workflow }}-${{ github.ref }}
1818
cancel-in-progress: false # Allow previous workflows’ clean-up steps to complete
1919

20+
env:
21+
TESTING_REPOSITORY: github/accessibility-scanner-testing
22+
2023
jobs:
2124
test:
2225
name: Test
@@ -74,7 +77,7 @@ jobs:
7477
login_url: http://127.0.0.1:4000/
7578
username: ${{ secrets.TEST_USERNAME }}
7679
password: ${{ secrets.TEST_PASSWORD }}
77-
repository: github/accessibility-scanner-testing
80+
repository: ${{ env.TESTING_REPOSITORY }}
7881
token: ${{ secrets.GH_TOKEN }}
7982
cache_key: ${{ steps.cache_key.outputs.cache_key }}
8083

@@ -110,6 +113,11 @@ jobs:
110113
if [[ "$URL" == *"/pull/"* ]]; then
111114
echo "Closing pull request: $URL"
112115
gh pr close "$URL" || echo "Failed to close pull request: $URL"
116+
branch="$(gh pr view "$URL" --json headRefName -q .headRefName || true)"
117+
if [[ -n "$branch" ]]; then
118+
echo "Deleting branch: $branch"
119+
gh api -X DELETE "repos/${{ env.TESTING_REPOSITORY }}/git/refs/heads/$branch" || echo "Failed to delete branch: $branch"
120+
fi
113121
elif [[ "$URL" == *"/issues/"* ]]; then
114122
echo "Closing issue: $URL"
115123
gh issue close "$URL" || echo "Failed to close issue: $URL"

0 commit comments

Comments
 (0)