scan, vex: pass collected files through disk, not argv
A 230-statement VEX file (234 KB) made jq fail with 'Argument list too long' (--argjson of the accumulated array). Each file is now one JSON object in an ndjson file, slurped into the report.
This commit is contained in:
1 parent
2b4b140200
commit
0e5054f5d0
2 files changed
+11
-8
No files matched your search
+6
-5
@@ -161,16 +161,17 @@ runs:
|
||||
set -euo pipefail
|
||||
url=${PANEL_URL:-${DTRACK_URL%/}/panel-ci/report}
|
||||
images=$(printf '%s' "$IMAGES" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | { grep -v '^$' || true; } | jq -R . | jq -s .) # no images is fine
|
||||
tomls='[]'
|
||||
# Files go through disk, never argv (a big VEX file blows the limit).
|
||||
: > tomls.ndjson
|
||||
while IFS= read -r f; do
|
||||
tomls=$(jq --arg p "$f" --rawfile c "$f" '. + [{path: $p, content: $c}]' <<<"$tomls")
|
||||
jq -n --arg p "$f" --rawfile c "$f" '{path: $p, content: $c}' >> tomls.ndjson
|
||||
done < <(find "$SCAN_PATH" -name osv-scanner.toml -not -path '*/node_modules/*' -not -path '*/.git/*' | head -20)
|
||||
vex='[]'
|
||||
: > vex.ndjson
|
||||
while IFS= read -r f; do
|
||||
vex=$(jq --arg p "$f" --rawfile c "$f" '. + [{path: $p, content: $c}]' <<<"$vex")
|
||||
jq -n --arg p "$f" --rawfile c "$f" '{path: $p, content: $c}' >> vex.ndjson
|
||||
done < <(find "$SCAN_PATH" -path '*/.vex/*' -name '*.json' -not -path '*/node_modules/*' -not -path '*/.git/*' | sort | head -200)
|
||||
jq -n --arg repo "$REPO" --arg commit "$COMMIT" --arg project "$PROJECT" \
|
||||
--argjson images "$images" --argjson tomls "$tomls" --argjson vex "$vex" \
|
||||
--argjson images "$images" --slurpfile tomls tomls.ndjson --slurpfile vex vex.ndjson \
|
||||
'{repo: $repo, commit: $commit, project: $project, images: $images, osvScannerToml: $tomls, vexFiles: $vex}' > report.json
|
||||
echo "Reporting $(jq '.images | length' report.json) image(s), $(jq '.osvScannerToml | length' report.json) osv-scanner.toml file(s), $(jq '.vexFiles | length' report.json) VEX file(s) to ${url}"
|
||||
curl -fsS -X POST "$url" -H "X-Api-Key: ${DTRACK_API_KEY}" -H "Content-Type: application/json" \
|
||||
|
||||
+5
-3
@@ -45,11 +45,13 @@ runs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
url=${PANEL_URL:-${DTRACK_URL%/}/panel-ci/vex}
|
||||
files='[]'
|
||||
# One JSON object per file on disk (never as an argument: a big VEX
|
||||
# file blows the argv limit), slurped into the report.
|
||||
: > vex-files.ndjson
|
||||
while IFS= read -r f; do
|
||||
files=$(jq --arg p "$f" --rawfile c "$f" '. + [{path: $p, content: $c}]' <<<"$files")
|
||||
jq -n --arg p "$f" --rawfile c "$f" '{path: $p, content: $c}' >> vex-files.ndjson
|
||||
done < <(find "$VEX_PATH" -name '*.json' -not -path '*/.git/*' | sort | head -500)
|
||||
jq -n --arg repo "$REPO" --arg commit "$COMMIT" --argjson files "$files" \
|
||||
jq -n --arg repo "$REPO" --arg commit "$COMMIT" --slurpfile files vex-files.ndjson \
|
||||
'{repo: $repo, commit: $commit, files: $files}' > vex-report.json
|
||||
echo "Posting $(jq '.files | length' vex-report.json) VEX file(s) to ${url}"
|
||||
# -f: a rejected file (bad JSON, no justification) fails the job.
|
||||
|
||||
Reference in new issue
Block a user