2222#
2323# Options:
2424# --dry-run Show what would be tested without running
25+ # --clean Enable cleanup of test resources (default: false)
2526# --help, -h Show help message
2627#
2728# Examples:
2829# ./e2e.sh # Run all tests
2930# ./e2e.sh --dry-run # See what would be tested
31+ # ./e2e.sh --clean # Run tests and clean up resources
3032#
3133# Prerequisites:
3234# - GitHub CLI (gh) installed and authenticated
@@ -915,29 +917,50 @@ wait_for_pr_reviews() {
915917
916918cleanup_test_resources () {
917919 info " Cleaning up test resources..."
920+ local issues_closed=0
921+ local prs_closed=0
922+ local branches_deleted=0
918923
919924 # Close all issues
920- gh issue list --limit 20 --json number --jq ' .[].number' | while read -r issue_num; do
925+ info " Checking for open issues to close..."
926+ while read -r issue_num; do
921927 if [[ -n " $issue_num " ]]; then
922- gh issue close " $issue_num " --comment " Closed by e2e test cleanup" & > /dev/null || true
928+ if gh issue close " $issue_num " --comment " Closed by e2e test cleanup" & > /dev/null; then
929+ info " Closed issue #$issue_num "
930+ (( issues_closed++ ))
931+ else
932+ warning " Failed to close issue #$issue_num "
933+ fi
923934 fi
924- done
935+ done < <( gh issue list --limit 20 --json number --jq ' .[].number ' 2> /dev/null || true )
925936
926937 # Close all PRs
927- gh pr list --limit 20 --json number --jq ' .[].number' | while read -r pr_num; do
938+ info " Checking for open pull requests to close..."
939+ while read -r pr_num; do
928940 if [[ -n " $pr_num " ]]; then
929- gh pr close " $pr_num " --comment " Closed by e2e test cleanup" & > /dev/null || true
941+ if gh pr close " $pr_num " --comment " Closed by e2e test cleanup" & > /dev/null; then
942+ info " Closed pull request #$pr_num "
943+ (( prs_closed++ ))
944+ else
945+ warning " Failed to close pull request #$pr_num "
946+ fi
930947 fi
931- done
948+ done < <( gh pr list --limit 20 --json number --jq ' .[].number ' 2> /dev/null || true )
932949
933950 # Delete test branches
934- git branch -r | grep ' origin/test-pr-\|origin/claude-test-branch\|origin/codex-test-branch' | sed ' s/origin\///' | while read -r branch; do
951+ info " Checking for test branches to delete..."
952+ while read -r branch; do
935953 if [[ -n " $branch " ]]; then
936- git push origin --delete " $branch " & > /dev/null || true
954+ if git push origin --delete " $branch " & > /dev/null; then
955+ info " Deleted branch: $branch "
956+ (( branches_deleted++ ))
957+ else
958+ warning " Failed to delete branch: $branch "
959+ fi
937960 fi
938- done
961+ done < <( git branch -r 2> /dev/null | grep ' origin/test-pr-\|origin/claude-test-branch\|origin/codex-test-branch ' | sed ' s/origin\/// ' || true )
939962
940- success " Cleanup completed"
963+ success " Cleanup completed: $issues_closed issues closed, $prs_closed PRs closed, $branches_deleted branches deleted "
941964}
942965
943966run_workflow_dispatch_tests () {
@@ -1260,6 +1283,7 @@ main() {
12601283 local run_issue_triggered=true
12611284 local run_command_triggered=true
12621285 local dry_run=false
1286+ local clean_resources=false
12631287 local specific_tests=()
12641288
12651289 while [[ $# -gt 0 ]]; do
@@ -1268,6 +1292,10 @@ main() {
12681292 dry_run=true
12691293 shift
12701294 ;;
1295+ --clean)
1296+ clean_resources=true
1297+ shift
1298+ ;;
12711299 --workflow-dispatch-only)
12721300 run_workflow_dispatch=true
12731301 run_issue_triggered=false
@@ -1291,6 +1319,7 @@ main() {
12911319 echo " "
12921320 echo " Options:"
12931321 echo " --dry-run, -n Show what would be tested without running"
1322+ echo " --clean Enable cleanup of test resources (default: false)"
12941323 echo " --workflow-dispatch-only Run only workflow dispatch tests"
12951324 echo " --issue-triggered-only Run only issue-triggered tests"
12961325 echo " --command-triggered-only Run only command-triggered tests"
@@ -1378,8 +1407,11 @@ main() {
13781407
13791408 if [[ " $dry_run " == true ]]; then
13801409 info " Dry run mode - skipping cleanup of test resources"
1381- else
1410+ elif [[ " $clean_resources " == true ]]; then
1411+ info " Cleanup enabled - running cleanup of test resources"
13821412 cleanup_test_resources
1413+ else
1414+ info " Cleanup disabled - skipping cleanup of test resources (use --clean to enable)"
13831415 fi
13841416
13851417 # If specific tests are provided, determine which test suites need to run
0 commit comments