|
| 1 | +# Module 2: GitHub Actions Integration |
| 2 | + |
| 3 | +This module extends the PR Agent with GitHub Actions webhook integration and MCP Prompts for standardized CI/CD workflows. |
| 4 | + |
| 5 | +## Features Added in Module 2 |
| 6 | + |
| 7 | +1. **GitHub Actions Tools**: |
| 8 | + - `get_recent_actions_events()` - View recent webhook events |
| 9 | + - `get_workflow_status()` - Check workflow statuses |
| 10 | + |
| 11 | +2. **MCP Prompts for CI/CD**: |
| 12 | + - `analyze_ci_results` - Comprehensive CI/CD analysis |
| 13 | + - `create_deployment_summary` - Team-friendly deployment updates |
| 14 | + - `generate_pr_status_report` - Combined code and CI/CD report |
| 15 | + - `troubleshoot_workflow_failure` - Systematic debugging guide |
| 16 | + |
| 17 | +3. **Webhook Server**: |
| 18 | + - Separate script that runs on port 8080 |
| 19 | + - Receives GitHub Actions events |
| 20 | + - Stores events in `github_events.json` for the MCP server to read |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +```bash |
| 25 | +# From the solution directory |
| 26 | +uv sync |
| 27 | +``` |
| 28 | + |
| 29 | +## Setting Up Cloudflare Tunnel |
| 30 | + |
| 31 | +To receive GitHub webhooks locally, you'll need to set up Cloudflare Tunnel (cloudflared): |
| 32 | + |
| 33 | +### Step 1: Install cloudflared |
| 34 | + |
| 35 | +**macOS:** |
| 36 | +```bash |
| 37 | +brew install cloudflared |
| 38 | +``` |
| 39 | + |
| 40 | +**Windows:** |
| 41 | +Download the Windows installer from: |
| 42 | +https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.msi |
| 43 | + |
| 44 | +**Linux:** |
| 45 | +```bash |
| 46 | +# For Debian/Ubuntu (amd64) |
| 47 | +curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb |
| 48 | +sudo dpkg -i cloudflared.deb |
| 49 | + |
| 50 | +# For other Linux distros, download the appropriate binary: |
| 51 | +# https://github.com/cloudflare/cloudflared/releases/latest |
| 52 | +``` |
| 53 | + |
| 54 | +### Step 2: Start the Tunnel |
| 55 | + |
| 56 | +```bash |
| 57 | +# This creates a public URL that forwards to your local webhook server |
| 58 | +cloudflared tunnel --url http://localhost:8080 |
| 59 | +``` |
| 60 | + |
| 61 | +You'll see output like: |
| 62 | +``` |
| 63 | +Your quick tunnel has been created! Visit it at: |
| 64 | +https://random-name-here.trycloudflare.com |
| 65 | +``` |
| 66 | + |
| 67 | +### Step 3: Configure GitHub Webhook |
| 68 | + |
| 69 | +1. Go to your GitHub repository → Settings → Webhooks |
| 70 | +2. Click "Add webhook" |
| 71 | +3. Set **Payload URL** to: `https://your-tunnel-url.trycloudflare.com/webhook/github` |
| 72 | +4. Set **Content type** to: `application/json` |
| 73 | +5. Select events: |
| 74 | + - Workflow runs |
| 75 | + - Check runs |
| 76 | + - Or choose "Send me everything" |
| 77 | +6. Click "Add webhook" |
| 78 | + |
| 79 | +## Running the Server |
| 80 | + |
| 81 | +### For Development |
| 82 | + |
| 83 | +```bash |
| 84 | +# Terminal 1: Start the webhook server |
| 85 | +python webhook_server.py |
| 86 | + |
| 87 | +# Terminal 2: Start Cloudflare Tunnel (if testing with real GitHub) |
| 88 | +cloudflared tunnel --url http://localhost:8080 |
| 89 | + |
| 90 | +# Terminal 3: Start the MCP server |
| 91 | +uv run server.py |
| 92 | +``` |
| 93 | + |
| 94 | +### With Claude Code |
| 95 | + |
| 96 | +1. Add to Claude Code settings: |
| 97 | +```json |
| 98 | +{ |
| 99 | + "pr-agent-actions": { |
| 100 | + "command": "uv", |
| 101 | + "args": ["run", "server.py"], |
| 102 | + "cwd": "/path/to/github-actions-integration/solution" |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +2. Restart Claude Code |
| 108 | +3. In a separate terminal, start the webhook server: `python webhook_server.py` |
| 109 | +4. (Optional) Start Cloudflare Tunnel if testing with real GitHub webhooks |
| 110 | + |
| 111 | +## Testing Webhooks |
| 112 | + |
| 113 | +### Manual Test |
| 114 | +```bash |
| 115 | +# Send a test webhook |
| 116 | +curl -X POST http://localhost:8080/webhook/github \ |
| 117 | + -H "Content-Type: application/json" \ |
| 118 | + -H "X-GitHub-Event: workflow_run" \ |
| 119 | + -d '{ |
| 120 | + "action": "completed", |
| 121 | + "workflow_run": { |
| 122 | + "id": 123456789, |
| 123 | + "name": "CI Tests", |
| 124 | + "head_branch": "main", |
| 125 | + "run_number": 42, |
| 126 | + "status": "completed", |
| 127 | + "conclusion": "success", |
| 128 | + "html_url": "https://github.com/user/repo/actions/runs/123456789", |
| 129 | + "updated_at": "2024-01-01T10:00:00Z" |
| 130 | + }, |
| 131 | + "repository": { |
| 132 | + "full_name": "user/repo" |
| 133 | + }, |
| 134 | + "sender": { |
| 135 | + "login": "test-user" |
| 136 | + } |
| 137 | + }' |
| 138 | +``` |
| 139 | + |
| 140 | +### With Claude Code |
| 141 | + |
| 142 | +After setting up webhooks and pushing a commit: |
| 143 | + |
| 144 | +1. **Check recent events**: |
| 145 | + - Ask: "What GitHub Actions events have we received?" |
| 146 | + - Claude will use `get_recent_actions_events()` |
| 147 | + |
| 148 | +2. **Analyze CI status**: |
| 149 | + - Use the prompt: "Analyze CI Results" |
| 150 | + - Claude will check workflows and provide insights |
| 151 | + |
| 152 | +3. **Create deployment summary**: |
| 153 | + - Use the prompt: "Create Deployment Summary" |
| 154 | + - Claude will format a team-friendly update |
| 155 | + |
| 156 | +## Module Structure |
| 157 | + |
| 158 | +- `server.py` - Main MCP server with Tools and Prompts |
| 159 | +- `webhook_server.py` - Separate webhook server that stores events |
| 160 | +- `github_events.json` - File where webhook events are stored (created automatically) |
| 161 | +- `pyproject.toml` - Dependencies for both servers |
| 162 | +- `README.md` - This file |
| 163 | + |
| 164 | +## Next Steps |
| 165 | + |
| 166 | +- Complete the exercises in the module |
| 167 | +- Experiment with different prompt workflows |
| 168 | +- Move on to Module 3 for Hugging Face Hub integration |
0 commit comments