@@ -31,55 +31,53 @@ steps:
3131 - scan :
3232 command :
3333 run : |
34- set -eu # fail on errors, but ignore unset vars in our loops
34+ set -eu
3535
36- # Ensure Directory.Packages.props exists
37- if [ ! -f "Directory.Packages.props" ]; then
38- cat > Directory.Packages.props <<'EOF'
39- <Project>
40- <ItemGroup></ItemGroup>
41- </Project>
42- EOF
43- fi
36+ SCAN_TARGET=""
4437
45- # Create temporary solution
46- dotnet new sln -n temp > /dev/null 2>&1
38+ # Find all .csproj files once (search up to depth 5 for performance)
39+ PROJECT_LIST=$(find . -maxdepth 5 -name "*.csproj" -type f)
4740
48- # Find all .csproj files
49- PROJECTS=$(find . -name "*.csproj")
41+ if [ -z "$PROJECT_LIST" ]; then
42+ echo "No projects found."
43+ exit 1
44+ fi
5045
51- # Temporary file for valid projects
52- VALID_PROJECTS=$(mktemp)
46+ # Create temporary solution to merge all projects
47+ dotnet new sln -n temp --force >/dev/null 2>&1 || true
5348
54- # Check which projects can be restored
55- for proj in $PROJECTS; do
56- if dotnet restore "$proj" --ignore-failed-sources --no-cache > /dev/null 2>&1; then
57- echo "$proj" >> "$VALID_PROJECTS"
58- fi
49+ # Add all found .csproj files to the solution
50+ echo "$PROJECT_LIST" | while IFS= read -r proj; do
51+ [ -n "$proj" ] && dotnet sln temp.sln add "$proj" >/dev/null 2>&1 || true
5952 done
6053
61- # Add only valid projects to solution
62- while read -r proj; do
63- dotnet sln temp.sln add "$proj" > /dev/null 2>&1
64- done < "$VALID_PROJECTS"
54+ SCAN_TARGET="./temp.sln"
55+
56+ # Restore packages while ignoring errors.
57+ if [ -n "$SCAN_TARGET" ]; then
58+ dotnet restore "$SCAN_TARGET" --ignore-failed-sources --no-cache >/dev/null 2>&1 || true
59+ fi
6560
66- rm "$VALID_PROJECTS"
61+ # Generate SBOM to temporary directory
62+ OUTPUT_DIR="temp_sbom_output"
63+ rm -rf "$OUTPUT_DIR" 2>/dev/null || true
6764
68- # Restore valid projects (ignore errors)
69- dotnet restore temp.sln --ignore-failed-sources --no-cache > /dev/null 2>&1 || true
65+ if [ -n "$SCAN_TARGET" ] && dotnet CycloneDX "$SCAN_TARGET" \
66+ --disable-package-restore \
67+ --output "$OUTPUT_DIR" \
68+ --output-format json \
69+ >/dev/null 2>&1; then
7070
71- # Generate SBOM, only stdout is the BOM
72- if $SETUP_PATH/scan-tools/.dotnet-tools/dotnet-CycloneDX $(pwd)/temp.sln \
73- --disable-package-restore --output temp_sbom.json --output-format json > /dev/null 2>&1; then
74- if [ -f "temp_sbom.json/bom.json" ]; then
75- cat temp_sbom.json/bom.json
76- else
77- # SBOM file missing but no fatal error
78- echo "{}"
79- fi
71+ if [ -f "$OUTPUT_DIR/bom.json" ]; then
72+ cat "$OUTPUT_DIR/bom.json"
73+ rm -rf "$OUTPUT_DIR"
74+ else
75+ echo "SBOM result missing."
76+ exit 1
77+ fi
8078 else
81- # CycloneDX failed but do not output logs, just empty JSON
82- echo "{}"
79+ echo " CycloneDX failed to generate SBOM."
80+ exit 1
8381 fi
8482
8583 format : cyclonedx
0 commit comments