6565
6666
6767# to check though:
68- diff -q <( tail -n 269 " $0 " | head -n 267 | shasum -a 384 -t -) <( tail -n 1 " $0 " ) || exit 70 ;
68+ diff -q <( tail -n 300 " $0 " | head -n 298 | shasum -a 384 -t -) <( tail -n 1 " $0 " ) || exit 70 ;
6969
7070ulimit -t 90
7171PATH=" /bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:${PATH} "
@@ -76,17 +76,42 @@ DS_TAG="0.8.6" # circa 2025
7676umask 127
7777
7878LOCK_FILE=" ${TMPDIR:-/ tmp} /org.pak.tests.scripts.code-climate.lock"
79- EXIT_CODE=0
80-
81- test -x " $( command -v grep) " || exit 126 ;
82- test -x " $( command -v sed) " || exit 126 ;
83- test -x " $( command -v curl) " || exit 126 ;
84- test -x " $( command -v mkdir) " || exit 126 ;
85- hash -p ./.github/tool_shlock_helper.sh shlock || exit 255 ;
86- test -x " $( command -v shlock) " || exit 126 ;
87- test -x " $( command -v gpgv) " || exit 126 ;
88- test -x " $( command -v shasum) " || exit 126 ;
89- test -x " $( command -v tar) " || exit 126 ;
79+ EXIT_CODE=1
80+ # Function to check if a command exists.
81+
82+ # USAGE:
83+ # ~$ check_command CMD
84+ # Arguments:
85+ # CMD (Required) -- Name of the command to check
86+ # Results:
87+ # exits 64 -- missing required argument
88+ # exits 126 -- check complete and has failed, can not find given command.
89+ # returns successful -- check complete and command found to be executable.
90+ function check_command() {
91+ test -z " $1 " && { printf " %s\n" " Error: command name is required to check for existence." >&2 ; exit 64 ; } ;
92+ local cmd=" $1 " ;
93+ # shellcheck disable=SC2086
94+ test -x " $( command -v ${cmd} ) " || { printf " %s\n" " Error: Required command '$cmd ' is not found." >&2 ; exit 126 ; } ;
95+ } # end check_command()
96+ # propagate/export function to sub-shells
97+ export -f check_command
98+
99+ # Set up CEP-5 shlock helper
100+ hash -p ./.github/tool_shlock_helper.sh shlock || { printf " %s\n" " Error: Failed to register shlock helper. CEP-5 locking will not work." >&2 ; exit 78 ; } ;
101+ check_command cat ;
102+ check_command chmod ;
103+ check_command curl ;
104+ check_command git ;
105+ check_command grep ;
106+ check_command gpg ;
107+ check_command mkdir ;
108+ check_command sed ; # but will try jq first
109+ check_command shasum ;
110+ check_command shlock ;
111+ check_command tar ;
112+ check_command uname ;
113+
114+ SCRIPT_FILE=" tests/fetch-test-reporter"
90115
91116# Detect the operating system
92117case " $( command uname -s ) " in
@@ -140,24 +165,25 @@ function cleanup() {
140165 unset CI_ENV_PREFIX 2> /dev/null || :
141166 unset CI_OS 2> /dev/null || :
142167 unset ARCH 2> /dev/null || :
168+ unset DS_TAG 2> /dev/null || :
143169 hash -d shlock 2> /dev/null > /dev/null || : ;
144170}
145171
146172if [[ ( $( shlock -f " ${LOCK_FILE} " -p $$ ) -eq 0 ) ]] ; then
147- trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 129 ;' SIGHUP || EXIT_CODE=129
148- trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 143 ;' SIGTERM || EXIT_CODE=143
149- trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 131 ;' SIGQUIT || EXIT_CODE=131
150- # SC2173 - https://github.com/koalaman/shellcheck/wiki/SC2173
151- # trap 'cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 1 ;' SIGSTOP || EXIT_CODE=7
152- trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 130 ;' SIGINT || EXIT_CODE=130
153- trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || true || : ; wait ; exit 137 ;' SIGABRT || EXIT_CODE=137
154- trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit ${EXIT_CODE} ;' EXIT || EXIT_CODE=1
155- trap ' cleanup ; wait ; exit ${EXIT_CODE} ;' EXIT || EXIT_CODE=1
173+ EXIT_CODE=0
174+ trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 129 ;' SIGHUP || EXIT_CODE=129
175+ trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 143 ;' SIGTERM || EXIT_CODE=143
176+ trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 131 ;' SIGQUIT || EXIT_CODE=131
177+ # SC2173 - https://github.com/koalaman/shellcheck/wiki/SC2173
178+ # trap 'cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 1 ;' SIGSTOP || EXIT_CODE=7
179+ trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 130 ;' SIGINT || EXIT_CODE=130
180+ trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit 137 ;' SIGABRT || EXIT_CODE=137
181+ trap ' cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null > /dev/null || : ; wait ; exit ${EXIT_CODE} ;' EXIT || EXIT_CODE=1
182+ trap ' cleanup ; wait ; exit ${EXIT_CODE} ;' EXIT || EXIT_CODE=1
156183else
157- # shellcheck disable=SC2046
158- printf " \t%s\n" " CodeClimate already in progress by " $( head " ${LOCK_FILE} " ) >&2 ;
159- false ;
160- exit 126 ;
184+ # shellcheck disable=SC2046
185+ printf " \t%s\n" " Fetch Tool already in progress by " $( head " ${LOCK_FILE} " ) >&2 ;
186+ exit 126 ;
161187fi
162188
163189# this is how test files are found:
187213# ########################
188214# actual Work starts here
189215# ########################
190- curl -fLso ./test-reporter-latest-${CI_ENV_PREFIX} https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${CI_ENV_PREFIX} ;
216+ curl -fLso ./test-reporter-latest-${CI_ENV_PREFIX} " https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${CI_ENV_PREFIX} " ;
191217for i in 1 256 512 ; do
192218 curl -fLso test-reporter-latest-${CI_ENV_PREFIX} .sha${i} " https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${CI_ENV_PREFIX} .sha${i} " ; wait ;
193219 curl -fLso test-reporter-latest-${CI_ENV_PREFIX} .sha${i} .sig " https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${CI_ENV_PREFIX} .sha${i} .sig" ; wait ;
@@ -196,15 +222,15 @@ for i in 1 256 512 ; do
196222 if [[ ${i} -eq 1 ]]; then
197223 printf " %s\n" " WARNING: SHA-1 is deprecated and should be avoided when possible. Consider using SHA-256 or SHA-512 for stronger integrity checks. (CWE-327: Use of a Broken or Risky Cryptographic Algorithm)"
198224 fi
199- if [[ ( -r test-reporter-latest-${CI_OS :- linux} - ${ARCH :- amd64 } .sha${i} .sig ) ]] ; then
225+ if [[ ( -r test-reporter-latest-${CI_ENV_PREFIX } .sha${i} .sig ) ]] ; then
200226 # configure your CI evironment to trust the key at gpg --keyserver keys.openpgp.org --recv-keys 9BD9E2DD46DA965A537E5B0A5CBF320243B6FD85
201227 # FP: KEY FP 9BD9 E2DD 46DA 965A 537E 5B0A 5CBF 3202 43B6 FD85
202228 # OR...
203229 # Set CI=true to continue on missing keys
204230 gpg --verify test-reporter-latest-${CI_ENV_PREFIX} .sha${i} .sig test-reporter-latest-${CI_ENV_PREFIX} .sha${i} || ${CI} 2> /dev/null || ${CIRCLECI} 2> /dev/null || EXIT_CODE=126
205231 rm -vf test-reporter-latest-${CI_ENV_PREFIX} .sha${i} .sig 2> /dev/null ;
206232 fi
207- shasum -a $i -c --ignore-missing test-reporter-latest-${CI_ENV_PREFIX} .sha${i} || EXIT_CODE=126
233+ shasum -a $i -c --ignore-missing test-reporter-latest-${CI_ENV_PREFIX} .sha${i} || EXIT_CODE=89
208234 rm -vf test-reporter-latest-${CI_ENV_PREFIX} .sha${i} 2> /dev/null ;
209235 fi
210236done
@@ -215,7 +241,8 @@ if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
215241fi
216242
217243if [[ -z ${DEEPSOURCE_DSN} ]] && [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
218- printf " %s\n" " No need for Unconfigured DeepSource." ;
244+ printf " ::notice %s::%s\n" " file=${SCRIPT_FILE} ,line=${BASH_LINENO:- 0} ,title=SKIP" \
245+ " No need for Unconfigured DeepSource." ;
219246elif [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
220247 printf " %s\n" " Detected Config for DeepSource" ;
221248
@@ -224,8 +251,9 @@ elif [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
224251
225252 # Check if the response is valid
226253 if [[ " $response " == * " Not Found" * ]]; then
227- printf " ::debug::%s\n" " Repository not found or no releases available."
228- EXIT_CODE=125
254+ printf " ::warning %s::%s\n" " file=${SCRIPT_FILE} ,line=${BASH_LINENO:- 0} ,title=${FUNCNAME:- $0 } " \
255+ " Repository not found or no releases available." >&2 ;
256+ EXIT_CODE=69
229257 fi ;
230258
231259 if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
@@ -241,16 +269,17 @@ elif [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
241269
242270 # Check if tag_name is empty
243271 if [[ ( -z " $tag_name " ) ]]; then
244- printf " ::debug::%s\n" " No tag name found in the response."
245- EXIT_CODE=125
272+ printf " ::warning %s::%s\n" " file=${SCRIPT_FILE} ,line=${BASH_LINENO:- 0} ,title=${FUNCNAME:- $0 } " \
273+ " No tag name found in the response." >&2 ;
274+ EXIT_CODE=65
246275 else
247276 printf " ::debug::%s\n" " Found version ${tag_name} for DeepSource" ;
248277 DS_TAG=" ${tag_name# v} "
249278 fi ;
250279
251280 if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
252281 printf " ::debug::%s\n" " Creating ${BINDIR} directory for DeepSource" ;
253- mkdir -m 755 " ${BINDIR} " || EXIT_CODE=66 ;
282+ mkdir -v - m 755 " ${BINDIR} " || EXIT_CODE=66 ;
254283 fi ;
255284
256285 curl -fLso " deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz" " https://github.com/DeepSourceCorp/cli/releases/download/v${DS_TAG} /deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz" || EXIT_CODE=125 ;
@@ -263,25 +292,29 @@ elif [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
263292
264293 if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
265294 printf " ::debug::%s\n" " Downloaded checksums.txt for DeepSource" ;
295+ if [[ ( -r checksums.txt ) ]] ; then
296+ shasum -a 256 -c --ignore-missing checksums.txt || EXIT_CODE=89
297+ rm -vf checksums.txt 2> /dev/null || : ;
298+ fi ;
299+ if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
300+ printf " %s\n" " Validated deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz for DeepSource" ;
301+ fi ;
266302 fi ;
267-
268- if [[ ( -r checksums.txt ) ]] ; then
269- shasum -a 256 -c --ignore-missing checksums.txt || EXIT_CODE=126
270- rm -f checksums.txt 2> /dev/null ;
271- fi ;
303+
304+ printf " ::group::%s\n" " Extracting deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz" ;
272305
273306 if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
274- printf " ::debug::%s\n " " Validated deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz for DeepSource " ;
275- tar --no-same-owner -xzf " deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz" -C " ${BINDIR} " 2> /dev/null || : ;
276- rm -f " deepsource_ ${DS_TAG} _ ${CI_OS} _ ${ARCH} .tar.gz " 2> /dev/null || EXIT_CODE=77 ;
277- rm -fRd " ${BINDIR} " /completions/ 2> /dev/null || : ;
307+ tar --no-same-owner -xzf " deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz" -C " ${BINDIR} " || : ;
308+ rm -vf " deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz" 2> /dev/null || : ;
309+ rm -vfRd " ${BINDIR} " /completions/ 2> /dev/null || : ;
310+ printf " ::debug::%s\n " " Extracted deepsource_ ${DS_TAG} _ ${CI_OS} _ ${ARCH} .tar.gz " ;
278311 fi ;
279312
313+ printf " ::endgroup::\n" ;
314+
280315 if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
281316 # ref: https://docs.deepsource.com/docs/analyzers-test-coverage#setup-test-coverage
282317 printf " ::debug::%s\n" " Extracted deepsource_${DS_TAG} _${CI_OS} _${ARCH} .tar.gz" ;
283- #{ cat ./ds-cli.sh | sh - | grep -o " (:?version).{1}\s[0-9].[0-9].[0-9]" ; } ; wait ;
284- # printf "::endgroup::\n" ;
285318 if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
286319 printf " ::debug::%s\n" " Checking for DeepSource CLI" ;
287320 if [[ ( -d " ${BINDIR} " ) ]] ; then
@@ -301,21 +334,19 @@ elif [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
301334 else
302335 printf " ::debug::..=> %s\n" " Missing ${BINDIR} /deepsource CLI tool" ;
303336 EXIT_CODE=66 ;
304- printf " ::debug::..=> %s\n" " Checking if ${BINDIR} is empty:" ;
305- readonly BIN_FILES=$( ls -1 " ${BINDIR} " 2> /dev/null ; )
306- printf " ::debug::..=> %s\n" " ${BIN_FILES} " ;
307- unset $BIN_FILES 2> /dev/null || : ;
308337 fi ;
309338 else
310339 printf " ::debug::=> %s\n" " Missing ${BINDIR} directory." ;
311- EXIT_CODE=125 ;
340+ EXIT_CODE=66 ;
312341 fi ;
313342 fi ;
314343 fi ;
315344
316345 if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
346+ printf " ::group::%s\n" " Checking DeepSource Config" ;
317347 # ref: https://docs.deepsource.com/docs/cli#commands
318- ./bin/deepsource config validate || EXIT_CODE=$? ;
348+ ./bin/deepsource config validate || ${CI} 2> /dev/null || ${CIRCLECI} 2> /dev/null || EXIT_CODE=125 ;
349+ printf " ::endgroup::\n" ;
319350 fi ;
320351 wait ;
321352fi ;
@@ -333,4 +364,4 @@ cleanup 2>/dev/null || rm -f "${LOCK_FILE}" 2>/dev/null > /dev/null || : ; wait
333364exit ${EXIT_CODE:- 255} ;
334365
335366# This file's code hash:
336- f606b901a37e190d4d0a3e3f6945dda08598de00f182e212a3805c05e6110d5cde47fa492b549add4446124c14ed45f4 -
367+ 64775bab23e56bbd695b87b099c23978d789791c79e94ae7c5cd126a99ca7fde949260d9ad26297027db34af2022f436 -
0 commit comments