Files
java-devops-demo/gitea-actions/scripts/04-sbom.sh
T

34 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Look inside the CycloneDX SBOM the build produced, and show the one-line mistake that drops it from the jar.
source "$(dirname "$0")/lib.sh"
SBOM=target/classes/META-INF/sbom/application.cdx.json
JAR=target/gitea-actions-demo-1.0.0.jar
{
banner "mvn -DskipTests package (default: Spring Boot parent wiring)"
"${MVN[@]}" -DskipTests clean package 2>&1 | clean | grep -E '^\[INFO\] --- (spring-boot|cyclonedx|jar)|CycloneDX: (Creating|Writing)' | sed -E 's/ @ gitea-actions-demo//; s#/.*/target#target#'
echo "jar contains: $(unzip -l $JAR | awk '/sbom\/application/ {print $4}')"
banner "Inside $SBOM"
python3 - <<'PY'
import json, collections
b = json.load(open("target/classes/META-INF/sbom/application.cdx.json"))
print("bomFormat :", b["bomFormat"])
print("specVersion :", b["specVersion"])
m = b["metadata"]["component"]
print("subject :", m["group"] + ":" + m["name"] + ":" + m["version"], "(" + m["type"] + ")")
c = b["components"]
print("components :", len(c))
print("by scope :", dict(collections.Counter(x.get("scope", "-") for x in c)))
print("all have purl :", all("purl" in x for x in c))
print("all have hash :", all(x.get("hashes") for x in c))
for want in ("spring-boot", "postgresql", "tomcat-embed-core", "jackson-databind", "testcontainers"):
hit = [x for x in c if x["name"] == want]
print(f"{want:18s}:", hit[0]["purl"] if hit else "(not in SBOM)")
print("dependency edges:", len(b.get("dependencies", [])))
PY
banner "The mistake: -Plate-sbom (re-declares the execution with phase=package)"
"${MVN[@]}" -DskipTests -Plate-sbom clean package 2>&1 | clean | grep -E '^\[INFO\] --- (spring-boot|cyclonedx|jar)' | sed -E 's/ @ gitea-actions-demo//'
echo "jar contains: $(unzip -l $JAR | awk '/sbom\/application/ {print $4}' | head -1)"
echo "(empty above = the SBOM is not in the jar)"
"${MVN[@]}" -q -DskipTests clean package >/dev/null 2>&1
} 2>&1 | tee "$OUT/04-sbom.txt"