11#! /bin/bash
22
3- output_file=./output.log
4-
53# ------------------------------------------------------
6- # Multi-registry auth.json creation
4+ # Main Entrypoint Orchestrator
75# ------------------------------------------------------
8- # Expected env vars:
9- # REGISTRIES="docker.io ghcr.io registry.example.com"
10- # USERNAME_<REGISTRY> and PASSWORD_<REGISTRY>
11- # Example: USERNAME_DOCKER_IO, PASSWORD_DOCKER_IO
12- # USERNAME_GHCR_IO, PASSWORD_GHCR_IO
13-
14- if [[ -n " $REGISTRIES " ]]; then
15- echo " 🔑 Creating multi-registry auth.json..."
16- mkdir -p /github/home/.config/containers
17- auths_entries=" "
18-
19- for reg in $REGISTRIES ; do
20- # Convert registry to env var friendly form (dots & dashes to underscores, uppercase)
21- env_suffix=$( echo " $reg " | tr ' .-' ' _' | tr ' [:lower:]' ' [:upper:]' )
22-
23- user_var=" USERNAME_${env_suffix} "
24- pass_var=" PASSWORD_${env_suffix} "
25-
26- user=" ${! user_var} "
27- pass=" ${! pass_var} "
28-
29- if [[ -n " $user " && -n " $pass " ]]; then
30- encoded=$( echo -n " ${user} :${pass} " | base64 -w0)
31- auths_entries+=" \" $reg \" : {\" auth\" : \" $encoded \" },"
32- echo " ✅ Added credentials for $reg "
33- else
34- echo " ⚠️ Skipping $reg — missing username/password"
35- fi
36- done
37-
38- # Remove trailing comma and wrap in JSON
39- auths_entries=" ${auths_entries% ,} "
40- echo " {\" auths\" : {${auths_entries} }}" > /github/home/.config/containers/auth.json
41- echo " ✅ Auth.json created at /github/home/.config/containers/auth.json"
42- else
43- echo " ⚠️ No REGISTRIES specified, skipping auth.json creation."
44- fi
45-
46- # Parse global params (applied to all commands)
47- if [ -n " ${GLOBAL_PARAMS} " ]; then
48- eval " global_arr=(${GLOBAL_PARAMS} )"
49- else
50- global_arr=()
51- fi
52-
53- # Parse scan-specific params
54- if [ -n " ${SCAN_PARAMS} " ]; then
55- eval " scan_arr=(${SCAN_PARAMS} )"
56- else
57- scan_arr=()
58- fi
596
60- # Parse utils-specific params
61- if [ -n " ${UTILS_PARAMS} " ]; then
62- eval " utils_arr=(${UTILS_PARAMS} )"
63- else
64- utils_arr=()
65- fi
7+ # 1. Setup Global Variables
8+ export output_file=./output.log
9+ echo " Server URL: $GITHUB_SERVER_URL "
6610
67- # Parse results-specific params
68- if [ -n " ${RESULTS_PARAMS} " ]; then
69- eval " results_arr=(${RESULTS_PARAMS} )"
11+ # 2. Determine Environment (Cloud vs On-Prem)
12+ if [ " $GITHUB_SERVER_URL " = " https://github.com" ]; then
13+ echo " Detected GitHub Cloud"
14+ export IS_CLOUD=true
7015else
71- results_arr=()
16+ echo " Detected GitHub Enterprise Server"
17+ export IS_CLOUD=false
7218fi
7319
74- # Backward compatibility: Support ADDITIONAL_PARAMS
75- if [ -n " ${ADDITIONAL_PARAMS} " ] && [ -z " ${SCAN_PARAMS} " ]; then
76- echo " ⚠️ ADDITIONAL_PARAMS is deprecated. Please use SCAN_PARAMS instead."
77- eval " scan_arr=(${ADDITIONAL_PARAMS} )"
78- fi
79-
80- # Combine global + scan-specific params
81- combined_scan_params=(" ${global_arr[@]} " " ${scan_arr[@]} " )
82-
20+ # A. Multi-Registry Authentication
21+ source /app/scripts/auth.sh
8322
84- /app/bin/cx scan create --project-name " ${PROJECT_NAME} " -s " ${SOURCE_DIR} " --branch " ${BRANCH # refs / heads / } " --scan-info-format json --agent " Github Action " " ${combined_scan_params[@]} " | tee -i $output_file
85- exitCode= ${PIPESTATUS[0]}
23+ # B. Scan Execution
24+ source /app/scripts/scan.sh
8625
87- scanId=(` grep -E ' "(ID)":"((\\"|[^"])*)"' $output_file | cut -d' ,' -f1 | cut -d' :' -f2 | tr -d ' "' ` )
26+ # C. PR Decoration
27+ source /app/scripts/pr_decoration.sh
8828
89- echo " cxcli=$( cat $output_file | tr -d ' \r\n' ) " >> $GITHUB_OUTPUT
90-
91- if [ -n " $scanId " ] && [ -n " ${PR_NUMBER} " ]; then
92- echo " Creating PR decoration for scan ID:" $scanId
93- # Combine global + utils-specific params
94- combined_utils_params=(" ${global_arr[@]} " " ${utils_arr[@]} " )
95- /app/bin/cx utils pr github --scan-id " ${scanId} " --namespace " ${NAMESPACE} " --repo-name " ${REPO_NAME} " --pr-number " ${PR_NUMBER} " --token " ${GITHUB_TOKEN} " " ${combined_utils_params[@]} "
96- else
97- echo " PR decoration not created."
98- fi
99-
100-
101- if [ -n " $scanId " ]; then
102- # Combine global + results-specific params
103- combined_results_params=(" ${global_arr[@]} " " ${results_arr[@]} " )
104- /app/bin/cx results show --scan-id " ${scanId} " --report-format markdown " ${combined_results_params[@]} "
105- cat ./cx_result.md > $GITHUB_STEP_SUMMARY
106- rm ./cx_result.md
107- echo " cxScanID=$scanId " >> $GITHUB_OUTPUT
108- fi
29+ # D. Results Reporting
30+ source /app/scripts/results.sh
10931
110- if [ $exitCode -eq 0 ]
111- then
112- echo " Scan completed"
32+ # 4. Final Exit Handling
33+ if [ $exitCode -eq 0 ] ; then
34+ echo " Scan completed successfully. "
11335else
114- echo " Scan failed"
115- exit $exitCode
36+ echo " Scan failed. "
37+ exit $exitCode
11638fi
0 commit comments