Skip to content

Commit eb55a4e

Browse files
Daily Repo Goal Achiever: Add CI Coach workflow (#172)
1 parent 044933f commit eb55a4e

3 files changed

Lines changed: 543 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A sample family of reusable [GitHub Agentic Workflows](https://github.github.com
1111
## Fault Analysis Workflows
1212

1313
- [🏥 CI Doctor](docs/ci-doctor.md) - Monitor CI workflows and investigate failures automatically
14+
- [🚀 CI Coach](docs/ci-coach.md) - Optimize CI workflows for speed and cost efficiency
1415

1516
## Code Review Workflows
1617

docs/ci-coach.md

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
# 🚀 CI Coach
2+
3+
**Automated CI/CD optimization expert that analyzes your GitHub Actions workflows and proposes efficiency improvements**
4+
5+
## What It Does
6+
7+
CI Coach is your personal CI/CD optimization consultant. It runs daily to:
8+
9+
1. **Analyzes all GitHub Actions workflows** in your repository
10+
2. **Collects performance metrics** from recent workflow runs
11+
3. **Identifies optimization opportunities** using proven patterns
12+
4. **Proposes concrete improvements** through pull requests
13+
5. **Estimates time and cost savings** for each optimization
14+
15+
Think of it as a tireless performance engineer who reviews your CI pipelines every day, looking for ways to make them faster and cheaper.
16+
17+
## Why It's Valuable
18+
19+
### Universal Problem, Universal Solution
20+
21+
Every repository with GitHub Actions can benefit from CI optimization:
22+
23+
- **Faster feedback loops** → Developers get test results sooner
24+
- **Lower costs** → Reduced GitHub Actions minutes consumption
25+
- **Better resource utilization** → Optimal use of runner resources
26+
- **Improved developer experience** → Less time waiting for CI
27+
28+
### Proven Track Record
29+
30+
From Peli's Agent Factory:
31+
> "CI Optimization Coach has contributed **9 merged PRs out of 9 proposed (100% merge rate)**, optimizing CI pipelines for speed and efficiency with perfect execution."
32+
33+
Examples of improvements made:
34+
- [Removing unnecessary test dependencies](https://github.com/github/gh-aw/pull/13925)
35+
- [Fixing duplicate test execution](https://github.com/github/gh-aw/pull/8176)
36+
37+
## How It Works
38+
39+
### Daily Analysis Cycle
40+
41+
````mermaid
42+
graph LR
43+
A[Find Workflows] --> B[Collect Metrics]
44+
B --> C[Analyze Performance]
45+
C --> D{Improvements<br/>Found?}
46+
D -->|Yes| E[Create PR]
47+
D -->|No| F[Report: All Good]
48+
````
49+
50+
### What It Analyzes
51+
52+
1. **Job Parallelization**
53+
- Are independent jobs running in parallel?
54+
- Can the critical path be shortened?
55+
- Are matrix jobs balanced?
56+
57+
2. **Caching Strategy**
58+
- Are dependencies cached effectively?
59+
- What's the cache hit rate?
60+
- Can cache keys be optimized?
61+
62+
3. **Test Distribution**
63+
- Is test execution balanced?
64+
- Can tests run in parallel?
65+
- Are slow tests identified?
66+
67+
4. **Resource Allocation**
68+
- Are timeouts appropriate?
69+
- Are runner types optimal?
70+
- Are jobs sized correctly?
71+
72+
5. **Artifact Management**
73+
- Are artifacts necessary?
74+
- Can sizes be reduced?
75+
- Are retention periods optimal?
76+
77+
6. **Conditional Execution**
78+
- Can jobs skip when not needed?
79+
- Are path filters used effectively?
80+
81+
### Sample Optimizations
82+
83+
**Before: Sequential Execution**
84+
```yaml
85+
test:
86+
needs: [build]
87+
runs-on: ubuntu-latest
88+
89+
lint:
90+
needs: [test] # Waits for test to finish
91+
runs-on: ubuntu-latest
92+
```
93+
94+
**After: Parallel Execution**
95+
```yaml
96+
test:
97+
needs: [build]
98+
runs-on: ubuntu-latest
99+
100+
lint:
101+
needs: [build] # Runs in parallel with test
102+
runs-on: ubuntu-latest
103+
```
104+
105+
**Impact**: 5 minutes saved per run (if lint takes 5 minutes)
106+
107+
## What You Get
108+
109+
### Pull Requests with Clear Value
110+
111+
Each PR includes:
112+
113+
- **Summary** of what's being optimized
114+
- **Detailed analysis** with metrics and data
115+
- **Expected impact** (time savings, cost reduction)
116+
- **Risk assessment** (low/medium/high)
117+
- **Testing recommendations**
118+
119+
### Evidence-Based Recommendations
120+
121+
All suggestions are backed by:
122+
- Actual workflow run data
123+
- Performance metrics
124+
- Before/after comparisons
125+
- Cost/benefit analysis
126+
127+
### Safe, Surgical Changes
128+
129+
CI Coach follows strict quality standards:
130+
- ✅ Minimal, focused changes
131+
- ✅ Low-risk optimizations prioritized
132+
- ✅ Clear documentation
133+
- ✅ Easy to review and rollback
134+
- ❌ Never breaks test integrity
135+
- ❌ Never sacrifices correctness for speed
136+
137+
## Configuration
138+
139+
### Basic Setup
140+
141+
The workflow runs daily by default:
142+
143+
```yaml
144+
on:
145+
schedule:
146+
- cron: daily
147+
```
148+
149+
### Customization
150+
151+
You can customize the behavior by editing the workflow file:
152+
153+
1. **Change schedule**: Modify the `cron` expression
154+
2. **Adjust timeout**: Change `timeout-minutes` if analysis takes longer
155+
3. **Modify PR expiration**: Adjust `expires` in safe-outputs
156+
157+
### Manual Trigger
158+
159+
You can also trigger the analysis manually:
160+
161+
```bash
162+
gh workflow run ci-coach.md
163+
```
164+
165+
## Use Cases
166+
167+
### 1. Growing Repositories
168+
169+
As your codebase grows, CI times naturally increase. CI Coach continuously monitors and optimizes to keep pipelines fast.
170+
171+
**Example**: Split monolithic test job into parallel matrix jobs as test count grows.
172+
173+
### 2. Cost-Conscious Teams
174+
175+
GitHub Actions minutes cost money. CI Coach finds opportunities to reduce runtime and save costs.
176+
177+
**Example**: Add dependency caching to eliminate repeated downloads (5-10 minute savings per run).
178+
179+
### 3. Fast-Moving Teams
180+
181+
Frequent commits mean CI runs constantly. Every minute saved multiplies across hundreds of runs.
182+
183+
**Example**: Enable parallel job execution to reduce critical path by 40%.
184+
185+
### 4. Multi-Language Projects
186+
187+
Different languages have different CI optimization patterns. CI Coach learns from your specific setup.
188+
189+
**Example**: Optimize build caching for npm, pip, and maven in the same repository.
190+
191+
## What It Won't Do
192+
193+
### Maintains Quality
194+
195+
CI Coach has strict rules to protect test integrity:
196+
197+
- ❌ Never modifies test code to hide failures
198+
- ❌ Never suppresses error output
199+
- ❌ Never makes failing tests appear to pass
200+
- ❌ Never sacrifices correctness for speed
201+
202+
### Respects Your Decisions
203+
204+
CI Coach is advisory only:
205+
206+
- It **proposes** optimizations via PR
207+
- You **review and approve** before merging
208+
- All changes are **documented and reversible**
209+
- You remain **in full control**
210+
211+
### Focuses on High-Value Work
212+
213+
CI Coach won't create noise:
214+
215+
- Only proposes changes with significant impact (>2% improvement)
216+
- Skips if no meaningful optimizations found
217+
- Prioritizes low-risk, high-value changes
218+
- Creates at most one PR per run
219+
220+
## Real-World Impact
221+
222+
### Time Savings Example
223+
224+
A typical repository might see:
225+
- **5-10 minutes** per CI run saved
226+
- **50+ runs** per month
227+
- **250-500 minutes** saved monthly
228+
- **~8 hours** of developer waiting time eliminated
229+
230+
### Cost Savings Example
231+
232+
For a repository running CI 200 times/month:
233+
- **Before**: 15 minutes/run = 3,000 minutes/month
234+
- **After**: 10 minutes/run = 2,000 minutes/month
235+
- **Savings**: 1,000 minutes/month
236+
237+
At GitHub Actions pricing, this saves real money while improving developer experience.
238+
239+
## Getting Started
240+
241+
1. **Add the workflow** to your repository (already done if you're reading this!)
242+
243+
2. **Wait for the first run** (runs daily automatically)
244+
245+
3. **Review any PRs** created by CI Coach
246+
247+
4. **Merge if beneficial**, or close with feedback
248+
249+
5. **Monitor impact** by comparing workflow run times before/after
250+
251+
## Tips for Best Results
252+
253+
### Provide Context
254+
255+
If CI Coach suggests something that doesn't fit your use case, close the PR with a comment explaining why. The agent learns from feedback.
256+
257+
### Review Thoroughly
258+
259+
While CI Coach has a perfect merge rate in its home repository, every repo is different. Always review proposed changes carefully.
260+
261+
### Start Small
262+
263+
Merge one optimization at a time, monitor the impact, then proceed with the next one.
264+
265+
### Share Feedback
266+
267+
If CI Coach misses an optimization opportunity or suggests something inappropriate, that's valuable feedback for improving the system.
268+
269+
## Comparison to Other Approaches
270+
271+
### vs. Manual Optimization
272+
273+
- **Manual**: Requires dedicated time, easily forgotten
274+
- **CI Coach**: Continuous monitoring, never forgets
275+
276+
### vs. Third-Party CI Tools
277+
278+
- **Third-party**: Additional service, data leaves GitHub
279+
- **CI Coach**: Native GitHub Actions, all data stays in your repo
280+
281+
### vs. Static Analysis
282+
283+
- **Static**: One-time snapshot
284+
- **CI Coach**: Adapts as your repository evolves
285+
286+
## Troubleshooting
287+
288+
### No PRs Created
289+
290+
This is normal! It means your CI is already well-optimized. CI Coach only creates PRs when it finds significant improvements.
291+
292+
### PR Suggests Unwanted Change
293+
294+
Close the PR with a comment explaining why the change isn't appropriate. This helps document your CI design decisions.
295+
296+
### Analysis Timeout
297+
298+
If the workflow times out, increase `timeout-minutes` in the workflow configuration.
299+
300+
## Learn More
301+
302+
- [CI Coach source workflow](https://github.com/github/gh-aw/blob/main/.github/workflows/ci-coach.md)
303+
- [GitHub Actions best practices](https://docs.github.com/en/actions/learn-github-actions/best-practices-for-github-actions)
304+
- [Optimizing GitHub Actions workflows](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows)
305+
306+
---
307+
308+
**Remember**: CI Coach is your optimization consultant, not a mandate. Review its suggestions, merge what makes sense, and enjoy faster, cheaper CI pipelines!

0 commit comments

Comments
 (0)