Skip to content

Commit 3bbc35a

Browse files
committed
Add debug/
Signed-off-by: Aaron Wislang <[email protected]>
1 parent cc70567 commit 3bbc35a

File tree

2 files changed

+239
-0
lines changed

2 files changed

+239
-0
lines changed

debug/Justfile

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
set shell := ["bash", "-uc"]
2+
3+
# List available recipes
4+
list:
5+
just --list
6+
7+
# Get logs from the latest GitHub Actions workflow run
8+
get-latest-logs output="latest-run.log":
9+
#!/usr/bin/env bash
10+
set -euxo pipefail
11+
echo "Fetching latest workflow run..."
12+
13+
# Get the latest run ID
14+
RUN_ID=$(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')
15+
16+
if [ -z "$RUN_ID" ]; then
17+
echo "Error: No workflow runs found"
18+
exit 1
19+
fi
20+
21+
echo "Latest run ID: $RUN_ID"
22+
23+
# Get the logs and save to file
24+
gh run view "$RUN_ID" --log > "{{output}}"
25+
26+
echo "Logs saved to: {{output}}"
27+
echo "Run 'just analyze-logs' to get AI analysis of the failure"
28+
29+
# Get logs from a specific workflow run by ID
30+
get-logs run_id output="run.log":
31+
#!/usr/bin/env bash
32+
set -euxo pipefail
33+
echo "Fetching logs for run ID: {{run_id}}"
34+
gh run view {{run_id}} --log > "{{output}}"
35+
echo "Logs saved to: {{output}}"
36+
37+
# List recent workflow runs
38+
list-runs limit="10":
39+
#!/usr/bin/env bash
40+
set -euxo pipefail
41+
echo "Recent workflow runs:"
42+
gh run list --limit {{limit}} --json databaseId,status,conclusion,name,createdAt,displayTitle
43+
44+
# Get detailed status of the latest workflow run
45+
status-latest:
46+
#!/usr/bin/env bash
47+
set -euxo pipefail
48+
echo "Latest workflow run status:"
49+
gh run list --limit 1 --json databaseId,status,conclusion,name,createdAt,displayTitle,workflowName,event,headBranch
50+
echo ""
51+
echo "Jobs in latest run:"
52+
RUN_ID=$(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')
53+
gh run view "$RUN_ID"
54+
55+
# Get logs from the latest failed workflow run
56+
get-failed-logs output="failed-run.log":
57+
#!/usr/bin/env bash
58+
set -euxo pipefail
59+
echo "Fetching latest failed workflow run..."
60+
61+
# Get the latest failed run ID
62+
RUN_ID=$(gh run list --limit 50 --json databaseId,conclusion --jq '.[] | select(.conclusion=="failure") | .databaseId' | head -n 1)
63+
64+
if [ -z "$RUN_ID" ]; then
65+
echo "Error: No failed workflow runs found in the last 50 runs"
66+
exit 1
67+
fi
68+
69+
echo "Latest failed run ID: $RUN_ID"
70+
71+
# Get the logs and save to file
72+
gh run view "$RUN_ID" --log > "{{output}}"
73+
74+
echo "Logs saved to: {{output}}"
75+
echo "Run 'just analyze-logs {{output}}' to get AI analysis of the failure"
76+
77+
# Watch workflow runs in real-time
78+
watch:
79+
gh run watch
80+
81+
# Re-run the latest failed workflow
82+
rerun-failed:
83+
#!/usr/bin/env bash
84+
set -euxo pipefail
85+
RUN_ID=$(gh run list --limit 50 --json databaseId,conclusion --jq '.[] | select(.conclusion=="failure") | .databaseId' | head -n 1)
86+
if [ -z "$RUN_ID" ]; then
87+
echo "Error: No failed workflow runs found"
88+
exit 1
89+
fi
90+
echo "Re-running failed workflow: $RUN_ID"
91+
gh run rerun "$RUN_ID"
92+
93+
# Cancel the latest running workflow
94+
cancel-latest:
95+
#!/usr/bin/env bash
96+
set -euxo pipefail
97+
RUN_ID=$(gh run list --limit 1 --json databaseId,status --jq '.[] | select(.status=="in_progress") | .databaseId' | head -n 1)
98+
if [ -z "$RUN_ID" ]; then
99+
echo "No running workflows found"
100+
exit 1
101+
fi
102+
echo "Cancelling workflow run: $RUN_ID"
103+
gh run cancel "$RUN_ID"

debug/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Debug Utilities
2+
3+
This directory contains utilities for debugging GitHub Actions workflows and other CI/CD issues.
4+
5+
## Prerequisites
6+
7+
- [GitHub CLI (`gh`)](https://cli.github.com/) - Already installed in the devcontainer
8+
- GitHub authentication configured (`gh auth login`)
9+
10+
## Available Commands
11+
12+
Run `just` to see all available recipes and their descriptions:
13+
14+
```bash
15+
cd debug
16+
just
17+
```
18+
19+
## Quick Start
20+
21+
### Get Logs from the Latest Workflow Run
22+
23+
```bash
24+
cd debug
25+
just get-latest-logs
26+
```
27+
28+
This will save the logs to `latest-run.log`.
29+
30+
### Get Logs from the Latest Failed Run
31+
32+
```bash
33+
just get-failed-logs
34+
```
35+
36+
This will find the most recent failed workflow run and save its logs to `failed-run.log`.
37+
38+
## Usage Examples
39+
40+
### Example 1: Debug the Latest Failure
41+
42+
```bash
43+
cd debug
44+
45+
# Get logs from the latest failed run
46+
just get-failed-logs
47+
48+
# Review the logs
49+
cat failed-run.log
50+
```
51+
52+
### Example 2: Check Recent Runs
53+
54+
```bash
55+
cd debug
56+
57+
# List the last 20 runs
58+
just list-runs 20
59+
60+
# Get detailed status of the latest run
61+
just status-latest
62+
```
63+
64+
### Example 3: Debug a Specific Run
65+
66+
```bash
67+
cd debug
68+
69+
# List runs to find the ID you want
70+
just list-runs
71+
72+
# Get logs for a specific run (e.g., run ID 12345678)
73+
just get-logs 12345678 my-debug.log
74+
```
75+
76+
### Example 4: Real-time Monitoring
77+
78+
```bash
79+
cd debug
80+
81+
# Watch workflows in real-time
82+
just watch
83+
84+
# In another terminal, if a run fails:
85+
just get-latest-logs
86+
```
87+
88+
### Example 5: Custom Output Location
89+
90+
```bash
91+
cd debug
92+
93+
# Save logs to a custom location
94+
just get-latest-logs output="../logs/workflow-$(date +%Y%m%d-%H%M%S).log"
95+
```
96+
97+
## Workflow
98+
99+
A typical debugging workflow:
100+
101+
1. **Check what failed:**
102+
```bash
103+
just list-runs
104+
```
105+
106+
2. **Get the logs:**
107+
```bash
108+
just get-failed-logs
109+
```
110+
111+
3. **Review and analyze the failure:**
112+
```bash
113+
cat failed-run.log
114+
# Or use your preferred AI tool to analyze the logs
115+
```
116+
117+
4. **Make fixes to your code**
118+
119+
5. **Re-run the workflow:**
120+
```bash
121+
just rerun-failed
122+
```
123+
124+
6. **Monitor the re-run:**
125+
```bash
126+
just watch
127+
```
128+
129+
## Tips
130+
131+
- Run `just` to see all available commands
132+
- Use `just list-runs` first to see the status of recent runs
133+
- The `get-failed-logs` recipe searches the last 50 runs for failures
134+
- Log files are saved in the current directory by default
135+
- You can specify custom output paths for any log-fetching recipe
136+
- Analyze log files with your preferred AI tool for debugging insights

0 commit comments

Comments
 (0)