关于 finops-waste
finops-waste 是用于检查 GitHub Actions 工作流成本浪费的技能,面向维护 CI 配置的仓库团队。它分析跳过的运行、机器人触发、并发组和路径筛选,并给出修复建议。
主要功能
- 01分析跳过的工作流运行
- 02检查机器人触发的运行
- 03发现缺失的并发组
- 04检查路径筛选配置
- 05提供针对性修复建议
适用场景
- 01审计 GitHub Actions 浪费
- 02为 PR 工作流添加运行取消配置
- 03减少机器人触发的 CI 噪声
- 04检查单个仓库的工作流配置
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ laurigates/ claude-plugins --skill finops-waste安装后在 Claude Code 中输入/finops-waste确认已加载。
附带文件scripts/waste-analysis.sh
详细介绍
/finops:waste
识别 GitHub Actions 中的浪费模式,并提供可执行的修复建议。分析跳过的运行、机器人触发、缺少并发组和缺少路径筛选器。
何时使用此技能
| 在以下情况下使用此技能…… | 在以下情况下改用同类技能…… |
|---|---|
| 你想获得可执行的 CI 成本浪费修复方案,例如并发、路径筛选器和机器人防护 | 你需要高层级的账单和运行状况概览——使用 /finops:overview |
你需要在 PR 工作流中添加 cancel-in-progress | 你需要工作流运行频率和持续时间统计——使用 /finops:workflows |
| 你正在审计跳过的运行和机器人触发的噪声 | 你正在审计缓存膨胀或过期缓存——使用 /finops:caches |
| 你想修复某个仓库的工作流配置 | 你想对多个仓库的浪费情况进行排名——使用 /finops:compare |
上下文
- 当前仓库 URL:!
git remote get-url origin - 工作流文件:!
find .github/workflows -maxdepth 1 \( -name '*.yml' -o -name '*.yaml' \)
参数
| 参数 | 说明 | 默认值 |
|---|---|---|
repo | 采用 owner/name 格式的仓库 | 当前仓库 |
执行
1. 运行基于 API 的浪费分析:
bash "${SKILL_DIR}/scripts/waste-analysis.sh" "$REPO"
2. 分析工作流文件(需要本地文件系统):
echo ""
echo "=== Workflow File Analysis ==="
for f in .github/workflows/*.yml .github/workflows/*.yaml 2>/dev/null; do
[ -f "$f" ] || continue
name=$(basename "$f")
issues=""
# Check for concurrency
if ! grep -q "concurrency:" "$f"; then
issues="${issues}missing-concurrency "
fi
# Check for path filters (on push/pull_request without paths)
if grep -qE "^\s*(push|pull_request):" "$f" && ! grep -q "paths:" "$f"; then
issues="${issues}no-path-filter "
fi
# Check for bot filter
if ! grep -q "github.event.sender.type" "$f" && ! grep -q "github.actor" "$f"; then
issues="${issues}no-bot-filter "
fi
# Check for cancel-in-progress
if grep -q "pull_request:" "$f" && ! grep -q "cancel-in-progress:" "$f"; then
issues="${issues}no-cancel-in-progress "
fi
if [ -n "$issues" ]; then
echo " $name: $issues"
else
echo " $name: OK"
fi
done
修复建议
分析完成后,根据发现的问题提供具体修复方案:
修复:缺少并发组
# Add to workflow file at top level or per-job
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true # For PR workflows
修复:机器人触发筛选器
jobs:
build:
# Skip if triggered by a bot
if: github.event.sender.type != 'Bot'
runs-on: ubuntu-latest
steps: ...
或者针对特定机器人:
if: github.actor != 'dependabot[bot]' && github.actor != 'renovate[bot]'
修复:添加路径筛选器
on:
push:
branches: [main]
paths:
- 'src/**'
- 'package.json'
- 'package-lock.json'
paths-ignore:
- '**.md'
- 'docs/**'
- '.github/**'
pull_request:
paths:
- 'src/**'
- 'package.json'
修复:取消重复的 PR 运行
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
输出格式
=== Waste Analysis: org/repo ===
=== Skipped Runs ===
Total runs: 100
Skipped: 15 (15%)
By workflow:
CI: 10 skipped
CodeQL: 5 skipped
=== Bot-Triggered Runs ===
Bot-triggered: 25/100 runs
By bot:
dependabot[bot]: 15 runs
renovate[bot]: 10 runs
=== Workflow File Analysis ===
ci.yml: missing-concurrency no-path-filter
deploy.yml: OK
codeql.yml: no-bot-filter
=== Potential Duplicate Runs ===
Commit abc1234: 3 runs (CI, CodeQL, Security)
=== High-Frequency Workflows ===
CI: 67 runs in sample - review trigger conditions
Agentic 优化
| 上下文 | 命令 |
|---|---|
| 跳过的运行次数 | `gh run list --limit 100 --json conclusion --jq '[.[] |
| 失败的运行(精简) | gh run list --limit 50 --status failure --json name,createdAt |
| 检查工作流文件 | bash "${SKILL_DIR}/scripts/waste-analysis.sh" "$REPO" |
| 检查文件中的并发配置 | grep -l "concurrency:" .github/workflows/*.yml |
| 机器人触发的运行 | `gh run list --limit 100 --json actor,conclusion --jq '[.[] |
后续操作
- 提出应用修复方案:对于发现的每个问题,提出直接编辑工作流文件
- 按影响排序:优先处理运行频率高的工作流
- 测试建议:建议先在功能分支上测试更改
- 创建跟踪议题:可选择创建 GitHub 议题来跟踪优化工作
评论
支持 Markdown