github-actions-efficiency

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Actions Efficiency

GitHub Actions 效率优化

Use this skill as a lean entrypoint for GitHub Actions efficiency work. Inspect the repo, identify the waste source, and load only the reference material needed for the current task.
If no workflows exist yet, load
references/actions.md
and define a baseline before proceeding with the steps below.
If shell or
gh
CLI access is unavailable:
ask the user to paste
.github/workflows/
contents and
gh run list --limit 10
output. If only partial files are provided, note it: "Audit based on provided files only; some insights may be incomplete." Begin responses from files alone with: "Static-only analysis (not confirmed with live runs)."
将此技能作为GitHub Actions效率优化工作的精简切入点。检查代码仓库,识别浪费来源,仅加载当前任务所需的参考资料。
如果尚无工作流,请加载
references/actions.md
并先定义基准,再执行以下步骤。
**如果无法访问shell或
gh
CLI:**请用户粘贴
.github/workflows/
目录内容和
gh run list --limit 10
的输出。如果仅提供了部分文件,请注明:"仅基于提供的文件进行审计;部分见解可能不完整。" 仅基于文件的回复需以:"仅静态分析(未通过实时运行验证)。" 开头。

Use This Skill When

何时使用此技能

  • The user wants to reduce GitHub Actions runtime, CI cost, or wasted workflow runs.
  • The repo has existing workflows in
    .github/workflows/
    or explicit GitHub Actions configuration questions.
  • The user asks for caching, concurrency, path filters, matrix reduction, job optimization, or workflow-specific fixes.
  • The user needs help creating a new GitHub Actions workflow or CI baseline from scratch.
  • 用户希望缩短GitHub Actions运行时间、降低CI成本或减少无用的工作流运行。
  • 代码仓库中已存在
    .github/workflows/
    目录下的工作流,或用户提出了明确的GitHub Actions配置问题。
  • 用户询问缓存、并发、路径过滤、矩阵缩减、任务优化或特定工作流的修复方案。
  • 用户需要帮助从零开始创建新的GitHub Actions工作流或CI基准。

Load Only What You Need

仅加载所需内容

  • references/actions.md
    — audits, job gating, matrix reduction, live validation, and workflow-specific fixes.
  • references/reporting.md
    — when the user asks for a before/after efficiency report.
  • references/patterns.md
    — full YAML examples when inline audit commands are not enough.
  • references/actions.md
    — 审计、任务门控、矩阵缩减、实时验证和特定工作流修复。
  • references/reporting.md
    — 当用户要求提供效率优化前后的对比报告时。
  • references/patterns.md
    — 当内联审计命令不足以解决问题时,提供完整的YAML示例。

Core Workflow

核心工作流程

1. Measure first

1. 先测量

bash
rg -n "on:|concurrency:|paths:|paths-ignore:|strategy:|matrix:|cache:" .github/workflows
gh run list --limit 10
run_id=$(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')
gh run view "$run_id" --log-failed
Look for: missing dependency caches, missing
concurrency
cancellation, over-broad triggers, duplicate workflow coverage, and expensive jobs that run on every change regardless of scope.
bash
rg -n "on:|concurrency:|paths:|paths-ignore:|strategy:|matrix:|cache:" .github/workflows
gh run list --limit 10
run_id=$(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')
gh run view "$run_id" --log-failed
查找以下问题:缺少依赖缓存、缺少
concurrency
取消机制、触发条件过于宽泛、工作流重复覆盖、无论变更范围如何都会运行的高成本任务。

2. Apply guardrails

2. 应用防护规则

Check each proposed fix against these rules before recommending it:
  1. Does not hide required validation — drop any fix that removes release, schema, migration, or shared-library checks.
  2. Does not reduce parallelism without justification — drop unless the user prioritised cost over latency and the new critical path stays within 1.25× the original.
  3. Preserves only documented matrix legs — drop matrix legs with no explicit version or platform commitment.
  4. Write-back jobs use opt-in triggers — flag (do not drop) formatter or bot jobs that run automatically; recommend an opt-in trigger instead.
  5. Repo changes stay separate from org settings — split any fix that mixes repo-editable YAML with org-level or GitHub-account settings into two distinct recommendations.
在推荐修复方案前,检查每个提议的修复是否符合以下规则:
  1. 不得隐藏必要的验证 — 放弃任何移除发布、schema、迁移或共享库检查的修复。
  2. 不得无故减少并行度 — 除非用户明确优先考虑成本而非延迟新的关键路径时长不超过原时长的1.25倍,否则放弃该修复。
  3. 仅保留有文档记录的矩阵分支 — 放弃没有明确版本或平台承诺的矩阵分支。
  4. 回写任务使用可选触发 — 标记(而非放弃)自动运行的格式化程序或机器人任务;建议改用可选触发。
  5. 仓库变更与组织设置分离 — 将任何混合了仓库可编辑YAML与组织级或GitHub账户设置的修复拆分为两个独立的建议。

3. Select the top 3 fixes

3. 选择前3项修复方案

From the six candidates below, keep only those supported by audit evidence from step 1 and passing all guardrails from step 2. Rank survivors by estimated daily CI minutes saved (per-run savings × runs per day). Select all candidates that meet both criteria, up to a maximum of 3.
  1. Add dependency caching with lockfile-based keys
  2. Add or correct
    concurrency
    cancellation
  3. Remove duplicate workflow coverage before merging jobs
  4. Narrow workflow or job triggers safely
  5. Reduce matrix breadth to match risk and event type
  6. Parallelize independent jobs on the critical path
从以下6个候选方案中,仅保留那些得到步骤1审计证据支持通过步骤2所有防护规则的方案。根据预计每日节省的CI时长(每次运行节省时长 × 每日运行次数)对剩余方案排序。选择所有符合条件的候选方案,最多不超过3个。
  1. 添加基于锁文件的依赖缓存
  2. 添加或修正
    concurrency
    取消机制
  3. 在合并任务前移除重复的工作流覆盖
  4. 安全地缩小工作流或任务的触发范围
  5. 根据风险和事件类型缩减矩阵广度
  6. 在关键路径上并行化独立任务

4. Verify

4. 验证

  • If
    gh
    CLI access is available, validate path-gating and concurrency cancellation with a live test push on a non-protected branch.
  • If live validation is not possible, state that explicitly in the output.
  • Treat unexpected live behavior as a real bug even when the YAML looks correct.
  • 如果可以访问
    gh
    CLI,在非保护分支上进行实时测试推送,验证路径门控和并发取消机制。
  • 如果无法进行实时验证,请在输出中明确说明。
  • 即使YAML看起来正确,也要将意外的实时行为视为真实bug。

Required Output

必需输出

  1. Waste sources — top cost or latency drivers found in step 1
  2. Proposed fixes — top 3 (or all remaining) with supporting audit evidence
  3. Validation — what was proven live, what was checked locally only, and any remaining risk
  4. Impact — expected savings vs. measured savings; separate PR wall-clock time from total runner time
  1. 浪费来源 — 步骤1中发现的主要成本或延迟驱动因素
  2. 提议的修复方案 — 前3项(或所有剩余)方案,并附上审计证据支持
  3. 验证情况 — 哪些已通过实时验证,哪些仅进行了本地检查,以及任何剩余风险
  4. 影响 — 预期节省与实际测量节省的对比;区分PR挂钟时间与总运行器时间

References

参考资料

  • references/actions.md
  • references/reporting.md
  • references/patterns.md
  • references/review-rubric.md
    — load when reviewing completed efficiency work
  • references/actions.md
  • references/reporting.md
  • references/patterns.md
  • references/review-rubric.md
    — 审核已完成的效率优化工作时加载