Skip to content

Commit 5a5b33f

Browse files
committed
Refine the run-scan.sh script to support multiple pipelines
Signed-off-by: tdruez <[email protected]>
1 parent bd92879 commit 5a5b33f

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

etc/scripts/run-scan.sh

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,52 @@
88
# ScanCode is a trademark of nexB Inc.
99

1010
# Usage:
11-
# Scan current directory with default pipeline 'scan_codebase':
12-
# ./run-scan.sh
11+
# Default scan of current directory using 'scan_codebase':
12+
# ./run-scan.sh
1313
#
14-
# Scan a specific directory with a custom pipeline:
15-
# ./run-scan.sh /path/to/scan/dir scan_single_package
14+
# Run pipelines on current directory:
15+
# ./run-scan.sh scan_codebase find_vulnerabilities
1616
#
17-
# Scan a specific directory with multiple pipelines:
18-
# ./run-scan.sh /path/to/scan/dir "scan_codebase find_vulnerabilities"
17+
# Run pipelines on a specific directory:
18+
# ./run-scan.sh scan_codebase /path/to/scan/dir
19+
#
20+
# Run multiple pipelines on a specific directory (directory must come last):
21+
# ./run-scan.sh scan_codebase find_vulnerabilities /my/codebase
22+
#
23+
# Scan a directory using default pipeline:
24+
# ./run-scan.sh /path/to/codebase
1925

2026
set -e
2127

22-
# Use first argument as scan directory or default to current directory
23-
SCAN_DIR="${1:-$(pwd)}"
24-
# Use second argument as pipeline name or default to 'scan_codebase'
25-
PIPELINE="${2:-scan_codebase}"
26-
SCIO_DOCKER_IMAGE="ghcr.io/aboutcode-org/scancode.io:latest"
27-
RESULTS_LOCATION="results.json"
28-
ABS_RESULTS_PATH="$(pwd)/$RESULTS_LOCATION"
28+
readonly SCIO_DOCKER_IMAGE="ghcr.io/aboutcode-org/scancode.io:latest"
29+
readonly RESULTS_LOCATION="results.json"
30+
31+
# Default values
32+
SCAN_DIR="$(pwd)"
33+
PIPELINES=()
34+
35+
# Check if last argument is a directory
36+
LAST_ARG="${!#}"
37+
if [ -d "$LAST_ARG" ]; then
38+
SCAN_DIR="$LAST_ARG"
39+
PIPELINES=("${@:1:$#-1}") # All args except last
40+
else
41+
PIPELINES=("$@")
42+
fi
2943

30-
# Run the pipeline
44+
# Default pipeline if none specified
45+
if [ "${#PIPELINES[@]}" -eq 0 ]; then
46+
PIPELINES=("scan_codebase")
47+
fi
48+
49+
# Run the scan
3150
docker run --rm \
3251
-v "$SCAN_DIR":/codebase \
3352
"$SCIO_DOCKER_IMAGE" \
34-
run $PIPELINE /codebase \
53+
run "${PIPELINES[@]}" /codebase \
3554
> "$RESULTS_LOCATION"
3655

37-
# Check if docker run succeeded
38-
if [ $? -eq 0 ]; then
39-
echo "✅ Scan complete using pipeline '$PIPELINE'. Results saved to $ABS_RESULTS_PATH"
40-
else
41-
echo "❌ Scan failed. Please check the error messages above."
42-
exit 1
43-
fi
56+
ABS_RESULTS_PATH="$(pwd)/$RESULTS_LOCATION"
57+
58+
echo "✅ Scan complete using pipeline(s): ${PIPELINES[*]}"
59+
echo "💾 Results saved to: $ABS_RESULTS_PATH"

0 commit comments

Comments
 (0)