fix(ci): ワークフロー検査を配布テンプレートまで広げ PR で強制する - #1071
Conversation
検査を追加しただけでは「今後も起きない」と言えない穴が2つあった。 1. 走査対象が .github/workflows/ だけだった config は templates/workflows/ を下流リポジトリへ配布するが、そこを見て いなかった。実際、直前に修正した templates/workflows/claude-health-check.yml の gh バグを自分の検査が検出できない状態だった。 actionlint と同じ3ディレクトリを走査する workflow_files() を共有し、 4検査すべてをそこへ揃える。 2. 週次メンテナンスの警告のみで CI が強制していなかった 退行を含む PR が緑のままマージでき、気付くのは次の定期実行時だった。 ci.yml の Workflow Lint ジョブで4検査を実行する。同ジョブは quality-gate の needs に含まれるため失敗がマージを止める。最初の失敗で打ち切らず 全違反を報告してから落ちる。 paths-filter の workflows は templates/workflows/** を含むため、テンプレート のみの変更でも検査が起動する。退行を注入して CI ステップが exit 1 になること、 既存テンプレートに違反が出ないことを実測済み。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
📝 WalkthroughWalkthroughThe change expands workflow guard scanning to repository and template directories. The CI Workflow Lint job now runs all four guards and reports failures through the quality gate. Tests cover distributed templates, reusable templates, and aggregate failure handling. ChangesWorkflow guard coverage
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WorkflowLint
participant repo_maintenance_checks
participant workflow_templates
participant quality_gate
WorkflowLint->>repo_maintenance_checks: run four workflow guards
repo_maintenance_checks->>workflow_templates: scan repository and template workflows
workflow_templates-->>repo_maintenance_checks: return violations and status
repo_maintenance_checks-->>WorkflowLint: report accumulated status
WorkflowLint->>quality_gate: pass or fail the quality gate
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
|
Claude finished @keito4's task in 4m 40s —— View job レビュー結果このPRは #1068 の穴(走査範囲がテンプレート未対応/CIで未強制)を的確に埋めています。 🟡 major: リスク説明の「Jestが常時実行される」は現在のCI設定では成立していないPR本文の Risk 節にこうあります:
つまり 対応案(どちらか):
🟢 minor: 3ディレクトリ横断後、警告メッセージが
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/repo-maintenance-workflow-guards.test.js (1)
381-464: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd template coverage for
--check-artifact-retention.This block covers three of the four workflow guards. It does not verify artifact retention scanning in either template directory. Add a template fixture with
actions/upload-artifactand missing or invalidretention-days, then assert a nonzero status. This protects the changed loop at Lines 216-253.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/repo-maintenance-workflow-guards.test.js` around lines 381 - 464, Add a new test case within the workflow guards describe block that verifies the --check-artifact-retention guard works on distributed templates. Create a workflow fixture that uses the actions/upload-artifact action without a retention-days parameter or with an invalid retention-days value, then call runCheck with the --check-artifact-retention flag pointing to the fixture in either templates/workflows/ or .github/workflows/templates/, and assert that the result.status is not zero. This mirrors the pattern of the existing test cases in this describe block.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/repo-maintenance-workflow-guards.test.js`:
- Around line 381-464: Add a new test case within the workflow guards describe
block that verifies the --check-artifact-retention guard works on distributed
templates. Create a workflow fixture that uses the actions/upload-artifact
action without a retention-days parameter or with an invalid retention-days
value, then call runCheck with the --check-artifact-retention flag pointing to
the fixture in either templates/workflows/ or .github/workflows/templates/, and
assert that the result.status is not zero. This mirrors the pattern of the
existing test cases in this describe block.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7e47e4c8-ef9b-49e9-b84b-c69e75bf3004
📒 Files selected for processing (6)
.claude/commands/repo-maintenance.md.github/workflows/ci.ymlscript/README.mdscript/lib/repo_maintenance_checks.shtest/claude-workflow-contract.test.jstest/repo-maintenance-workflow-guards.test.js
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6eeb6567fb
ℹ️ 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".
| for check in \ | ||
| --check-claude-action-credentials \ | ||
| --check-self-cancelling-workflows \ | ||
| --check-gh-repo-context \ |
There was a problem hiding this comment.
Honor the documented
-R flag before enforcing this guard
For a checkout-less job that correctly runs gh issue create -R "$GITHUB_REPOSITORY" ..., this newly blocking check fails the Workflow Lint job: gh issue create --help documents -R, --repo [HOST/]OWNER/REPO, but check_gh_repo_context accepts only a literal --repo followed by whitespace. Thus a valid workflow or distributed template using the documented short form cannot pass CI; recognize -R (and the accepted --repo=... form) before making this guard mandatory.
Useful? React with 👍 / 👎.
| guard_status=0 | ||
| for check in \ | ||
| --check-claude-action-credentials \ | ||
| --check-self-cancelling-workflows \ |
There was a problem hiding this comment.
Check the concurrency group before blocking release workflows
For a push-triggered publishing workflow whose concurrency group includes ${{ github.sha }} or ${{ github.run_id }}, a push created by the workflow belongs to a different group and therefore cannot cancel the current run. Nevertheless, check_self_cancelling_workflows considers only the literal cancel-in-progress: true, the push trigger, and a publishing command, so this newly mandatory invocation rejects that valid configuration and fails every workflow-related PR containing it. Inspect the group expression before treating this warning-oriented heuristic as a CI failure.
Useful? React with 👍 / 👎.
検査が CI をブロックするようになったため、偽陽性は正当な PR を止める。 Codex の指摘2件を修正した。 1. gh の -R / --repo= 形式を拒否していた gh は -R, --repo [HOST/]OWNER/REPO を受け付ける。--repo に空白が続く 形式しか認めていなかったため、正しく書かれた checkout 無しジョブが Workflow Lint を落としていた。 2. concurrency group が sha / run_id を含む場合も自己キャンセル扱いしていた group に github.sha や github.run_id が入っていると、自分が起こす push は 別グループに属するため自分自身をキャンセルできない。この構成を拒否すると 正当な publish ワークフローが通らない。 偽陽性を消したうえで、実バグ4件(config の資格情報・gh context・配布テンプレート、 intent-gate-android の自己キャンセル)を引き続き検出できることを再実証済み。 あわせてテストが file-length ゲート(500行)に達したため、共有ヘルパーを test/helpers/workflow-guards.js へ切り出し、gh 関連の検査を別ファイルへ分けた。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
🎉 This PR is included in version 1.133.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Closes #1070
Why
PR #1068 で4つのワークフロー検査を追加したが、「今後も起きない」と言い切れない穴が2つ残っていた。
1. 走査対象が
.github/workflows/だけだったconfig は
templates/workflows/を下流リポジトリへ配布するが、検査はそこを見ていなかった。PR #1068 で修正した
templates/workflows/claude-health-check.ymlのghバグを、同じ PR で追加した検査が検出できない状態だった。修正前のテンプレートを置いた実測:2. CI で強制されていなかった
検査は
scheduled-maintenance.yml(週次 TAKT 実行)からしか呼ばれず、退行を含む PR は緑のままマージできた。今回のdependabot-autoが繰り返し失敗し続けていたのと同じ構図。What
workflow_files()を共有し、4検査すべてを揃えるci.ymlの Workflow Lint ジョブで4検査を実行paths-filterのworkflowsは既にtemplates/workflows/**を含むため、テンプレートのみの変更でも検査が起動する。Workflow Lint はquality-gateのneedsに含まれるため、失敗がマージを止める。最初の失敗で打ち切らず全違反を報告してから落ちる形にした(1件直すたびに次が出る往復を避けるため)。
How to test
走査範囲の拡大(修正前のテンプレートを検出できるか):
CI 強制(退行を注入して CI ステップを再現):
既存テンプレートへの影響: 現行の
templates/workflows/9ファイルに対して4検査とも exit=0。範囲拡大で新たな違反は出ない。npm run workflow:sync:check/actionlint/ lint / format / shellcheck: すべて passレビュー対応(54132bd)
Codex が偽陽性を2件指摘した。検査が CI をブロックするようになった以上、偽陽性は正当な PR を止めるため修正した。
ghの-R/--repo=形式を拒否ghは-R, --repo [HOST/]OWNER/REPOを受け付ける。--repo+ 空白しか認めておらず、正しく書かれた checkout 無しジョブが Workflow Lint を落としていたconcurrency groupがsha/run_idを含む場合も自己キャンセル扱いgithub.sha/github.run_idが入ると、自分が起こす push は別グループに属するため自分自身をキャンセルできない。この構成を拒否すると正当な publish ワークフローが通らない偽陽性を消したうえで、実バグ4件を引き続き検出できることを再実証した(config の資格情報・gh context・配布テンプレート、intent-gate-android の自己キャンセル、いずれも修正前の実ファイルで exit=1)。
あわせてテストが file-length ゲート(500行)に達したため、共有ヘルパーを
test/helpers/workflow-guards.jsへ切り出し、gh関連の検査をtest/repo-maintenance-gh-guards.test.jsへ分けた。ゲートの回避(.filelengthignoreへの追加)はしていない。Risk
needs.changes.outputs.workflows == 'true'が条件。検査スクリプト自体(script/lib/repo_maintenance_checks.sh)のみを変更する PR ではこのジョブは走らないが、検査の挙動は Jest 側の 30 件で固定されており常時実行される。workflow_files()はfindベースのため、ワークフローが存在しないリポジトリでも空を返して正常終了する(下流リポジトリでのrepo-maintenance実行を壊さない)。🤖 Generated with Claude Code
Summary by CodeRabbit
Tests
Chores