|
| 1 | +name: Claude Review - Phase 2 (Sensitive File Detection) |
| 2 | + |
| 3 | +# Phase 2: Claude Review with enhanced detection for security-sensitive files |
| 4 | +# Flags high-stakes changes for extra human review attention |
| 5 | +# Estimated cost: ~$1.50/PR |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + types: [opened, ready_for_review, synchronize] |
| 10 | + |
| 11 | +jobs: |
| 12 | + detect-high-stakes: |
| 13 | + name: Detect High-Stakes Changes |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + is_high_stakes: ${{ steps.check.outputs.is_high_stakes }} |
| 17 | + sensitive_files: ${{ steps.check.outputs.sensitive_files }} |
| 18 | + reason: ${{ steps.check.outputs.reason }} |
| 19 | + is_fork: ${{ steps.fork-check.outputs.is_fork }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Check if fork PR |
| 23 | + id: fork-check |
| 24 | + run: | |
| 25 | + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then |
| 26 | + echo "is_fork=true" >> $GITHUB_OUTPUT |
| 27 | + echo "::notice::Fork PR detected — Claude review requires repo secrets and will be skipped" |
| 28 | + else |
| 29 | + echo "is_fork=false" >> $GITHUB_OUTPUT |
| 30 | + fi |
| 31 | +
|
| 32 | + - name: Checkout code |
| 33 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Check for high-stakes changes |
| 38 | + id: check |
| 39 | + run: | |
| 40 | + HIGH_STAKES_PATTERNS=( |
| 41 | + "dream-server/installers/" |
| 42 | + "dream-server/dream-cli" |
| 43 | + "dream-server/config/" |
| 44 | + "dream-server/extensions/services/dashboard-api/security.py" |
| 45 | + ".github/workflows/" |
| 46 | + ".env" |
| 47 | + "docker-compose" |
| 48 | + ) |
| 49 | +
|
| 50 | + CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref || github.event.repository.default_branch || 'main' }}...HEAD) |
| 51 | +
|
| 52 | + IS_HIGH_STAKES="false" |
| 53 | + SENSITIVE_FILES="" |
| 54 | + REASON="" |
| 55 | +
|
| 56 | + for pattern in "${HIGH_STAKES_PATTERNS[@]}"; do |
| 57 | + if echo "$CHANGED_FILES" | grep -i "$pattern" > /dev/null; then |
| 58 | + IS_HIGH_STAKES="true" |
| 59 | + SENSITIVE_FILES=$(echo "$CHANGED_FILES" | grep -i "$pattern" | head -5) |
| 60 | + REASON="Security-sensitive files detected: $pattern" |
| 61 | + break |
| 62 | + fi |
| 63 | + done |
| 64 | +
|
| 65 | + if [[ "${{ contains(github.event.pull_request.labels.*.name, 'ai-consensus') }}" == "true" ]]; then |
| 66 | + IS_HIGH_STAKES="true" |
| 67 | + REASON="Manual review escalation requested via label" |
| 68 | + fi |
| 69 | +
|
| 70 | + echo "is_high_stakes=$IS_HIGH_STAKES" >> $GITHUB_OUTPUT |
| 71 | + echo "sensitive_files<<EOF" >> $GITHUB_OUTPUT |
| 72 | + echo "$SENSITIVE_FILES" >> $GITHUB_OUTPUT |
| 73 | + echo "EOF" >> $GITHUB_OUTPUT |
| 74 | + echo "reason=$REASON" >> $GITHUB_OUTPUT |
| 75 | +
|
| 76 | + if [ "$IS_HIGH_STAKES" == "true" ]; then |
| 77 | + echo "::notice::High-stakes changes detected — flagging for extra review" |
| 78 | + fi |
| 79 | +
|
| 80 | + claude-review: |
| 81 | + name: Claude Code Review |
| 82 | + needs: detect-high-stakes |
| 83 | + if: | |
| 84 | + needs.detect-high-stakes.outputs.is_fork != 'true' && |
| 85 | + github.actor != 'claude[bot]' && |
| 86 | + github.actor != 'dependabot[bot]' && |
| 87 | + github.actor != 'github-actions[bot]' |
| 88 | +
|
| 89 | + runs-on: ubuntu-latest |
| 90 | + timeout-minutes: 15 |
| 91 | + |
| 92 | + concurrency: |
| 93 | + group: claude-review-p2-${{ github.event.pull_request.number }} |
| 94 | + cancel-in-progress: true |
| 95 | + |
| 96 | + steps: |
| 97 | + - name: Checkout code |
| 98 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 99 | + with: |
| 100 | + fetch-depth: 0 |
| 101 | + |
| 102 | + - name: Run Claude Code Review |
| 103 | + id: review |
| 104 | + uses: anthropics/claude-code-action@88c168b39e7e64da0286d812b6e9fbebb6708185 # v1 |
| 105 | + with: |
| 106 | + claude_args: | |
| 107 | + code-review \ |
| 108 | + --model claude-opus-4-5-20251101 \ |
| 109 | + --max-turns 20 \ |
| 110 | + --allowedTools "Bash(git diff *),Bash(git log *),Bash(git blame *),Read" |
| 111 | +
|
| 112 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 114 | + |
| 115 | + - name: Save review artifact (high-stakes) |
| 116 | + if: needs.detect-high-stakes.outputs.is_high_stakes == 'true' |
| 117 | + run: | |
| 118 | + mkdir -p /tmp/review-artifacts |
| 119 | + echo "high-stakes review completed" > /tmp/review-artifacts/claude-review.txt |
| 120 | +
|
| 121 | + - name: Upload review artifact |
| 122 | + if: needs.detect-high-stakes.outputs.is_high_stakes == 'true' |
| 123 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 124 | + with: |
| 125 | + name: claude-review-result |
| 126 | + path: /tmp/review-artifacts/ |
| 127 | + |
| 128 | + review-summary: |
| 129 | + name: Review Summary |
| 130 | + needs: [detect-high-stakes, claude-review] |
| 131 | + if: always() && needs.detect-high-stakes.outputs.is_fork != 'true' |
| 132 | + runs-on: ubuntu-latest |
| 133 | + permissions: |
| 134 | + pull-requests: write |
| 135 | + |
| 136 | + steps: |
| 137 | + - name: Post high-stakes notice |
| 138 | + if: needs.detect-high-stakes.outputs.is_high_stakes == 'true' |
| 139 | + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 |
| 140 | + with: |
| 141 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + script: | |
| 143 | + const reason = `${{ needs.detect-high-stakes.outputs.reason }}`; |
| 144 | + const sensitiveFiles = `${{ needs.detect-high-stakes.outputs.sensitive_files }}`; |
| 145 | +
|
| 146 | + await github.rest.issues.createComment({ |
| 147 | + owner: context.repo.owner, |
| 148 | + repo: context.repo.repo, |
| 149 | + issue_number: context.payload.pull_request.number, |
| 150 | + body: `## Sensitive Files Detected |
| 151 | +
|
| 152 | + **Trigger**: ${reason} |
| 153 | +
|
| 154 | + **Files flagged**: |
| 155 | + \`\`\` |
| 156 | + ${sensitiveFiles} |
| 157 | + \`\`\` |
| 158 | +
|
| 159 | + Extra human review is recommended for this PR. |
| 160 | +
|
| 161 | + --- |
| 162 | + **Phase**: 2 (Sensitive File Detection) | **Estimated Cost**: ~$1.50` |
| 163 | + }); |
| 164 | +
|
| 165 | + - name: Generate summary |
| 166 | + run: | |
| 167 | + echo "### Review Complete" >> $GITHUB_STEP_SUMMARY |
| 168 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 169 | + echo "- **Phase**: 2 (Sensitive File Detection)" >> $GITHUB_STEP_SUMMARY |
| 170 | + echo "- **High-Stakes**: ${{ needs.detect-high-stakes.outputs.is_high_stakes }}" >> $GITHUB_STEP_SUMMARY |
| 171 | + if [ "${{ needs.detect-high-stakes.outputs.is_high_stakes }}" == "true" ]; then |
| 172 | + echo "- **Reason**: ${{ needs.detect-high-stakes.outputs.reason }}" >> $GITHUB_STEP_SUMMARY |
| 173 | + fi |
| 174 | + echo "- **Estimated Cost**: ~\$1.50" >> $GITHUB_STEP_SUMMARY |
0 commit comments