From 14677ab150fa0b2f1eeb9fe1731093a0b11f8347 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Sep 2025 09:54:59 +0000 Subject: [PATCH 1/3] Initial plan From 0d7f49b48fbe1dbb52bda8b0d4632c07ad16b18f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Sep 2025 10:00:12 +0000 Subject: [PATCH 2/3] Add --clean flag for optional test resource cleanup Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- e2e.sh | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/e2e.sh b/e2e.sh index aafaa432..0ba57d4d 100755 --- a/e2e.sh +++ b/e2e.sh @@ -22,11 +22,13 @@ # # Options: # --dry-run Show what would be tested without running +# --clean Enable cleanup of test resources (default: false) # --help, -h Show help message # # Examples: # ./e2e.sh # Run all tests # ./e2e.sh --dry-run # See what would be tested +# ./e2e.sh --clean # Run tests and clean up resources # # Prerequisites: # - GitHub CLI (gh) installed and authenticated @@ -915,29 +917,50 @@ wait_for_pr_reviews() { cleanup_test_resources() { info "Cleaning up test resources..." + local issues_closed=0 + local prs_closed=0 + local branches_deleted=0 # Close all issues - gh issue list --limit 20 --json number --jq '.[].number' | while read -r issue_num; do + info "Checking for open issues to close..." + while read -r issue_num; do if [[ -n "$issue_num" ]]; then - gh issue close "$issue_num" --comment "Closed by e2e test cleanup" &>/dev/null || true + if gh issue close "$issue_num" --comment "Closed by e2e test cleanup" &>/dev/null; then + info "Closed issue #$issue_num" + ((issues_closed++)) + else + warning "Failed to close issue #$issue_num" + fi fi - done + done < <(gh issue list --limit 20 --json number --jq '.[].number' 2>/dev/null || true) # Close all PRs - gh pr list --limit 20 --json number --jq '.[].number' | while read -r pr_num; do + info "Checking for open pull requests to close..." + while read -r pr_num; do if [[ -n "$pr_num" ]]; then - gh pr close "$pr_num" --comment "Closed by e2e test cleanup" &>/dev/null || true + if gh pr close "$pr_num" --comment "Closed by e2e test cleanup" &>/dev/null; then + info "Closed pull request #$pr_num" + ((prs_closed++)) + else + warning "Failed to close pull request #$pr_num" + fi fi - done + done < <(gh pr list --limit 20 --json number --jq '.[].number' 2>/dev/null || true) # Delete test branches - git branch -r | grep 'origin/test-pr-\|origin/claude-test-branch\|origin/codex-test-branch' | sed 's/origin\///' | while read -r branch; do + info "Checking for test branches to delete..." + while read -r branch; do if [[ -n "$branch" ]]; then - git push origin --delete "$branch" &>/dev/null || true + if git push origin --delete "$branch" &>/dev/null; then + info "Deleted branch: $branch" + ((branches_deleted++)) + else + warning "Failed to delete branch: $branch" + fi fi - done + done < <(git branch -r 2>/dev/null | grep 'origin/test-pr-\|origin/claude-test-branch\|origin/codex-test-branch' | sed 's/origin\///' || true) - success "Cleanup completed" + success "Cleanup completed: $issues_closed issues closed, $prs_closed PRs closed, $branches_deleted branches deleted" } run_workflow_dispatch_tests() { @@ -1260,6 +1283,7 @@ main() { local run_issue_triggered=true local run_command_triggered=true local dry_run=false + local clean_resources=false local specific_tests=() while [[ $# -gt 0 ]]; do @@ -1268,6 +1292,10 @@ main() { dry_run=true shift ;; + --clean) + clean_resources=true + shift + ;; --workflow-dispatch-only) run_workflow_dispatch=true run_issue_triggered=false @@ -1291,6 +1319,7 @@ main() { echo "" echo "Options:" echo " --dry-run, -n Show what would be tested without running" + echo " --clean Enable cleanup of test resources (default: false)" echo " --workflow-dispatch-only Run only workflow dispatch tests" echo " --issue-triggered-only Run only issue-triggered tests" echo " --command-triggered-only Run only command-triggered tests" @@ -1378,8 +1407,11 @@ main() { if [[ "$dry_run" == true ]]; then info "Dry run mode - skipping cleanup of test resources" - else + elif [[ "$clean_resources" == true ]]; then + info "Cleanup enabled - running cleanup of test resources" cleanup_test_resources + else + info "Cleanup disabled - skipping cleanup of test resources (use --clean to enable)" fi # If specific tests are provided, determine which test suites need to run From 46bb9656fd5e62f10be149af3ecd24b570344c34 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Sep 2025 10:11:01 +0000 Subject: [PATCH 3/3] Refactor cleanup to separate clean.sh script and add clean job to e2e.yml Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/e2e.yml | 25 ++++++++ clean.sh | 122 ++++++++++++++++++++++++++++++++++++++ e2e.sh | 65 -------------------- 3 files changed, 147 insertions(+), 65 deletions(-) create mode 100755 clean.sh diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index b4d76e5c..809097d9 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -15,8 +15,33 @@ permissions: actions: write jobs: + clean: + runs-on: ubuntu-latest + name: "Clean test resources" + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: GitHub CLI - show auth status + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh auth status + - name: Run cleanup script + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + chmod +x ./clean.sh + ./clean.sh + - name: Upload cleanup log artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: cleanup-log + path: cleanup-*.log + e2e: runs-on: ubuntu-latest + needs: clean strategy: matrix: test-suite: diff --git a/clean.sh b/clean.sh new file mode 100755 index 00000000..f255068a --- /dev/null +++ b/clean.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +# Cleanup script for GitHub Agentic Workflows test resources +# This script cleans up test resources (issues, PRs, branches) created during e2e testing +# +# Usage: ./clean.sh +# +# This script will: +# 1. Close all open issues with cleanup comment +# 2. Close all open pull requests with cleanup comment +# 3. Delete test branches matching specific patterns +# 4. Provide detailed logging of all cleanup operations + +set -uo pipefail + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +PURPLE='\033[0;35m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +# Configuration +LOG_FILE="cleanup-$(date +%Y%m%d-%H%M%S).log" + +# Utility functions +log() { + echo "$(date '+%Y-%m-%d %H:%M:%S') $*" | tee -a "$LOG_FILE" +} + +info() { + echo -e "${BLUE}ℹ️ $*${NC}" | tee -a "$LOG_FILE" +} + +success() { + echo -e "${GREEN}✅ $*${NC}" | tee -a "$LOG_FILE" +} + +warning() { + echo -e "${YELLOW}⚠️ $*${NC}" | tee -a "$LOG_FILE" +} + +error() { + echo -e "${RED}❌ $*${NC}" | tee -a "$LOG_FILE" +} + +cleanup_test_resources() { + info "Cleaning up test resources..." + local issues_closed=0 + local prs_closed=0 + local branches_deleted=0 + + # Close all issues + info "Checking for open issues to close..." + while read -r issue_num; do + if [[ -n "$issue_num" ]]; then + if gh issue close "$issue_num" --comment "Closed by e2e test cleanup" &>/dev/null; then + info "Closed issue #$issue_num" + ((issues_closed++)) + else + warning "Failed to close issue #$issue_num" + fi + fi + done < <(gh issue list --limit 20 --json number --jq '.[].number' 2>/dev/null || true) + + # Close all PRs + info "Checking for open pull requests to close..." + while read -r pr_num; do + if [[ -n "$pr_num" ]]; then + if gh pr close "$pr_num" --comment "Closed by e2e test cleanup" &>/dev/null; then + info "Closed pull request #$pr_num" + ((prs_closed++)) + else + warning "Failed to close pull request #$pr_num" + fi + fi + done < <(gh pr list --limit 20 --json number --jq '.[].number' 2>/dev/null || true) + + # Delete test branches + info "Checking for test branches to delete..." + while read -r branch; do + if [[ -n "$branch" ]]; then + if git push origin --delete "$branch" &>/dev/null; then + info "Deleted branch: $branch" + ((branches_deleted++)) + else + warning "Failed to delete branch: $branch" + fi + fi + done < <(git branch -r 2>/dev/null | grep 'origin/test-pr-\|origin/claude-test-branch\|origin/codex-test-branch' | sed 's/origin\///' || true) + + success "Cleanup completed: $issues_closed issues closed, $prs_closed PRs closed, $branches_deleted branches deleted" +} + +main() { + echo -e "${CYAN}🧹 GitHub Agentic Workflows Test Resource Cleanup${NC}" + echo -e "${CYAN}==================================================${NC}" + echo + + log "Starting cleanup at $(date)" + + # Check if gh CLI is available and authenticated + if ! command -v gh &> /dev/null; then + error "GitHub CLI (gh) is not installed" + exit 1 + fi + + if ! gh auth status &> /dev/null; then + error "GitHub CLI is not authenticated. Run 'gh auth login'" + exit 1 + fi + + cleanup_test_resources + + echo + echo -e "${CYAN}📄 Log file: $LOG_FILE${NC}" +} + +# Run main function +main "$@" \ No newline at end of file diff --git a/e2e.sh b/e2e.sh index 0ba57d4d..8339b5b3 100755 --- a/e2e.sh +++ b/e2e.sh @@ -22,13 +22,11 @@ # # Options: # --dry-run Show what would be tested without running -# --clean Enable cleanup of test resources (default: false) # --help, -h Show help message # # Examples: # ./e2e.sh # Run all tests # ./e2e.sh --dry-run # See what would be tested -# ./e2e.sh --clean # Run tests and clean up resources # # Prerequisites: # - GitHub CLI (gh) installed and authenticated @@ -915,54 +913,6 @@ wait_for_pr_reviews() { return 1 } -cleanup_test_resources() { - info "Cleaning up test resources..." - local issues_closed=0 - local prs_closed=0 - local branches_deleted=0 - - # Close all issues - info "Checking for open issues to close..." - while read -r issue_num; do - if [[ -n "$issue_num" ]]; then - if gh issue close "$issue_num" --comment "Closed by e2e test cleanup" &>/dev/null; then - info "Closed issue #$issue_num" - ((issues_closed++)) - else - warning "Failed to close issue #$issue_num" - fi - fi - done < <(gh issue list --limit 20 --json number --jq '.[].number' 2>/dev/null || true) - - # Close all PRs - info "Checking for open pull requests to close..." - while read -r pr_num; do - if [[ -n "$pr_num" ]]; then - if gh pr close "$pr_num" --comment "Closed by e2e test cleanup" &>/dev/null; then - info "Closed pull request #$pr_num" - ((prs_closed++)) - else - warning "Failed to close pull request #$pr_num" - fi - fi - done < <(gh pr list --limit 20 --json number --jq '.[].number' 2>/dev/null || true) - - # Delete test branches - info "Checking for test branches to delete..." - while read -r branch; do - if [[ -n "$branch" ]]; then - if git push origin --delete "$branch" &>/dev/null; then - info "Deleted branch: $branch" - ((branches_deleted++)) - else - warning "Failed to delete branch: $branch" - fi - fi - done < <(git branch -r 2>/dev/null | grep 'origin/test-pr-\|origin/claude-test-branch\|origin/codex-test-branch' | sed 's/origin\///' || true) - - success "Cleanup completed: $issues_closed issues closed, $prs_closed PRs closed, $branches_deleted branches deleted" -} - run_workflow_dispatch_tests() { local patterns=("$@") info "🚀 Running workflow_dispatch tests..." @@ -1283,7 +1233,6 @@ main() { local run_issue_triggered=true local run_command_triggered=true local dry_run=false - local clean_resources=false local specific_tests=() while [[ $# -gt 0 ]]; do @@ -1292,10 +1241,6 @@ main() { dry_run=true shift ;; - --clean) - clean_resources=true - shift - ;; --workflow-dispatch-only) run_workflow_dispatch=true run_issue_triggered=false @@ -1319,7 +1264,6 @@ main() { echo "" echo "Options:" echo " --dry-run, -n Show what would be tested without running" - echo " --clean Enable cleanup of test resources (default: false)" echo " --workflow-dispatch-only Run only workflow dispatch tests" echo " --issue-triggered-only Run only issue-triggered tests" echo " --command-triggered-only Run only command-triggered tests" @@ -1404,15 +1348,6 @@ main() { log "Starting e2e tests at $(date)" check_prerequisites - - if [[ "$dry_run" == true ]]; then - info "Dry run mode - skipping cleanup of test resources" - elif [[ "$clean_resources" == true ]]; then - info "Cleanup enabled - running cleanup of test resources" - cleanup_test_resources - else - info "Cleanup disabled - skipping cleanup of test resources (use --clean to enable)" - fi # If specific tests are provided, determine which test suites need to run if [[ ${#specific_tests[@]} -gt 0 ]]; then