Commands/cicd
/cicd:optimize
CI/CD Pipeline Optimization
/cicd:optimize
Claude Code
Agent: devops-engineer Skills: cicd-automation
/cicd:optimize - CI/CD Pipeline Optimization
Analyze and optimize GitHub Actions workflows for speed and cost.
Usage
/cicd:optimize [workflow]
/cicd:optimize - Analyze all workflows
/cicd:optimize ci.yml - Optimize specific workflow
/cicd:optimize --report - Generate detailed report onlyExecution Steps
1. Gather Metrics
# List workflows
gh workflow list
# Get recent run timings
gh run list --workflow=ci.yml --limit 10 --json databaseId,timing
# Analyze step durations
gh run view <run-id> --json jobs2. Identify Bottlenecks
Time Analysis:
- Which steps take longest?
- Which jobs could run in parallel?
- Are there redundant steps?
Common Bottlenecks:
| Issue | Symptom | Solution |
|---|---|---|
| No caching | npm install >2min | Add cache action |
| Sequential jobs | Total time = sum of jobs | Use needs for parallelism |
| Large artifacts | Upload/download slow | Reduce artifact size |
| Checkout depth | git checkout slow | Use fetch-depth: 1 |
| Heavy images | Container pull slow | Use lighter base images |
3. Generate Recommendations
## Pipeline Optimization Report
### Current State
- **Average Duration**: {time}
- **P95 Duration**: {time}
- **Success Rate**: {percentage}
- **Monthly Minutes**: {minutes}
### Bottleneck Analysis
#### Slowest Steps
| Step | Avg Duration | % of Total |
|------|--------------|------------|
| npm install | 3m 45s | 35% |
| npm test | 4m 20s | 40% |
| npm build | 2m 15s | 25% |
### Recommendations
#### 1. Add Dependency Caching (Est. -2min)
```yaml
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-$\{\{ hashFiles('package-lock.json') \}\}2. Parallelize Test Suites (Est. -3min)
jobs:
test-unit:
...
test-integration:
...
test-e2e:
...3. Use Shallow Clone (Est. -30s)
- uses: actions/checkout@v4
with:
fetch-depth: 1Projected Improvements
| Optimization | Time Saved | Cost Saved/Month |
|---|---|---|
| Caching | 2min | $X |
| Parallelization | 3min | $X |
| Shallow clone | 30s | $X |
| Total | 5.5min | $X |
## Agent Configuration
```yaml
agent: devops-engineer
skills:
- cicd-automation
confirmation: none # Analysis onlyOptimization Templates
Caching Node.js
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'Caching Docker Layers
- uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=maxMatrix Strategy
strategy:
matrix:
node: [18, 20, 22]
os: [ubuntu-latest, macos-latest]Concurrency Control
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true