From 6feb2d2894dfd6b7de62a510ba37945effa43dba Mon Sep 17 00:00:00 2001 From: Predge <307976007+predge-ai@users.noreply.github.com> Date: Sun, 4 Oct 2026 17:51:56 +0300 Subject: [PATCH] ci: add Claude Code PR review and security review workflows --- .github/workflows/claude-security-review.yml | 49 +++++++++ .github/workflows/claude.yml | 101 +++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 .github/workflows/claude-security-review.yml create mode 100644 .github/workflows/claude.yml diff --git a/.github/workflows/claude-security-review.yml b/.github/workflows/claude-security-review.yml new file mode 100644 index 0000000..eb99201 --- /dev/null +++ b/.github/workflows/claude-security-review.yml @@ -0,0 +1,49 @@ +name: Claude Security Review + +# Security review of each PR diff with anthropics/claude-code-security-review. +# Auth: this action only supports an Anthropic API key (ANTHROPIC_API_KEY secret); +# it does not accept a Claude Code OAuth token. If the secret is missing, the job +# skips with a notice instead of failing. +# Only `pull_request` (never `pull_request_target`); fork PRs are skipped. + +on: + pull_request: + types: [opened, synchronize, ready_for_review, reopened] + +permissions: {} + +concurrency: + group: claude-security-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + security: + if: | + github.event.pull_request.draft == false && + github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: read + pull-requests: write + steps: + - name: Check auth secret + id: auth + env: + KEY: ${{ secrets.ANTHROPIC_API_KEY }} + run: | + if [ -n "$KEY" ]; then echo "ok=true" >> "$GITHUB_OUTPUT"; else echo "::notice::ANTHROPIC_API_KEY is not set; skipping security review."; fi + + - name: Checkout repository + if: steps.auth.outputs.ok == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} + fetch-depth: 2 + + - name: Claude security review + if: steps.auth.outputs.ok == 'true' + uses: anthropics/claude-code-security-review@0c6a49f1fa56a1d472575da86a94dbc1edb78eda # main @ 2026-02-11 (no release tags) + with: + comment-pr: true + claude-api-key: ${{ secrets.ANTHROPIC_API_KEY }} diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml new file mode 100644 index 0000000..6fd553c --- /dev/null +++ b/.github/workflows/claude.yml @@ -0,0 +1,101 @@ +name: Claude Code + +# @claude mentions (comments, reviews, issues) + automatic review on PRs. +# Auth: CLAUDE_CODE_OAUTH_TOKEN secret (from `claude setup-token`). +# Requires the Claude GitHub App installed on the repo: https://github.com/apps/claude +# If the secret is missing, jobs skip with a notice instead of failing. +# Only `pull_request` (never `pull_request_target`) is used, so fork PRs get no secrets. + +on: + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + pull_request_review: + types: [submitted] + issues: + types: [opened, assigned] + pull_request: + types: [opened, synchronize, ready_for_review, reopened] + +permissions: {} + +jobs: + mention: + if: | + (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_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || + (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: write + pull-requests: write + issues: write + id-token: write + actions: read + steps: + - name: Check auth secret + id: auth + env: + TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + run: | + if [ -n "$TOKEN" ]; then echo "ok=true" >> "$GITHUB_OUTPUT"; else echo "::notice::CLAUDE_CODE_OAUTH_TOKEN is not set; skipping Claude."; fi + + - name: Checkout repository + if: steps.auth.outputs.ok == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 1 + + - name: Run Claude Code + if: steps.auth.outputs.ok == 'true' + uses: anthropics/claude-code-action@cab360f6565aa35a51d6ce9e43f1f4287c0a32ea # v1.0.241 + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + + review: + if: | + github.event_name == 'pull_request' && + github.event.pull_request.draft == false && + github.event.pull_request.head.repo.full_name == github.repository + concurrency: + group: claude-review-${{ github.event.pull_request.number }} + cancel-in-progress: true + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: read + pull-requests: write + id-token: write + steps: + - name: Check auth secret + id: auth + env: + TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + run: | + if [ -n "$TOKEN" ]; then echo "ok=true" >> "$GITHUB_OUTPUT"; else echo "::notice::CLAUDE_CODE_OAUTH_TOKEN is not set; skipping Claude review."; fi + + - name: Checkout repository + if: steps.auth.outputs.ok == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 1 + + - name: Claude PR review + if: steps.auth.outputs.ok == 'true' + uses: anthropics/claude-code-action@cab360f6565aa35a51d6ce9e43f1f4287c0a32ea # v1.0.241 + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + track_progress: true + prompt: | + REPO: ${{ github.repository }} + PR NUMBER: ${{ github.event.pull_request.number }} + + Review this pull request. Focus on correctness bugs, security issues, + error handling and edge cases, and missing tests for changed behaviour. + Skip style nits. Use inline comments for specific issues and one short + top-level summary comment. + claude_args: | + --allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"