Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ jobs:
workflows:
- '.github/workflows/**'
- '.github/actionlint.yaml'
- '.github/labels.yml'
- 'templates/workflows/**'
- 'templates/github/labels.yml'
dependencies:
- 'package.json'
- 'package-lock.json'
Expand All @@ -91,7 +94,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: changes
if: needs.changes.outputs.code == 'true' || needs.changes.outputs.scripts == 'true' || needs.changes.outputs.dependencies == 'true'
if: needs.changes.outputs.code == 'true' || needs.changes.outputs.scripts == 'true' || needs.changes.outputs.dependencies == 'true' || needs.changes.outputs.workflows == 'true'
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6

Expand All @@ -114,7 +117,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: changes
if: needs.changes.outputs.code == 'true' || needs.changes.outputs.dependencies == 'true'
if: needs.changes.outputs.code == 'true' || needs.changes.outputs.dependencies == 'true' || needs.changes.outputs.workflows == 'true'
permissions:
contents: read
actions: write
Expand Down Expand Up @@ -161,7 +164,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: changes
if: needs.changes.outputs.scripts == 'true' || needs.changes.outputs.dependencies == 'true'
if: needs.changes.outputs.scripts == 'true' || needs.changes.outputs.dependencies == 'true' || needs.changes.outputs.workflows == 'true'
permissions:
contents: read
actions: write
Expand Down Expand Up @@ -200,6 +203,10 @@ jobs:
with:
reporter: github-pr-review
fail_on_error: true
actionlint_flags: >-
.github/workflows/*.yml
.github/workflows/templates/*.yml
templates/workflows/*.yml

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 Include .yaml workflows in actionlint flags

The path filters at the top of this workflow still trigger CI for **.yaml and .github/workflows/**, but this new explicit file list only passes *.yml globs to actionlint (the pinned reviewdog entrypoint runs actionlint -oneline ${INPUT_ACTIONLINT_FLAGS}). When someone adds or changes a valid GitHub Actions .yaml workflow/template, the Workflow Lint job runs but never checks that file, so syntax or expression errors in the changed workflow can merge. Include the .yaml globs or generate the file list from both extensions.

Useful? React with 👍 / 👎.


pr-size-check:
name: PR Size Check
Expand Down
22 changes: 20 additions & 2 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ jobs:
github.event.issue.author_association
) &&
(
(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)) ||
(github.event_name == 'issue_comment' && contains(github.event.comment.body || '', '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body || '', '@claude') &&
github.event.pull_request.draft == false) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body || '', '@claude') &&
Expand All @@ -57,13 +56,32 @@ jobs:
actions: read # Required for Claude to read CI results on PRs
checks: read
steps:
- name: Check PR draft state
id: pr_draft
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const { data: pull } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
core.setOutput('is_draft', pull.draft ? 'true' : 'false');

- name: Skip draft PR
if: steps.pr_draft.outputs.is_draft == 'true'
run: echo "Skipping Claude Code for draft PR."

- name: Checkout repository
if: steps.pr_draft.outputs.is_draft != 'true'
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
fetch-depth: 1

- name: Run Claude Code
id: claude
if: steps.pr_draft.outputs.is_draft != 'true'
uses: anthropics/claude-code-action@d5726de019ec4498aa667642bc3a80fca83aa102 # v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
Expand Down
22 changes: 20 additions & 2 deletions templates/workflows/claude.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ jobs:
github.event.issue.author_association
) &&
(
(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)) ||
(github.event_name == 'issue_comment' && contains(github.event.comment.body || '', '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body || '', '@claude') &&
github.event.pull_request.draft == false) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body || '', '@claude') &&
Expand All @@ -72,13 +71,32 @@ jobs:
actions: read # Required for Claude to read CI results on PRs
checks: read
steps:
- name: Check PR draft state
id: pr_draft
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const { data: pull } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
core.setOutput('is_draft', pull.draft ? 'true' : 'false');

- name: Skip draft PR
if: steps.pr_draft.outputs.is_draft == 'true'
run: echo "Skipping Claude Code for draft PR."

- name: Checkout repository
if: steps.pr_draft.outputs.is_draft != 'true'
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
fetch-depth: 1

- name: Run Claude Code
id: claude
if: steps.pr_draft.outputs.is_draft != 'true'
uses: anthropics/claude-code-action@d5726de019ec4498aa667642bc3a80fca83aa102 # v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
Expand Down
36 changes: 26 additions & 10 deletions templates/workflows/terraform-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ on:
workflow_dispatch:
inputs:
environment:
description: 'スキャン対象の環境(空の場合は全環境)'
description: 'スキャン対象の環境'
required: false
type: choice
default: all
options:
- ''
- all
- dev
- staging
- production
Expand Down Expand Up @@ -86,13 +87,6 @@ jobs:
- environment: production
tf_directory: terraform/environments/production

# --- 環境フィルタ ---
# 手動実行で特定環境が指定された場合、その環境のみ実行する
if: >-
github.event_name == 'schedule' ||
github.event.inputs.environment == '' ||
github.event.inputs.environment == matrix.environment

# TODO: GitHub Environments を使用する場合はコメントを外す
# environment: ${{ matrix.environment }}

Expand All @@ -102,16 +96,36 @@ jobs:
TF_CLI_ARGS_plan: '-lock=false'

steps:
# -----------------------------------------------------------------
# 対象環境の判定
# -----------------------------------------------------------------
- name: Select environment
id: selected
run: |
TARGET="${{ github.event.inputs.environment }}"
if [ -z "$TARGET" ]; then
TARGET="all"
fi

if [ "$TARGET" = "all" ] || [ "$TARGET" = "${{ matrix.environment }}" ]; then
echo "run=true" >> "$GITHUB_OUTPUT"
else
echo "run=false" >> "$GITHUB_OUTPUT"
echo "Skipping ${{ matrix.environment }} because target is ${TARGET}."
fi

# -----------------------------------------------------------------
# リポジトリのチェックアウト
# -----------------------------------------------------------------
- name: Checkout repository
if: steps.selected.outputs.run == 'true'
uses: actions/checkout@v6

# -----------------------------------------------------------------
# Terraform セットアップ
# -----------------------------------------------------------------
- name: Setup Terraform
if: steps.selected.outputs.run == 'true'
uses: hashicorp/setup-terraform@v4
with:
# TODO: プロジェクトで使用する Terraform バージョンを指定する
Expand Down Expand Up @@ -151,6 +165,7 @@ jobs:
# -----------------------------------------------------------------
- name: Terraform Init
id: init
if: steps.selected.outputs.run == 'true'
working-directory: ${{ matrix.tf_directory }}
run: terraform init -input=false -no-color

Expand All @@ -163,6 +178,7 @@ jobs:
# 2 = 差分あり(ドリフト検出)
- name: Terraform Plan (Drift Detection)
id: plan
if: steps.selected.outputs.run == 'true'
working-directory: ${{ matrix.tf_directory }}
run: |
set +e
Expand Down Expand Up @@ -364,7 +380,7 @@ jobs:
# Terraform plan エラー時の Slack 通知
# -----------------------------------------------------------------
- name: Notify Slack on error
if: failure()
if: steps.selected.outputs.run == 'true' && failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
Expand Down
12 changes: 12 additions & 0 deletions test/claude-workflow-contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ describe('Claude workflow contracts', () => {
expect(workflow).not.toContain('"allowedTools"');
});

test.each(issueWorkflows)('%s skips draft PR issue comments through the Pulls API', (workflowPath) => {
const workflow = readWorkflow(workflowPath);

expect(workflow).not.toContain('github.event.issue.draft');
expect(workflow).toContain('name: Check PR draft state');
expect(workflow).toContain('github.rest.pulls.get');
expect(workflow).toContain('pull_number: context.issue.number');
expect(workflow).toContain("core.setOutput('is_draft', pull.draft ? 'true' : 'false')");
expect(workflow).toContain("if: steps.pr_draft.outputs.is_draft != 'true'");
expect(workflow).toContain('name: Skip draft PR');
});

test.each(maintenanceWorkflows)('%s creates maintenance PRs in a post-Claude Actions step', (workflowPath) => {
const workflow = readWorkflow(workflowPath);

Expand Down
5 changes: 5 additions & 0 deletions test/integration/workflows.bats
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ load ../test_helper/test_helper
grep -Fq "'**.yml'" "$workflow"
grep -Fq "'**.yaml'" "$workflow"
grep -Fq "'.github/actionlint.yaml'" "$workflow"
grep -Fq "'templates/workflows/**'" "$workflow"
grep -Fq "'templates/github/labels.yml'" "$workflow"
grep -Fq "workflows:" "$workflow"
grep -Fq "needs.changes.outputs.workflows == 'true'" "$workflow"
grep -Fq "actionlint_flags:" "$workflow"
grep -Fq "templates/workflows/*.yml" "$workflow"
}

@test "CI workflow uses secure practices" {
Expand Down
Loading