github-actions-efficiency
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub 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 and define a baseline before proceeding with the steps below.
references/actions.mdIf shell or CLI access is unavailable: ask the user to paste contents and 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)."
gh.github/workflows/gh run list --limit 10将此技能作为GitHub Actions效率优化工作的精简切入点。检查代码仓库,识别浪费来源,仅加载当前任务所需的参考资料。
如果尚无工作流,请加载并先定义基准,再执行以下步骤。
references/actions.md**如果无法访问shell或 CLI:**请用户粘贴目录内容和的输出。如果仅提供了部分文件,请注明:"仅基于提供的文件进行审计;部分见解可能不完整。" 仅基于文件的回复需以:"仅静态分析(未通过实时运行验证)。" 开头。
gh.github/workflows/gh run list --limit 10Use This Skill When
何时使用此技能
- The user wants to reduce GitHub Actions runtime, CI cost, or wasted workflow runs.
- The repo has existing workflows in or explicit GitHub Actions configuration questions.
.github/workflows/ - 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 Actions配置问题。
.github/workflows/ - 用户询问缓存、并发、路径过滤、矩阵缩减、任务优化或特定工作流的修复方案。
- 用户需要帮助从零开始创建新的GitHub Actions工作流或CI基准。
Load Only What You Need
仅加载所需内容
- — audits, job gating, matrix reduction, live validation, and workflow-specific fixes.
references/actions.md - — when the user asks for a before/after efficiency report.
references/reporting.md - — full YAML examples when inline audit commands are not enough.
references/patterns.md
- — 审计、任务门控、矩阵缩减、实时验证和特定工作流修复。
references/actions.md - — 当用户要求提供效率优化前后的对比报告时。
references/reporting.md - — 当内联审计命令不足以解决问题时,提供完整的YAML示例。
references/patterns.md
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-failedLook for: missing dependency caches, missing cancellation, over-broad triggers, duplicate workflow coverage, and expensive jobs that run on every change regardless of scope.
concurrencybash
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查找以下问题:缺少依赖缓存、缺少取消机制、触发条件过于宽泛、工作流重复覆盖、无论变更范围如何都会运行的高成本任务。
concurrency2. Apply guardrails
2. 应用防护规则
Check each proposed fix against these rules before recommending it:
- Does not hide required validation — drop any fix that removes release, schema, migration, or shared-library checks.
- 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.
- Preserves only documented matrix legs — drop matrix legs with no explicit version or platform commitment.
- Write-back jobs use opt-in triggers — flag (do not drop) formatter or bot jobs that run automatically; recommend an opt-in trigger instead.
- 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.
在推荐修复方案前,检查每个提议的修复是否符合以下规则:
- 不得隐藏必要的验证 — 放弃任何移除发布、schema、迁移或共享库检查的修复。
- 不得无故减少并行度 — 除非用户明确优先考虑成本而非延迟且新的关键路径时长不超过原时长的1.25倍,否则放弃该修复。
- 仅保留有文档记录的矩阵分支 — 放弃没有明确版本或平台承诺的矩阵分支。
- 回写任务使用可选触发 — 标记(而非放弃)自动运行的格式化程序或机器人任务;建议改用可选触发。
- 仓库变更与组织设置分离 — 将任何混合了仓库可编辑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.
- Add dependency caching with lockfile-based keys
- Add or correct cancellation
concurrency - Remove duplicate workflow coverage before merging jobs
- Narrow workflow or job triggers safely
- Reduce matrix breadth to match risk and event type
- Parallelize independent jobs on the critical path
从以下6个候选方案中,仅保留那些得到步骤1审计证据支持且通过步骤2所有防护规则的方案。根据预计每日节省的CI时长(每次运行节省时长 × 每日运行次数)对剩余方案排序。选择所有符合条件的候选方案,最多不超过3个。
- 添加基于锁文件的依赖缓存
- 添加或修正取消机制
concurrency - 在合并任务前移除重复的工作流覆盖
- 安全地缩小工作流或任务的触发范围
- 根据风险和事件类型缩减矩阵广度
- 在关键路径上并行化独立任务
4. Verify
4. 验证
- If CLI access is available, validate path-gating and concurrency cancellation with a live test push on a non-protected branch.
gh - 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.
- 如果可以访问CLI,在非保护分支上进行实时测试推送,验证路径门控和并发取消机制。
gh - 如果无法进行实时验证,请在输出中明确说明。
- 即使YAML看起来正确,也要将意外的实时行为视为真实bug。
Required Output
必需输出
- Waste sources — top cost or latency drivers found in step 1
- Proposed fixes — top 3 (or all remaining) with supporting audit evidence
- Validation — what was proven live, what was checked locally only, and any remaining risk
- Impact — expected savings vs. measured savings; separate PR wall-clock time from total runner time
- 浪费来源 — 步骤1中发现的主要成本或延迟驱动因素
- 提议的修复方案 — 前3项(或所有剩余)方案,并附上审计证据支持
- 验证情况 — 哪些已通过实时验证,哪些仅进行了本地检查,以及任何剩余风险
- 影响 — 预期节省与实际测量节省的对比;区分PR挂钟时间与总运行器时间
References
参考资料
references/actions.mdreferences/reporting.mdreferences/patterns.md- — load when reviewing completed efficiency work
references/review-rubric.md
references/actions.mdreferences/reporting.mdreferences/patterns.md- — 审核已完成的效率优化工作时加载
references/review-rubric.md