@@ -8,8 +8,8 @@ permissions:
88 contents : read
99 pull-requests : write
1010 issues : read
11-
1211 id-token : write
12+
1313jobs :
1414 claude-code-review :
1515 runs-on : ubuntu-latest
@@ -20,11 +20,51 @@ jobs:
2020 with :
2121 fetch-depth : 0
2222
23+ # The Claude Code Action validates that the workflow file exists on the default branch
24+ # and is identical. This makes first-time installation (or updates) fail on the PR that
25+ # introduces changes to this file. We preflight and skip gracefully in that case.
26+ - name : Preflight (workflow integrity)
27+ id : preflight
28+ shell : bash
29+ run : |
30+ set -euo pipefail
31+
32+ file_path=".github/workflows/claude-code-review.yml"
33+ default_branch="${{ github.event.repository.default_branch }}"
34+
35+ git fetch --no-tags --depth=1 origin "${default_branch}"
36+
37+ if git cat-file -e "origin/${default_branch}:${file_path}" 2>/dev/null; then
38+ if git diff --quiet "origin/${default_branch}" -- "${file_path}"; then
39+ echo "should_run=true" >> "$GITHUB_OUTPUT"
40+ exit 0
41+ fi
42+
43+ echo "should_run=false" >> "$GITHUB_OUTPUT"
44+ echo "reason=workflow_differs_from_default_branch" >> "$GITHUB_OUTPUT"
45+ exit 0
46+ fi
47+
48+ echo "should_run=false" >> "$GITHUB_OUTPUT"
49+ echo "reason=workflow_missing_on_default_branch" >> "$GITHUB_OUTPUT"
50+
2351 - name : Claude Review
52+ if : steps.preflight.outputs.should_run == 'true' && secrets.ANTHROPIC_API_KEY != ''
2453 uses : anthropics/claude-code-action@v1
2554 with :
2655 anthropic_api_key : ${{ secrets.ANTHROPIC_API_KEY }}
2756 prompt : " /review"
2857 # CLAUDE.md is a symlink to AGENTS.md in this repo; keep repo rules there.
2958 claude_args : |
3059 --max-turns 4
60+
61+ - name : Claude Review (skipped)
62+ if : steps.preflight.outputs.should_run != 'true'
63+ run : |
64+ echo "Skipping Claude review: ${{ steps.preflight.outputs.reason }}"
65+ echo "This is expected when this workflow is first introduced or updated in a PR."
66+
67+ - name : Claude Review (skipped: missing secret)
68+ if : steps.preflight.outputs.should_run == 'true' && secrets.ANTHROPIC_API_KEY == ''
69+ run : |
70+ echo "Skipping Claude review: missing ANTHROPIC_API_KEY secret."
0 commit comments