Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
122 changes: 122 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
33 changes: 0 additions & 33 deletions e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -913,33 +913,6 @@ wait_for_pr_reviews() {
return 1
}

cleanup_test_resources() {
info "Cleaning up test resources..."

# Close all issues
gh issue list --limit 20 --json number --jq '.[].number' | 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
fi
done

# Close all PRs
gh pr list --limit 20 --json number --jq '.[].number' | 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
fi
done

# 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
if [[ -n "$branch" ]]; then
git push origin --delete "$branch" &>/dev/null || true
fi
done

success "Cleanup completed"
}

run_workflow_dispatch_tests() {
local patterns=("$@")
info "🚀 Running workflow_dispatch tests..."
Expand Down Expand Up @@ -1375,12 +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"
else
cleanup_test_resources
fi

# If specific tests are provided, determine which test suites need to run
if [[ ${#specific_tests[@]} -gt 0 ]]; then
Expand Down
Loading