Skip to content

Commit 3f780b2

Browse files
committed
ci(osv-scanner): fix issue when no old result
1 parent 795ce6a commit 3f780b2

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

‎.github/workflows/osv-scanner-pr.yml‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,23 @@ jobs:
5454
# from the old results (by id or alias), i.e. introduced by the PR, as
5555
# a table like the one from osv-scanner's reporter, with the columns
5656
# 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}" '
6074
def pad($w): . + ((" " * ($w - length)) // "");
6175
def rating:
6276
if . == null or . == 0 then "Unknown"
@@ -100,7 +114,7 @@ jobs:
100114
"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")).",
101115
"",
102116
$border, row($table[0]), $border, ($table[1:][] | row(.)), $border
103-
' "${RUNNER_TEMP}/osv/new-results.json")"
117+
' "${new}")"
104118
if [ -z "${table}" ]; then
105119
exit 0
106120
fi

0 commit comments

Comments
 (0)