当前位置: 首页 > Skill >

Github Actions Optimizer

Github Actions Optimizer

1.0.1 2026.11.04 浏览:339
获取Skill文件查看使用说明
作者:林舟许可证:
本文目录展开

GitHub Actions Optimizer

Analyze and optimize GitHub Actions workflows for faster builds, lower costs, better security, and higher reliability. Reviews workflow files, run history, cache usage, and runner configurations. Use when CI is slow, expensive, or unreliable.

Usage

"Optimize my GitHub Actions workflows"
"Why are my CI builds so slow?"
"Audit my workflows for security issues"
"Reduce GitHub Actions costs"
"Find flaky steps in my CI pipeline"

How It Works

1. Workflow Discovery

# Find all workflow files
find .github/workflows -name "*.yml" -o -name "*.yaml" 2>/dev/null

# Check recent run durations
gh run list --limit 20 --json name,status,conclusion,startedAt,updatedAt,databaseId | python3 -c "
import json, sys
from datetime import datetime
runs = json.load(sys.stdin)
for r in runs:
    start = datetime.fromisoformat(r['startedAt'].rstrip('Z'))
    end = datetime.fromisoformat(r['updatedAt'].rstrip('Z'))
    duration = (end - start).total_seconds() / 60
    print(f'{r["name"]:30s} {r["conclusion"]:10s} {duration:.1f}min')
"

2. Speed Optimization

Caching analysis:

  • Are dependencies cached? (actions/cache or actions/setup-node with cache)
  • Cache hit rate from recent runs
  • Missing cache keys for build artifacts, Docker layers, compiled assets
  • Cache size approaching 10GB limit?
  • Stale cache keys never cleaned up

Job parallelism:

  • Sequential jobs that could run in parallel
  • Large matrix builds that could be split
  • Test suites that could be sharded
  • Independent steps within a single job

Runner optimization:

  • Self-hosted vs GitHub-hosted: cost/speed tradeoff
  • Larger runners available? (ubuntu-latest-xl, ubuntu-latest-16-cores)
  • ARM runners for compatible workloads (30% cheaper)
  • Container jobs vs VM jobs

Build optimization:

  • Unnecessary checkout of full git history (fetch-depth: 0)
  • Redundant install steps across jobs
  • Tests running on every push instead of just PRs
  • Docker builds without layer caching
  • Missing path filters (trigger on irrelevant file changes)

3. Cost Reduction

Minute savings:

  • Identify most expensive workflows (minutes × frequency)
  • Timeout missing on long-running jobs (default: 6 hours!)
  • Concurrency groups to cancel redundant runs
  • Path filtering to skip irrelevant triggers
  • PR-only vs push+PR triggers

Storage savings:

  • Artifact retention too long (default: 90 days)
  • Large artifacts uploaded unnecessarily
  • Cache entries never evicted

4. Security Audit

  • Pinned actions: Using @v3 instead of SHA pinning
  • Secrets exposure: Secrets passed to untrusted steps
  • GITHUB_TOKEN permissions: Overly broad default permissions
  • Pull request target: Workflow runs on pull_request_target with checkout of PR head
  • Script injection: Untrusted input in run: blocks (${{ github.event.issue.title }})
  • Third-party actions: Unverified marketplace actions with broad permissions
  • Environment protection: Missing required reviewers on production deployments

5. Reliability

  • Retry strategy: Flaky steps without retry configuration
  • Timeout values: Missing or too generous timeouts
  • Error handling: continue-on-error hiding real failures
  • Status checks: Required checks that aren't actually running
  • Concurrency: Race conditions between parallel workflow runs

6. Modern Patterns

Recommend modern GitHub Actions features:

  • Reusable workflows for DRY CI
  • Composite actions for shared steps
  • Environments with deployment protection rules
  • OIDC for cloud authentication (no long-lived secrets)
  • Merge queues for safe main branch

Output

## GitHub Actions Optimization Report

**Workflows:** 5 | **Avg monthly minutes:** 12,400 | **Monthly cost:** ~$99

### ⚡ Speed Improvements

1. **Add dependency caching** — ci.yml
   Current: `npm ci` runs fresh every time (2m 15s)
   Fix: Add `cache: 'npm'` to `actions/setup-node`
   Savings: ~1m 45s per run × 180 runs/mo = 315 min/mo

2. **Parallelize test suites** — ci.yml
   Current: Unit + integration + e2e run sequentially (18 min)
   Fix: Split into 3 parallel jobs
   Savings: ~12 min per run (runs in 6 min instead of 18)

3. **Add path filters** — ci.yml
   Current: Triggers on all pushes including docs changes
   Fix: `paths-ignore: ['docs/**', '*.md', 'LICENSE']`
   Savings: ~40 unnecessary runs/mo × 18 min = 720 min/mo

### 🔐 Security Issues

4. **Unpinned action** — deploy.yml:12
   `uses: actions/checkout@v4` → pin to SHA
   
5. **Script injection risk** — pr-comment.yml:8
   `run: echo "${{ github.event.comment.body }}"` 
   → Use environment variable instead

6. **Broad GITHUB_TOKEN** — all workflows
   No `permissions:` block = read-write to everything
   → Add explicit `permissions: { contents: read }`

### 💰 Cost Savings
| Optimization | Minutes Saved/mo | $ Saved/mo |
|-------------|------------------|------------|
| Dependency cache | 315 | $2.52 |
| Path filters | 720 | $5.76 |
| Concurrency cancel | 200 | $1.60 |
| Timeout (6h → 30m) | ~0 (prevents surprise) | — |
| **Total** | **1,235** | **$9.88** |

Projected monthly: 12,400 → 11,165 min (-10%)

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,031
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,029
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,017
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,014
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,011
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,011
Skill 文件
  • SKILL.md
    • GitHub Actions Optimizer
    • Usage
    • How It Works
      • 1. Workflow Discovery
      • 2. Speed Optimization
      • 3. Cost Reduction
      • 4. Security Audit
      • 5. Reliability
      • 6. Modern Patterns
    • Output
  • 项目或源文件

相关 Skill

更多
GitHub Actions SHA Rerun Debt Audit GitHub Actions SHA Rerun Debt Audit 按提交SHA审查重跑成本,识别跨工作流反复消耗CI分钟数的提交。
GitHub Actions 工作流组合器 GitHub Actions 工作流组合器 从模块化作业模板中组合 GitHub Actions 工作流 YAML 文件,解析操作版本引脚和秘密引用。根据 GitHub Actions 模式进行验证,并检查已知操作 CVE。
GitHub Actions Step Flake Audit GitHub Actions Step Flake Audit 通过检测多次运行中成功与失败混合的情况,发现不稳定的 GitHub Actions 步骤。
GitHub Actions OIDC Token Validator GitHub Actions OIDC Token Validator 验证 GitHub Actions OIDC 令牌以实现安全、无秘密的部署。使用 GitHub Actions id-token API 和 jose JWT 库来验证受众、发行者和主题声明。与 AWS STS AssumeRoleWithWebIdentity 和 GCP Workload Identity Federation 集成以访问云资源。
GitHub Actions Failure Streak Audit GitHub Actions Failure Streak Audit 检测仓库/工作流/分支的GitHub Actions连续失败,优先处理不稳定的流水线。