fix: robustly parse distro from in-build SBOM package PURLs
CI Tests / JS Unit Tests (pull_request) Successful in 8s
Philipp/Global-Workflows: Pre-commit Lint (Scoped) / pre-commit (pull_request) Successful in 1m35s
CI Tests / cross-check-mixed-sbom (sbom=false) (pull_request) Successful in 3m3s
CI Tests / cross-check-mixed-sbom (sbom=true) (pull_request) Successful in 3m11s
CI Tests / without-inbuild-sbom (sbom=false) (pull_request) Successful in 7m2s
CI Tests / without-inbuild-sbom (sbom=true) (pull_request) Successful in 5m32s
CI Tests / with-inbuild-sbom (sbom=false) (pull_request) Successful in 5m32s
CI Tests / with-inbuild-sbom (sbom=true) (pull_request) Successful in 1m49s

This commit is contained in:
Philipp committed 2026-09-14 23:37:07 +02:00
1 parent 3b9043a746
commit 64747ec466
1 file changed
+27 -18
+27 -18
View File
@@ -310,6 +310,31 @@ runs:
target_summary=()
use_inbuild="${{ inputs.use-inbuild-sbom }}"
detect_distro() {
node -e '
const fs = require("fs");
try {
const data = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
let name, ver;
for (const pkg of (data.packages || [])) {
for (const ref of (pkg.externalRefs || [])) {
if (ref.referenceType === "purl" && ref.referenceLocator) {
const mName = ref.referenceLocator.match(/[?&]os_name=([^&]+)/);
const mVer = ref.referenceLocator.match(/[?&]os_version=([^&]+)/);
if (mName && mVer) {
name = mName[1];
ver = mVer[1];
break;
}
}
}
if (name && ver) break;
}
if (name && ver) console.log(name + "/" + ver);
} catch (e) {}
' "$1" 2>/dev/null || true
}
# 1. Scan Head SBOMs
if [ ${#head_sboms[@]} -eq 0 ]; then
head_ok=false
@@ -323,15 +348,7 @@ runs:
echo "Scanning head SBOM for architecture: $arch"
distro_arg=""
if [ "$use_inbuild" = "true" ]; then
detected_distro=$(node -e '
const fs = require("fs");
const content = fs.readFileSync(process.argv[1], "utf8");
const nameMatch = content.match(/[?&]os_name=([^&"\s]+)/);
const verMatch = content.match(/[?&]os_version=([^&"\s]+)/);
if (nameMatch && verMatch) {
console.log(`${nameMatch[1]}/${verMatch[1]}`);
}
' "$f" 2>/dev/null || true)
detected_distro=$(detect_distro "$f")
if [ -n "$detected_distro" ]; then
echo "Detected distribution '${detected_distro}' from in-build SBOM PURLs. Scanning with --distro."
distro_arg="--distro ${detected_distro}"
@@ -405,15 +422,7 @@ runs:
echo "Scanning target SBOM for architecture: $arch"
distro_arg=""
if [ "$use_inbuild" = "true" ]; then
detected_distro=$(node -e '
const fs = require("fs");
const content = fs.readFileSync(process.argv[1], "utf8");
const nameMatch = content.match(/[?&]os_name=([^&"\s]+)/);
const verMatch = content.match(/[?&]os_version=([^&"\s]+)/);
if (nameMatch && verMatch) {
console.log(`${nameMatch[1]}/${verMatch[1]}`);
}
' "$f" 2>/dev/null || true)
detected_distro=$(detect_distro "$f")
if [ -n "$detected_distro" ]; then
echo "Detected distribution '${detected_distro}' from in-build SBOM PURLs. Scanning with --distro."
distro_arg="--distro ${detected_distro}"