Cleanup Test Resources #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Cleanup Test Resources | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| delete_closed_issues: | |
| description: 'Also delete closed issues (requires admin access)' | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| cleanup: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Git | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Clean up test resources | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -e | |
| REPO="${{ github.repository }}" | |
| TEMPLATE_FILE="notes/2026/2026-01-13-transcript.template.md" | |
| TRANSCRIPT_FILE="notes/2026/2026-01-13-transcript.md" | |
| echo "Cleaning up test GitHub resources in $REPO..." | |
| echo "" | |
| # Close test issues | |
| echo "Closing test issues..." | |
| ISSUE_TITLES=( | |
| "Regression discussion" | |
| "Related context issue" | |
| "Bare reference test" | |
| ) | |
| for title in "${ISSUE_TITLES[@]}"; do | |
| echo " Looking for: $title" | |
| ISSUE_NUM=$(gh issue list --repo "$REPO" --search "\"$title\" in:title" --state open --json number --jq '.[0].number' 2>/dev/null || echo "") | |
| if [ -n "$ISSUE_NUM" ] && [ "$ISSUE_NUM" != "null" ]; then | |
| echo " Closing issue #$ISSUE_NUM..." | |
| gh issue close "$ISSUE_NUM" --repo "$REPO" --comment "Cleaning up test resources from transcript workflow testing." | |
| else | |
| echo " No matching open issue found" | |
| fi | |
| done | |
| # Close test PRs | |
| echo "" | |
| echo "Closing test PRs..." | |
| echo " Looking for: Test PR for transcript workflow" | |
| PR_NUM=$(gh pr list --repo "$REPO" --search "\"Test PR for transcript workflow\" in:title" --state open --json number --jq '.[0].number' 2>/dev/null || echo "") | |
| if [ -n "$PR_NUM" ] && [ "$PR_NUM" != "null" ]; then | |
| echo " Closing PR #$PR_NUM..." | |
| gh pr close "$PR_NUM" --repo "$REPO" --comment "Cleaning up test resources from transcript workflow testing." --delete-branch | |
| else | |
| echo " No matching open PR found" | |
| fi | |
| # Clean up test branches | |
| echo "" | |
| echo "Cleaning up test branches..." | |
| git fetch origin --prune | |
| # Clean up remote test branches | |
| TEST_BRANCHES=$(git branch -r | grep "origin/test-pr-" | sed 's/origin\///' || echo "") | |
| if [ -n "$TEST_BRANCHES" ]; then | |
| while IFS= read -r branch; do | |
| branch=$(echo "$branch" | xargs) | |
| if [ -n "$branch" ]; then | |
| echo " Deleting remote branch: $branch" | |
| git push origin --delete "$branch" 2>/dev/null || echo " Already deleted" | |
| fi | |
| done <<< "$TEST_BRANCHES" | |
| fi | |
| # Remove test file if it exists | |
| echo "" | |
| echo "Cleaning up test files..." | |
| if [ -f "test-file.md" ]; then | |
| echo " Removing test-file.md" | |
| git rm test-file.md 2>/dev/null || rm test-file.md | |
| if ! git diff --staged --quiet; then | |
| git commit -m "Clean up test file from transcript workflow testing [skip ci]" | |
| git push origin main | |
| fi | |
| fi | |
| # Restore transcript template | |
| echo "" | |
| echo "Restoring transcript to template..." | |
| if [ -f "$TEMPLATE_FILE" ]; then | |
| cp "$TEMPLATE_FILE" "$TRANSCRIPT_FILE" | |
| git add "$TRANSCRIPT_FILE" | |
| if ! git diff --staged --quiet; then | |
| git commit -m "Restore transcript template [skip ci]" | |
| git push origin main | |
| fi | |
| echo " Transcript restored with placeholders" | |
| else | |
| echo " Warning: Template file not found, transcript not restored" | |
| fi | |
| echo "" | |
| echo "✅ Cleanup complete!" | |
| echo "" | |
| echo "Transcript has been restored to template state." | |
| echo "Run the 'Setup Test Resources' workflow to recreate test resources." |