|
54 | 54 | # from the old results (by id or alias), i.e. introduced by the PR, as |
55 | 55 | # a table like the one from osv-scanner's reporter, with the columns |
56 | 56 | # the results give directly; print nothing if there are none. A jq |
57 | | - # failure (e.g. missing or malformed results) aborts the step via |
58 | | - # set -e instead of being mistaken for "no new vulnerabilities". |
59 | | - table="$(jq -r --slurpfile old "${RUNNER_TEMP}/osv/old-results.json" ' |
| 57 | + # failure (e.g. malformed results) aborts the step via set -e |
| 58 | + # instead of being mistaken for "no new vulnerabilities". |
| 59 | + old="${RUNNER_TEMP}/osv/old-results.json" |
| 60 | + new="${RUNNER_TEMP}/osv/new-results.json" |
| 61 | + # The scanner exits successfully without writing results when it |
| 62 | + # finds no lockfiles (a failed scan without results already fails |
| 63 | + # the reusable workflow), so a missing file means nothing was |
| 64 | + # scanned: no new results means nothing to check, and no old |
| 65 | + # results means every new vulnerability is introduced by the PR. |
| 66 | + if [ ! -e "${new}" ]; then |
| 67 | + echo "::notice::No OSV scan results for this PR (no lockfiles found), nothing to check." |
| 68 | + exit 0 |
| 69 | + fi |
| 70 | + if [ ! -e "${old}" ]; then |
| 71 | + old=/dev/null |
| 72 | + fi |
| 73 | + table="$(jq -r --slurpfile old "${old}" ' |
60 | 74 | def pad($w): . + ((" " * ($w - length)) // ""); |
61 | 75 | def rating: |
62 | 76 | if . == null or . == 0 then "Unknown" |
@@ -100,7 +114,7 @@ jobs: |
100 | 114 | "Total \($packages) \(form($packages; "package"; "packages")) affected by \($rows | length) new \(form($rows | length; "vulnerability"; "vulnerabilities")) (\($ratings.Critical // 0) Critical, \($ratings.High // 0) High, \($ratings.Medium // 0) Medium, \($ratings.Low // 0) Low, \($ratings.Unknown // 0) Unknown) from \($ecosystems) \(form($ecosystems; "ecosystem"; "ecosystems")).", |
101 | 115 | "", |
102 | 116 | $border, row($table[0]), $border, ($table[1:][] | row(.)), $border |
103 | | - ' "${RUNNER_TEMP}/osv/new-results.json")" |
| 117 | + ' "${new}")" |
104 | 118 | if [ -z "${table}" ]; then |
105 | 119 | exit 0 |
106 | 120 | fi |
|
0 commit comments