Skip to content

chore: GitHub Actions コスト最適化チェックを repo-maintenance に追加 - #564

Merged
keito4 merged 3 commits into
mainfrom
chore/actions-cost-optimization
Mar 13, 2026
Merged

chore: GitHub Actions コスト最適化チェックを repo-maintenance に追加#564
keito4 merged 3 commits into
mainfrom
chore/actions-cost-optimization

Conversation

@keito4

@keito4 keito4 commented Mar 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Claude ワークフローテンプレート(claude.yml, claude-code-review.yml)をコスト最適化版に更新
  • repo-maintenance の Step 3.6 に GitHub Actions コスト最適化チェックを新設
  • 全ワークフロー共通・Claude固有・CI/CD固有・セキュリティ重複・Artifact保持・未使用ワークフロー・Runnerサイズの7つのサブチェック

背景

Elu-co-jp org の請求調査で、Claude Code ワークフローの過剰実行(1日64回)や非効率な CI 設定が Actions 費用の最大要因($615/3ヶ月)であることが判明。全リポジトリに標準的なコスト最適化を適用するため、config テンプレートとメンテナンスチェックを更新する。

変更内容

claude.yml テンプレート

  • cancel-in-progress: true(重複実行防止)
  • issues トリガーから assigned を削除
  • bot ユーザー除外(github-actions, dependabot)
  • Draft PR でのトリガーをスキップ
  • timeout を 30分 → 20分に短縮

claude-code-review.yml テンプレート

  • synchronize トリガーを削除(push毎のレビュー実行防止)

repo-maintenance.md — Step 3.6 新設

サブステップ チェック内容
3.6.1 全ワークフロー共通(concurrency, timeout, Draft, paths)
3.6.2 Claude 固有(cancel-in-progress, bot除外, synchronize)
3.6.3 CI/CD 固有(キャッシュ, paths, Dependabot制限)
3.6.4 セキュリティ重複(CodeQL重複, AIレビュー重複)
3.6.5 Artifact 保持期間(90日デフォルト検出)
3.6.6 未使用ワークフロー検出(30日未実行, 常時失敗, schedule棚卸し)
3.6.7 Runner サイズ(Large/Windows/macOS の高コスト検出)

Test plan

  • /repo-maintenance --mode check-only で新チェックが実行されること
  • /repo-maintenance --mode full で問題検出時に修正提案が表示されること
  • claude.yml テンプレートが新規リポに正しく適用されること

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Optimized GitHub Actions workflows with refined triggers to exclude unnecessary automation
    • Reduced task execution timeouts for faster feedback cycles
    • Expanded maintenance documentation with comprehensive GitHub Actions cost optimization checks and best practices

keito4 and others added 3 commits March 13, 2026 10:49
## 変更内容

### claude.yml テンプレート
- cancel-in-progress: true に変更(重複実行防止)
- issues トリガーから assigned を削除
- bot ユーザー除外(github-actions, dependabot)
- Draft PR でのトリガーをスキップ
- timeout を 30分 → 20分に短縮

### claude-code-review.yml テンプレート
- synchronize トリガーを削除(push毎のレビュー実行防止)

### repo-maintenance.md
- Step 3.6 に Claude Workflow Cost Optimization Check を追加
- 既存リポジトリの設定を自動チェック・修正を推奨

## 背景
Elu-co-jp org で Claude Code ワークフローの過剰実行(1日64回等)が
Actions 費用の最大要因(推定 $400+/3ヶ月)であったため、
全リポジトリに標準的なコスト最適化を適用する。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Step 3.6 を Claude 固有から汎用的な GitHub Actions コスト最適化に拡張:

- 3.6.1: 全ワークフロー共通チェック(concurrency, timeout, Draft PR, paths フィルタ)
- 3.6.2: Claude ワークフロー固有チェック(既存)
- 3.6.3: CI/CD ワークフロー固有チェック(キャッシュ, paths, Dependabot制限)
- 3.6.4: セキュリティワークフローの重複チェック(CodeQL重複, AIレビュー重複)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
repo-maintenance の Step 3.6 に以下のサブチェックを追加:

- 3.6.5: Artifact 保持期間チェック
  - upload-artifact の retention-days 未設定(デフォルト90日)を検出
  - 30日以下の設定を推奨

- 3.6.6: 未使用ワークフロー検出
  - 30日以上実行のないワークフローの検出・無効化提案
  - schedule トリガーの棚卸し
  - 直近5回全て失敗しているワークフローの検出

- 3.6.7: Actions Runner サイズチェック
  - Large Runner / Windows / macOS の使用を検出
  - コスト比較表を提示し、Linux代替を提案

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 13, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR optimizes GitHub Actions configuration by replacing Renovate/Dependabot checks with comprehensive cost optimization guidance in maintenance documentation, refining Claude workflow triggers to exclude bot actions and draft PRs, and reducing Claude workflow timeout from 30 to 20 minutes.

Changes

Cohort / File(s) Summary
GitHub Actions Workflows
\.github/workflows/claude.yml, \.github/workflows/claude-code-review.yml
Refined event triggers and gating logic: removed synchronize trigger from claude-code-review.yml; added bot/draft exclusions, actor-based guardrails (github-actions[bot], dependabot[bot]), and draft-state checks for claude.yml; reduced timeout from 30 to 20 minutes.
Maintenance Documentation
\.claude/commands/repo-maintenance.md
Replaced Renovate/Dependabot section with comprehensive GitHub Actions Cost Optimization checks (3.6): added multi-part structure covering common workflow checks, Claude-specific checks, CI/CD workflows, security duplication detection, artifact retention, unused workflows, and runner size optimization; renumbered subsequent sections (3.7→3.8, 3.8→3.9, 3.9→3.10); expanded with shell-based verification logic and guidance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

size/S

Poem

🐰 GitHub Actions costs reduced with care,
Bot guards and draft checks fill the air,
Timeouts trimmed and workflows refined,
Documentation wise and well-designed! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding GitHub Actions cost optimization checks to repo-maintenance documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/actions-cost-optimization
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 640723fee2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

github.actor != 'dependabot[bot]' &&
(
(github.event_name == 'issue_comment' && contains(github.event.comment.body || '', '@claude') &&
!(github.event.issue.pull_request && github.event.issue.pull_request.url && github.event.issue.draft == true)) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a real draft signal for issue_comment gating

The new Draft PR skip guard for issue_comment is ineffective because github.event.issue.draft is not populated on issue_comment payloads (the issue object only carries a pull_request link block), so github.event.issue.draft == true never matches and comments with @claude on draft PRs still run this workflow. In repositories that rely on draft mode to suppress automation, this reintroduces the very unnecessary executions this change is trying to prevent.

Useful? React with 👍 / 👎.

@keito4

keito4 commented Mar 13, 2026

Copy link
Copy Markdown
Owner Author

(aside)
@claude PRがbaseにマージする際にCIが落ちています。
修正してください。

@claude

claude Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Claude finished @keito4's task in 4m 35s —— View job


調査完了・修正不可の理由説明

  • CI失敗内容の確認
  • 問題箇所の特定

🔍 CI失敗の根本原因

エラー: Workflow validation failed. The workflow file must exist and have identical content to the version on the repository's default branch.

発生メカニズム

  1. このPRで .github/workflows/claude.yml を変更している
  2. Codex の pull_request_review_comment イベントにより claude.yml ワークフローがトリガーされた
  3. anthropics/claude-code-action@v1 が OIDC トークンを交換しようとした際、セキュリティチェックが発動
  4. ワークフローファイルの内容が main ブランチと異なるため、401 Unauthorized で失敗

これは 悪意ある PR がワークフローを改ざんして権限昇格するのを防ぐ セキュリティ機能です。

エラーメッセージ自体にも "If you're seeing this on a PR when you first add a code review workflow file to your repository, this is normal and you should ignore this error." と記載されています。


❌ 修正できない理由

根本的な制約: claude.yml を修正している限り、このPR上でこのワークフローが起動するたびに同じエラーが発生します。

さらに、私(Claude)は .github/workflows/ ディレクトリのファイルを変更する権限を持っていません(GitHub App の制限)。仮に修正を試みてもプッシュが拒否されます。


✅ 対処方法

オプション 内容
そのままマージ このCIエラーは期待された動作であり、ブランチ保護設定でこのチェックを必須にしていない場合はマージ可能
ブランチ保護設定を確認 "Claude Code" が必須チェックでなければ、他のチェックが通っていればマージできる
エラーを許容 エラーメッセージが示す通り「無視してよい」ケース

推奨: claude.yml の変更を含むPRでは、この「Claude Code」ワークフローの失敗は避けられません。ブランチ保護で必須チェックになっていなければ、そのままマージしてください。


補足: Codex レビューアーが指摘した github.event.issue.draft == true の問題(issue_comment ペイロードには draft フィールドが存在しない)は本PRの既知のバグですが、ワークフローファイルへの修正権限がないため私では対処できません。Repo owner が直接修正する必要があります
|

@keito4
keito4 merged commit 57f6cfe into main Mar 13, 2026
13 of 15 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.94.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant