| name | make-ci-green |
| description | Re-run failed GitHub Actions CI jobs for a PR. Detects failure type (build vs test) and reruns only failed jobs. Triggers on: make ci green, retry ci, rerun ci, fix ci, re-run failed jobs, retrigger ci. |
| argument-hint | <pr-number> [--dry-run] |
| allowed-tools | Bash, Read, Grep, Glob |
Make CI Green
Re-run failed GitHub Actions CI jobs for a PR. Automatically detects the failure
type and reruns only the failed jobs within a workflow run.
When to Use
- Flaky test failures on CI that just need a retry
- Build/infra failures that may recover on a clean re-run
- After pushing new commits to retrigger only the failing checks
- Batch retriggering when multiple workflow runs are failing
Prerequisites
gh CLI must be authenticated (gh auth status)
- The current directory must be inside the repository (or specify
--repo)
The Job
Step 1: Parse Arguments
Extract the PR number from the user's input. The PR number is required. Check
for --dry-run flag.
| User says | PR number |
|---|
/make-ci-green 482 | 482 |
| "retry ci for 482" | 482 |
| "make ci green on PR 482" | 482 |
| "re-run failed jobs 482 --dry-run" | 482 (dry run) |
Step 2: Detect Repository
Auto-detect the current repository from the git remote:
gh repo view --json nameWithOwner --jq '.nameWithOwner'
This gives you the OWNER/REPO needed for all subsequent commands.
Step 3: Get PR Branch and Failed Runs
Fetch the PR's head branch and find failed workflow runs:
PR_BRANCH=$(gh pr view <pr-number> --json headRefName --jq '.headRefName')
gh run list --branch "$PR_BRANCH" --status failure --json databaseId,name,conclusion,event,headBranch,createdAt --limit 20
Also check for runs still in progress:
gh run list --branch "$PR_BRANCH" --status in_progress --json databaseId,name,conclusion,event,headBranch,createdAt --limit 10
Step 4: Analyze Failures
For each failed run, get the job-level details to classify the failure:
gh run view <run-id> --json jobs --jq '.jobs[] | select(.conclusion == "failure") | {name, conclusion, steps: [.steps[] | select(.conclusion == "failure") | {name, conclusion}]}'
Classify each failure:
| Failed Step Pattern | Type | Rationale |
|---|
| checkout, setup, install, build, compile, configure, bootstrap, deps, cache | Build | Infrastructure/build failure |
| test, spec, check, lint, audit, storybook, e2e | Test | Test failure, likely flaky |
| Unknown | Unknown | Safe to retry |
Step matching is case-insensitive substring matching.
Step 5: Present Findings
Show the user what was found:
- Failed runs: run name, failed jobs, failed steps, failure type
- In-progress runs: listed for awareness
- No failures: report that CI is already green
Example output:
PR 482: 2 failed workflow run(s)
[FAILED] CI Tests (run 12345678)
Job: test-linux
Failed step: Run tests
Type: test failure (likely flaky)
[FAILED] Build (run 12345679)
Job: build-macos
Failed step: Compile project
Type: build failure
[IN PROGRESS] Lint (run 12345680)
Still running, skipping.
Step 6: Analyze Test Failures (for test-type failures)
For test failures, pull the logs to identify specific failing tests:
gh run view <run-id> --log-failed 2>/dev/null | tail -200
From the logs, try to extract:
- Specific test names that failed (look for common patterns:
FAILED,
FAIL:, Error in, AssertionError, etc.)
- Whether the failure looks flaky (timing-related, network-related,
intermittent keywords)
- Whether the failure could be PR-related (check if PR changes touch
files in the same area as the failing test)
Present per-test analysis to the user when available.
Step 7: Confirm and Trigger
If --dry-run, stop here after presenting findings.
Otherwise, ask the user to confirm, then rerun only the failed jobs:
gh run rerun <run-id> --failed
This reruns only the failed jobs within the run, not the entire workflow.
Report the results: which runs were retriggered, and provide links:
gh run view <run-id> --json url --jq '.url'
Failure Classification Summary
| Failed Step Keywords | Action | Rationale |
|---|
| checkout, setup, install, build, compile, configure, deps, cache, fetch | Rerun | Build/infra failure; retry may fix |
| test, spec, lint, audit, e2e, check | Rerun | Likely flaky; retry may pass |
| Unknown | Rerun | Safe default |
Usage Examples
/make-ci-green 482 --dry-run
/make-ci-green 482
"retry ci for PR 482"
"make ci green on 482"
Exit Behavior
- If no failed runs are found, report that CI is already green and stop.
- If
--dry-run, present analysis and stop without triggering anything.
- If runs are retriggered, report which ones and provide URLs.
Limitations
- Only handles GitHub Actions workflow runs
- Cannot retrigger third-party CI systems (e.g., external services reporting
status checks)
gh run rerun --failed requires the run to have completed (not in progress)
- Log analysis for test failures depends on output format varying by test
framework
- Does not auto-file issues for flaky tests (only suggests)