Skip to content

feat: GitHub Actions で静的チェックを実行する - #8

Merged
kenshin-morioka merged 5 commits into
mainfrom
feat-ci
Aug 11, 2026
Merged

feat: GitHub Actions で静的チェックを実行する#8
kenshin-morioka merged 5 commits into
mainfrom
feat-ci

Conversation

@kenshin-morioka

@kenshin-morioka kenshin-morioka commented Aug 11, 2026

Copy link
Copy Markdown
Owner

概要

push (main) / PR 時にローカルと同じ make check を CI で実行 (docs/specification.md のステップ7)。

内容

  • .github/workflows/validate.yml
    • jdx/mise-action: mise.toml のツールを導入 (terraform / tflint / checkov / cfn-lint / cfn-dia)
    • aws-actions/setup-sam: SAM CLI を導入
    • apt (graphviz) + Homebrew (inframap ※ v0.8.1 はバイナリ配布が無いため、ボトルを持つ brew を利用)
    • make check で fmt-check / validate / lint / 構成図生成まで一気通貫
  • 安全対策: AWS credentials 不使用、permissions: contents: read のみ
  • mise.toml: CI の再現性のため "latest" からバージョン固定に変更

動作確認

  • ローカル: mise install (固定バージョン) + make check
  • CI 本体はこの PR の checks で検証されます

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 改善
    • メインブランチへの変更やプルリクエストを対象に、自動検証を実行するワークフローを追加しました。
    • Terraform、TFLint、Checkovなどの検証ツールを導入し、構成チェックを自動化しました。
    • 検証ツールのバージョンを固定し、実行結果の一貫性を向上しました。
    • TerraformやSAMの検証を整理し、問題の発見と確認を行いやすくしました。
    • インフラ構成の検証と図式化に必要なツールを整備しました。

- push (main) / PR 時に make check を実行 (validate / lint / 図生成の検証)
- AWS credentials は使用しない (permissions: contents: read のみ)
- ツールは mise.toml (バージョン固定に変更) + setup-sam + brew/apt で導入

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

mise.toml の検証ツールを固定バージョンに変更しました。GitHub Actionsに、必要なツールをセットアップして make check を実行する validate ワークフローを追加しました。Checkovの実行方法とSAMテンプレートの除外設定も変更しました。

Changes

検証環境とCI

Layer / File(s) Summary
検証ツールのバージョン固定
mise.toml
Terraform、TFLint、Checkov、cfn-lint、cfn-diagramのバージョンを固定しました。fast-xml-parser@4.5.7 のtrust policy除外を追加しました。
Checkov検証の分離と例外設定
Makefile, sam/template.yaml
TerraformとSAMを個別にCheckovで検証するよう変更しました。HelloFunctionHelloRustFunction に3件のCheckovスキップ設定を追加しました。
GitHub Actions検証ワークフロー
.github/workflows/validate.yml
mainへのpushとpull requestで実行するワークフローを追加しました。必要なツールをセットアップした後に make check を実行します。

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

ぴょんと跳ねて、ツールを固定
CIの道を、軽やかに確認
SAMとGraphvizもそろえ
make check を走らせる
うさぎも安心、検証完了 🌙

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは、GitHub Actionsで静的チェックを実行するという変更の主目的を明確かつ簡潔に示しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

kenshin-morioka and others added 2 commits August 12, 2026 08:33
mise の npm backend が provenance 無しを理由に cfn-diagram の依存
fast-xml-parser@4.5.7 を拒否して CI が失敗するため、以下を検証して
この 1 バージョンのみ除外:
- npm tarball と GitHub v4.5.7 タグのソースが完全一致
- 公開者は 4.x 系全リリースと同一のメンテナ本人アカウント
- 5.x 系のみ GitHub Actions の trusted publishing を使う運用によるもの

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ubuntu-24.04 ランナーには Homebrew が搭載されていないため、
バイナリ配布の無い InfraMap は Go でソースからインストールする

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In @.github/workflows/validate.yml:
- Line 21: Update the actions/checkout@v4 step in the workflow to set
persist-credentials to false, ensuring the checkout does not retain the
GITHUB_TOKEN while leaving the existing checkout behavior unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a2f4a708-4f88-44be-a4fc-a5a19ccdcdc7

📥 Commits

Reviewing files that changed from the base of the PR and between 7f57924 and 158c6d2.

📒 Files selected for processing (2)
  • .github/workflows/validate.yml
  • mise.toml

Comment thread .github/workflows/validate.yml
kenshin-morioka and others added 2 commits August 12, 2026 08:38
- --directory を複数同時に渡すと SAM 側が CloudFormation として
  スキャンされない挙動があるため、ディレクトリごとに checkov を実行
- プレースホルダ関数への CKV_AWS_115/116/117 は、各設定の意味を
  コメントで説明した上で Metadata の checkov.skip で明示的に抑制

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@sam/template.yaml`:
- Around line 30-40: Update the Checkov skip comments in the Metadata for both
HelloFunction and HelloRustFunction, covering all six CKV_AWS_115, CKV_AWS_116,
and CKV_AWS_117 entries. Replace the generic “learning placeholder” text with
specific comments describing the relevant control and the action required before
production: reserved concurrency limits, a dead-letter queue, and VPC placement
evaluation. Ensure Checkov 3.3.9 reports six skipped checks with those
descriptive Suppress comments.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ac9f57d7-0335-4530-8fe9-2ebe1d95d4b1

📥 Commits

Reviewing files that changed from the base of the PR and between 4a96567 and 0432ca9.

📒 Files selected for processing (3)
  • .github/workflows/validate.yml
  • Makefile
  • sam/template.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/validate.yml

Comment thread sam/template.yaml
Comment on lines +30 to +40
Metadata:
# checkov が指摘する下記 3 点は本来設計すべき項目だが、学習用プレースホルダの
# ため理由を明記した上でスキップする。本実装では各項目を設計判断すること
checkov:
skip:
- id: CKV_AWS_115 # 同時実行数制限: 暴走や下流サービス保護のための上限設定
comment: "learning placeholder"
- id: CKV_AWS_116 # DLQ: 失敗イベントを退避して調査・再処理できるようにする
comment: "learning placeholder"
- id: CKV_AWS_117 # VPC 配置: プライベートリソースへ安全にアクセスするため
comment: "learning placeholder"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT

set +e
mise exec -- checkov \
  --directory sam \
  --check CKV_AWS_115,CKV_AWS_116,CKV_AWS_117 \
  --compact >"$tmp" 2>&1
status=$?
set -e

cat "$tmp"
test "$status" -eq 0
grep -q 'Suppressed Checks: 6' "$tmp"
! grep -q 'Suppress comment: learning placeholder' "$tmp"

Repository: kenshin-morioka/aws-learning

Length of output: 204


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- candidate files ---'
git ls-files | rg '(^|/)(template\.yaml|Makefile|mise\.toml|pyproject\.toml|requirements.*|\.checkov\.yaml|README)' || true

printf '%s\n' '--- template locations ---'
rg -n -C 5 'CKV_AWS_11[567]|learning placeholder|Hello(Function|RustFunction)|Metadata:' sam/template.yaml

printf '%s\n' '--- Checkov references ---'
rg -n -i -C 3 'checkov|CKV_AWS_11[567]|Suppressed Checks' . --glob '!node_modules/**' --glob '!dist/**' --glob '!build/**' || true

Repository: kenshin-morioka/aws-learning

Length of output: 7543


🌐 Web query:

Checkov 3.3.9 CloudFormation SAM metadata checkov skip comment Suppressed Checks output CKV_AWS_115 CKV_AWS_116 CKV_AWS_117

💡 Result:

In Checkov, you can suppress specific policy checks like CKV_AWS_115, CKV_AWS_116, and CKV_AWS_117 in AWS CloudFormation and SAM templates using either inline comments or the resource Metadata section [1][2]. Inline Comments To suppress a check for a specific resource, add a comment directly above the resource definition using the following pattern [1][3]: # checkov:skip=<check_id>:<suppression_comment> Example: Resources: MyLambdaFunction: # checkov:skip=CKV_AWS_115:Function-level concurrent execution limit is not required # checkov:skip=CKV_AWS_116:Dead Letter Queue is not required # checkov:skip=CKV_AWS_117:Function is not inside a VPC Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: nodejs18.x Metadata Section Alternatively, you can use the Metadata section within the resource. This is often cleaner for multiple suppressions [1][2]. Example: Resources: MyLambdaFunction: Type: AWS::Serverless::Function Metadata: checkov: skip: - id: CKV_AWS_115 comment: Function-level concurrent execution limit is not required - id: CKV_AWS_116 comment: Dead Letter Queue is not required - id: CKV_AWS_117 comment: Function is not inside a VPC Properties: Handler: index.handler Runtime: nodejs18.x Global Suppression If you prefer to skip these checks across your entire project, you can use a.checkov.yml configuration file [3][4]: skip-check: - CKV_AWS_115 - CKV_AWS_116 - CKV_AWS_117 Note that AWS SAM templates are scanned using the same underlying logic as CloudFormation [5]. The Metadata approach is particularly effective when working with generated templates (such as those from AWS CDK or Serverless Framework) [6][7].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- pinned tool configuration ---'
cat -n mise.toml | sed -n '1,12p'

printf '%s\n' '--- relevant template ---'
cat -n sam/template.yaml | sed -n '20,70p'

printf '%s\n' '--- local Checkov availability ---'
command -v checkov || true
python3 - <<'PY'
try:
    import checkov
    print("python checkov import: available")
except Exception as exc:
    print(f"python checkov import: unavailable ({type(exc).__name__}: {exc})")
PY

printf '%s\n' '--- structured skip-entry count from template text ---'
python3 - <<'PY'
from pathlib import Path
text = Path("sam/template.yaml").read_text()
ids = ["CKV_AWS_115", "CKV_AWS_116", "CKV_AWS_117"]
for function in ("HelloFunction", "HelloRustFunction"):
    start = text.index(f"  {function}:")
    end = text.find("\n  ", start + 3)
    block = text[start:] if end == -1 else text[start:end]
    print(function)
    for check_id in ids:
        occurrences = block.count(f"id: {check_id}")
        comments = []
        for line in block.splitlines():
            if f"id: {check_id}" in line:
                comments.append(line)
        print(f"  {check_id}: entries={occurrences}, {comments}")
PY

Repository: kenshin-morioka/aws-learning

Length of output: 3200


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- installed Checkov wrapper/version ---'
head -n 5 /usr/local/bin/checkov 2>/dev/null || true
checkov --version

printf '%s\n' '--- targeted Checkov scan ---'
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
set +e
checkov --directory sam \
  --check CKV_AWS_115,CKV_AWS_116,CKV_AWS_117 \
  --compact >"$tmp" 2>&1
status=$?
set -e
cat "$tmp"
printf 'checkov_exit=%s\n' "$status"

printf '%s\n' '--- corrected six-entry check ---'
python3 - <<'PY'
from pathlib import Path
text = Path("sam/template.yaml").read_text()
for function in ("HelloFunction", "HelloRustFunction"):
    start = text.index(f"  {function}:")
    next_function = text.find("\n  ", start + len(function) + 4)
    block = text[start:] if next_function < 0 else text[start:next_function]
    print(function)
    for check_id in ("CKV_AWS_115", "CKV_AWS_116", "CKV_AWS_117"):
        lines = [line.strip() for line in block.splitlines() if f"- id: {check_id}" in line]
        comments = [
            line.strip() for line in block.splitlines()
            if line.strip().startswith("comment:")
        ]
        print(f"  {check_id}: {len(lines)} entry, comments={comments}")
PY

Repository: kenshin-morioka/aws-learning

Length of output: 5062


Checkov の抑制理由をチェックごとに具体化してください。

HelloFunctionHelloRustFunction の6件について、comment を対象制御と本番化前の対応を示す内容に変更してください。

  • CKV_AWS_115: 予約同時実行数を本番化前に設定する理由
  • CKV_AWS_116: DLQを本番化前に設定する理由
  • CKV_AWS_117: VPC配置を本番化前に評価する理由

Checkov 3.3.9で Skipped checks: 6 となり、各結果に具体的な Suppress comment が表示される状態にしてください。

🤖 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 `@sam/template.yaml` around lines 30 - 40, Update the Checkov skip comments in
the Metadata for both HelloFunction and HelloRustFunction, covering all six
CKV_AWS_115, CKV_AWS_116, and CKV_AWS_117 entries. Replace the generic “learning
placeholder” text with specific comments describing the relevant control and the
action required before production: reserved concurrency limits, a dead-letter
queue, and VPC placement evaluation. Ensure Checkov 3.3.9 reports six skipped
checks with those descriptive Suppress comments.

@kenshin-morioka
kenshin-morioka merged commit c6f51b3 into main Aug 11, 2026
2 checks passed
@kenshin-morioka
kenshin-morioka deleted the feat-ci branch August 11, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant