Skip to content

Commit 3fc2968

Browse files
authored
ci: fix security scan checks on PR runs (#2246)
1 parent 21c000d commit 3fc2968

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

.github/workflows/security-scan.yaml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,34 @@ on:
33
push:
44
branches: [master]
55
paths: [pixi.lock]
6+
# No path filter, a required check must report on every PR
67
pull_request:
78
branches: [master]
8-
paths: [pixi.lock]
99
schedule:
1010
- cron: "0 6 * * *"
1111
workflow_dispatch:
1212

1313
jobs:
14+
changes:
15+
name: Detect pixi.lock changes
16+
if: github.event_name == 'pull_request'
17+
runs-on: ubuntu-latest
18+
outputs:
19+
pixi: ${{ steps.diff.outputs.pixi }}
20+
steps:
21+
- id: diff
22+
env:
23+
GH_TOKEN: ${{ github.token }}
24+
run: |
25+
files=$(gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" --paginate --jq '.[].filename')
26+
grep -qxF pixi.lock <<< "$files" && pixi=true || pixi=false
27+
echo "pixi=$pixi" >> "$GITHUB_OUTPUT"
28+
1429
scan:
1530
name: SBOM and vulnerability scan
31+
needs: changes
32+
# Skip only when pixi.lock is confirmed unchanged
33+
if: ${{ !cancelled() && !(needs.changes.result == 'success' && needs.changes.outputs.pixi == 'false') }}
1634
runs-on: ubuntu-latest
1735
permissions:
1836
security-events: write
@@ -56,14 +74,13 @@ jobs:
5674
mv normalized.sarif "${{ steps.scan.outputs.sarif }}"
5775
5876
- name: Upload SARIF
59-
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
77+
if: github.ref == 'refs/heads/master'
6078
uses: github/codeql-action/upload-sarif@v4
6179
with:
6280
sarif_file: ${{ steps.scan.outputs.sarif }}
6381
category: pixi-vuln-scan
6482

65-
# Fork PRs cant upload SARIF (no access to token), so code scannings native diff
66-
# does not apply. This builds our own diff from a master-uploaded SARIF artifact instead.
83+
# Baseline for the PR CVE diff below
6784
- name: Upload SARIF as artifact
6885
if: github.ref == 'refs/heads/master'
6986
uses: actions/upload-artifact@v7
@@ -72,10 +89,9 @@ jobs:
7289
path: ${{ steps.scan.outputs.sarif }}
7390
retention-days: 30
7491

75-
# Fork PRs cant upload SARIF to code scanning (no token write access), so
76-
# diff against the master baseline artifact here instead
77-
- name: Download master baseline (fork PRs only)
78-
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
92+
# All PRs gate on new CVEs vs the master baseline
93+
- name: Download master baseline
94+
if: github.event_name == 'pull_request'
7995
uses: dawidd6/action-download-artifact@v21
8096
with:
8197
workflow: security-scan.yaml
@@ -84,8 +100,8 @@ jobs:
84100
if_no_artifact_found: fail
85101
path: master-baseline
86102

87-
- name: Fail on new CVEs (fork PRs only)
88-
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
103+
- name: Fail on new CVEs
104+
if: github.event_name == 'pull_request'
89105
env:
90106
SARIF_PATH: ${{ steps.scan.outputs.sarif }}
91107
run: |

0 commit comments

Comments
 (0)