Created
November 6, 2025 03:19
-
-
Save lukemurraynz/5f7280cf158cec0d403a605b81a3e515 to your computer and use it in GitHub Desktop.
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: Weekly Cleanup Specialist | |
| on: | |
| schedule: | |
| # Runs every Monday at 9:00 AM UTC | |
| - cron: '0 9 * * 1' | |
| workflow_dispatch: # Allows manual triggering | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| run-cleanup-specialist: | |
| runs-on: ubuntu-latest | |
| name: Run Cleanup Specialist Agent | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Install GitHub Copilot CLI | |
| run: | | |
| npm install -g @github/copilot | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Run Cleanup Specialist Analysis | |
| run: | | |
| echo "==========================================" | |
| echo "Starting Cleanup Specialist Analysis" | |
| echo "==========================================" | |
| echo "" | |
| echo "Repository: ${{ github.repository }}" | |
| echo "Branch: ${{ github.ref_name }}" | |
| echo "Timestamp: $(date -u +"%Y-%m-%d %H:%M:%S UTC")" | |
| echo "" | |
| # Read the agent prompt | |
| echo "Reading agent prompt from .github/agents/cleanup-specialist.agent.md..." | |
| AGENT_PROMPT=$(cat .github/agents/cleanup-specialist.agent.md) | |
| echo "✓ Agent prompt loaded successfully" | |
| echo "" | |
| # Prepare the execution context | |
| echo "Preparing execution context..." | |
| ANALYSIS_PROMPT="$AGENT_PROMPT | |
| Repository: ${{ github.repository }} | |
| Branch: ${{ github.ref_name }} | |
| Please analyze this repository following the guidelines above. You have access to the GitHub MCP server to create/update issues. | |
| Repository structure (sample): | |
| $(find . -maxdepth 3 -type f -not -path '*/\.*' -not -path '*/node_modules/*' | head -50) | |
| Use the github-mcp-server tools to: | |
| 1. Check for existing open issues with label 'cleanup-specialist' | |
| 2. If found, add a comment with new findings | |
| 3. If not found, create a new issue with your analysis | |
| " | |
| echo "✓ Execution context prepared" | |
| echo "" | |
| # Run the agent with GitHub Copilot CLI in programmatic mode | |
| echo "==========================================" | |
| echo "Executing GitHub Copilot CLI Agent" | |
| echo "==========================================" | |
| echo "Command: copilot --prompt <ANALYSIS_PROMPT> --allow-all-tools" | |
| echo "" | |
| # Create a temporary file for output | |
| OUTPUT_FILE=$(mktemp) | |
| # Ensure cleanup happens even if script fails | |
| trap 'rm -f "$OUTPUT_FILE"' EXIT | |
| # Using --allow-all-tools for non-interactive execution | |
| # Capture exit code without failing the script | |
| EXIT_CODE=0 | |
| copilot --prompt "$ANALYSIS_PROMPT" --allow-all-tools > "$OUTPUT_FILE" 2>&1 || EXIT_CODE=$? | |
| echo "" | |
| echo "==========================================" | |
| echo "Copilot CLI Execution Completed" | |
| echo "==========================================" | |
| echo "Exit Code: $EXIT_CODE" | |
| echo "" | |
| # Display the output | |
| echo "Agent Output:" | |
| echo "----------------------------------------" | |
| cat "$OUTPUT_FILE" | |
| echo "----------------------------------------" | |
| echo "" | |
| # Provide detailed status based on exit code | |
| if [ $EXIT_CODE -eq 0 ]; then | |
| echo "✓ SUCCESS: The Cleanup Specialist agent completed successfully." | |
| echo " The agent should have created or updated a GitHub issue with findings." | |
| echo " Check the output above for details on what actions were taken." | |
| else | |
| echo "⚠ WARNING: The Cleanup Specialist agent exited with code $EXIT_CODE." | |
| echo " This may indicate:" | |
| echo " - The agent encountered an error during execution" | |
| echo " - No cleanup opportunities were found (some agents exit with non-zero on no findings)" | |
| echo " - There was an issue communicating with GitHub API" | |
| echo "" | |
| echo " Please review the agent output above for more details." | |
| echo " If an issue was created/updated, the agent still may have completed its work successfully." | |
| # Fail the workflow if copilot CLI exits with an error | |
| exit $EXIT_CODE | |
| fi | |
| echo "" | |
| echo "==========================================" | |
| echo "Analysis Complete" | |
| echo "==========================================" | |
| env: | |
| COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }} | |
| GH_TOKEN: ${{ github.token }} | |
| GITHUB_TOKEN: ${{ github.token }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment