|
3 | 3 | push: |
4 | 4 | branches: [master] |
5 | 5 | paths: [pixi.lock] |
| 6 | + # No path filter, a required check must report on every PR |
6 | 7 | pull_request: |
7 | 8 | branches: [master] |
8 | | - paths: [pixi.lock] |
9 | 9 | schedule: |
10 | 10 | - cron: "0 6 * * *" |
11 | 11 | workflow_dispatch: |
12 | 12 |
|
13 | 13 | 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 | +
|
14 | 29 | scan: |
15 | 30 | 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') }} |
16 | 34 | runs-on: ubuntu-latest |
17 | 35 | permissions: |
18 | 36 | security-events: write |
@@ -56,14 +74,13 @@ jobs: |
56 | 74 | mv normalized.sarif "${{ steps.scan.outputs.sarif }}" |
57 | 75 |
|
58 | 76 | - 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' |
60 | 78 | uses: github/codeql-action/upload-sarif@v4 |
61 | 79 | with: |
62 | 80 | sarif_file: ${{ steps.scan.outputs.sarif }} |
63 | 81 | category: pixi-vuln-scan |
64 | 82 |
|
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 |
67 | 84 | - name: Upload SARIF as artifact |
68 | 85 | if: github.ref == 'refs/heads/master' |
69 | 86 | uses: actions/upload-artifact@v7 |
|
72 | 89 | path: ${{ steps.scan.outputs.sarif }} |
73 | 90 | retention-days: 30 |
74 | 91 |
|
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' |
79 | 95 | uses: dawidd6/action-download-artifact@v21 |
80 | 96 | with: |
81 | 97 | workflow: security-scan.yaml |
|
84 | 100 | if_no_artifact_found: fail |
85 | 101 | path: master-baseline |
86 | 102 |
|
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' |
89 | 105 | env: |
90 | 106 | SARIF_PATH: ${{ steps.scan.outputs.sarif }} |
91 | 107 | run: | |
|
0 commit comments