Repository navigation
83 lines (76 loc) · 3.83 KB
/
Copy pathpr-review.yml
File metadata and controls
83 lines (76 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: pr-review
# K2 — scan the diff on a pull request and comment the proposed band-aid.
#
# Deliberately NOT part of `ci.yml`: that workflow is the test gate and must stay green, fast and
# free of model credentials. This one spends model calls and needs write access to comment, so it is
# its own workflow with its own permissions and can be disabled without touching the tests.
#
# `pull_request` (not `pull_request_target`) is the safe trigger: it runs with a read-only token
# against the merge commit and cannot be used by a fork to exfiltrate secrets. The consequence is
# that PRs from forks get no secrets and therefore no review — the right trade, and stated in
# docs/CI.md rather than discovered.
on:
pull_request:
# Scoped to the directory the action below actually SCANS, not to every code file in the repo.
# A `**/*.py` filter fired on any change — including this repo's own `src/vpcopilot/**` — and
# then scanned zero files, because `repo-path` points at the demo app. That spends a model
# credential and a runner to review nothing. Point both at the same place, or the trigger and
# the scan disagree about what this workflow is for.
paths:
- "bench/fixtures/nimbus-vuln-lab/app/src/app/api/**"
- ".github/workflows/pr-review.yml"
- ".github/actions/vpcopilot-scan/**"
workflow_dispatch:
permissions:
contents: read
pull-requests: write # to leave the review comment, and nothing else
concurrency:
# A pushed branch cancels its own in-flight review rather than racing two comments.
group: pr-review-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
review:
# Two reasons to skip rather than fail. A fork PR has no access to secrets, so the scan could not
# run; and a repository that has not set ANTHROPIC_API_KEY has nothing to run it with. Neither is
# something the PR author can fix, and a permanently red check is a check people learn to ignore.
# Skipping is safe here only because the action itself fails loudly on an empty key — so the
# combination cannot produce a green check for a review that did not happen.
if: >-
(github.event.pull_request.head.repo.full_name == github.repository
|| github.event_name == 'workflow_dispatch')
&& github.event.repository.fork == false
runs-on: ubuntu-latest
env:
# Read once at job level so both the skip note and the review step key off the same value.
MODEL_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
steps:
- name: Say so when there is no model credential to scan with
if: env.MODEL_KEY == ''
run: |
{
echo "## The PR review was skipped"
echo
echo "\`ANTHROPIC_API_KEY\` is not set for this repository, so there is nothing to scan"
echo "with. **This is not a clean bill of health** — the diff was not reviewed."
echo
echo "Set the secret, or run \`vpcopilot ci-review\` locally (see docs/CI.md)."
} >> "$GITHUB_STEP_SUMMARY"
- uses: actions/checkout@v4
if: env.MODEL_KEY != ''
with:
# `git merge-base` needs history on both sides; the default single-commit fetch has none.
fetch-depth: 0
- name: Review the diff
if: env.MODEL_KEY != ''
uses: ./.github/actions/vpcopilot-scan
with:
# The demo app this repo carries. Point this at your own source directory.
repo-path: bench/fixtures/nimbus-vuln-lab/app/src/app/api
min-severity: high
max-files: 40
comment: "true"
# The comment is the deliverable; a red check on an accepted finding is how a useful bot
# gets switched off.
fail-on-findings: "false"
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
github-token: ${{ github.token }}