-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (60 loc) · 2.45 KB
/
Copy pathpr-scan.yml
File metadata and controls
64 lines (60 loc) · 2.45 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
name: Dependency scan
on:
pull_request:
branches: [main]
# One run per PR: rapid pushes must not interleave the sticky-comment find-then-post.
concurrency:
group: pr-scan-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: read
security-events: write
pull-requests: write
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build
# vetguard is published, but this dogfoods the flow from the local build so
# it scans the code in the PR, not a released version. External consumers use
# the published action (see README). This workflow is informational: it
# tolerates exit 1 (findings) but fails on exit >= 2 (a scanner crash), so a
# broken build cannot masquerade as a clean, empty report.
- name: Scan dependencies (SARIF)
run: |
set +e
node dist/cli.js scan . --sarif > vetguard.sarif
code=$?
set -e
if [ "$code" -ge 2 ]; then echo "vetguard exited $code (scan error)"; exit "$code"; fi
- name: Scan dependencies (summary + sticky PR comment)
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
set +e
node dist/cli.js scan . --markdown | tee vetguard-report.md >> "$GITHUB_STEP_SUMMARY"
code=${PIPESTATUS[0]}
set -e
if [ "$code" -ge 2 ]; then echo "vetguard exited $code (scan error)"; exit "$code"; fi
# Match our marker AND the actions-bot author so a PR author cannot redirect the update.
existing=$(gh api "repos/${REPO}/issues/${PR}/comments" \
--jq 'map(select((.body | contains("<!-- vetguard-report -->")) and .user.login == "github-actions[bot]")) | .[0].id // empty' 2>/dev/null || true)
if [ -n "$existing" ]; then
gh api -X PATCH "repos/${REPO}/issues/comments/${existing}" -F body=@vetguard-report.md >/dev/null || true
else
gh api -X POST "repos/${REPO}/issues/${PR}/comments" -F body=@vetguard-report.md >/dev/null || true
fi
- name: Upload SARIF
if: always()
continue-on-error: true
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: vetguard.sarif