|
| 1 | +# =============================================================== |
| 2 | +# 🛡️ OSV-Scanner – Open-Source Vulnerability Scan Workflow |
| 3 | +# =============================================================== |
| 4 | +# |
| 5 | +# This workflow: |
| 6 | +# • **scan-pr** ─ Diffs dependency changes in every PR / merge-queue |
| 7 | +# and fails only if the PR introduces *new* vulns. |
| 8 | +# • **scan-scheduled** ─ Runs a full scan of the default branch |
| 9 | +# on pushes & weekly cron to catch newly-published CVEs. |
| 10 | +# • Uploads SARIF results to “Security → Code scanning”. |
| 11 | +# |
| 12 | +# Action reference: |
| 13 | +# • Docs: https://google.github.io/osv-scanner/github-action/ |
| 14 | +# • Repo: https://github.com/google/osv-scanner-action (Apache-2.0) |
| 15 | +# |
| 16 | +# Tips: |
| 17 | +# • Ignore a CVE by creating .osv-scanner.toml or using --ignore-vuln. |
| 18 | +# • Add “--skip-git” so the scan isn’t cluttered with .git metadata. |
| 19 | +# =============================================================== |
| 20 | + |
| 21 | +name: OSV-Scanner |
| 22 | + |
| 23 | +on: |
| 24 | + # ───────── Pull-request diff scan ───────── |
| 25 | + pull_request: |
| 26 | + branches: [ "main" ] |
| 27 | + merge_group: |
| 28 | + branches: [ "main" ] |
| 29 | + |
| 30 | + # ───────── Full scans ───────── |
| 31 | + push: |
| 32 | + branches: [ "main" ] |
| 33 | + schedule: |
| 34 | + - cron: '20 22 * * 0' # Sunday @ 22:20 UTC |
| 35 | + |
| 36 | +# ----------------------------------------------------------------- |
| 37 | +# Least-privilege permissions |
| 38 | +# ----------------------------------------------------------------- |
| 39 | +permissions: |
| 40 | + contents: read # checkout / version diff |
| 41 | + security-events: write # upload SARIF results |
| 42 | + actions: read # needed by upload-sarif for private repos |
| 43 | + |
| 44 | +jobs: |
| 45 | + # ============================================================= |
| 46 | + # 1️⃣ Full scan on push / cron |
| 47 | + # ============================================================= |
| 48 | + scan-scheduled: |
| 49 | + if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} |
| 50 | + uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@1f124291d8a60496dd1874b24b62b2370ed4c78" # v1.7.1 |
| 51 | + with: |
| 52 | + # CLI flags (line-split) |
| 53 | + scan-args: |- |
| 54 | + -r # recurse into sub-dirs |
| 55 | + --skip-git # ignore .git dir |
| 56 | + ./ # repo root |
| 57 | +
|
| 58 | + # ============================================================= |
| 59 | + # 2️⃣ Diff scan on PR / merge-queue |
| 60 | + # Fails if the PR adds *new* vulns vs. base branch |
| 61 | + # ============================================================= |
| 62 | + scan-pr: |
| 63 | + if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }} |
| 64 | + uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@1f124291d8a60496dd1874b24b62b2370ed4c78" # v1.7.1 |
| 65 | + with: |
| 66 | + scan-args: |- |
| 67 | + -r |
| 68 | + --skip-git |
| 69 | + ./ |
| 70 | + # Fail the check when new vulns are introduced (default true) |
| 71 | + fail-on-vuln: true |
0 commit comments