Skip to content

Commit 297e758

Browse files
[DEBUG] Re-write tool to actually work (- WIP PR #82 -)
1 parent 5040345 commit 297e758

File tree

2 files changed

+57
-26
lines changed

2 files changed

+57
-26
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ legacy-purge: clean uninstall
216216
purge: legacy-purge
217217
$(QUIET)$(RM) ./cc-test-reporter 2>$(ERROR_LOG_PATH) || :
218218
$(QUIET)$(RM) ./ds-cli.sh 2>$(ERROR_LOG_PATH) || :
219+
$(QUIET)$(RM) ./bin/deepsource 2>$(ERROR_LOG_PATH) || :
220+
$(QUIET)$(RMDIR) ./bin/ 2>$(ERROR_LOG_PATH) || :
219221
$(QUIET)$(RM) ./test-reports/*.xml 2>$(ERROR_LOG_PATH) || :
220222
$(QUIET)$(RMDIR) ./test-reports/ 2>$(ERROR_LOG_PATH) || :
221223
$(QUIET)$(ECHO) "$@: Done."

tests/fetch_cc-test-reporter

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,28 @@
6565

6666

6767
# to check though:
68-
diff -q <(tail -n 240 "$0" | head -n 238 | shasum -a 384 -t -) <(tail -n 1 "$0") || exit 70 ;
68+
diff -q <(tail -n 269 "$0" | head -n 267 | shasum -a 384 -t -) <(tail -n 1 "$0") || exit 70 ;
6969

7070
ulimit -t 90
7171
PATH="/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:${PATH}"
7272
LANG=${LANG:-"en_US"}
7373
LC_ALL="${LANG:0:5}.utf-8"
74-
export BINDIR="${BINDIR:-./bin}"
74+
BINDIR="${BINDIR:-./bin}"
75+
DS_TAG="0.8.6" # circa 2025
7576
umask 127
7677

7778
LOCK_FILE="${TMPDIR:-/tmp}/org.pak.tests.scripts.code-climate.lock"
7879
EXIT_CODE=0
7980

8081
test -x "$(command -v grep)" || exit 126 ;
82+
test -x "$(command -v sed)" || exit 126 ;
8183
test -x "$(command -v curl)" || exit 126 ;
8284
test -x "$(command -v mkdir)" || exit 126 ;
8385
hash -p ./.github/tool_shlock_helper.sh shlock || exit 255 ;
8486
test -x "$(command -v shlock)" || exit 126 ;
8587
test -x "$(command -v gpgv)" || exit 126 ;
8688
test -x "$(command -v shasum)" || exit 126 ;
89+
test -x "$(command -v tar)" || exit 126 ;
8790

8891
# Detect the operating system
8992
case "$( command uname -s )" in
@@ -216,43 +219,69 @@ if [[ -z ${DEEPSOURCE_DSN} ]] && [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
216219
elif [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
217220
printf "%s\n" "Detected Config for DeepSource" ;
218221

219-
# USED FOR INTEGRETY
220-
printf "adc12b89f5a41201f7556d4181cf33fa0a5a9964 ds-cli.sh\n" >ds-cli.sh.sha1
221-
printf "61e8a49d3d5c49a3614be2bcaaf96e232466fd87c225ecc782e96f4d65dd5bdf ds-cli.sh\n" >ds-cli.sh.sha256
222-
printf "b7232d1e8d73aeb4cefdf3707dd43f0e141b2585fedfd602cb97ec15047de60284f0ed4703b6e98717aebc3aee90e11c26417afbaba1168a5d0a98e22d74f66d ds-cli.sh\n" >ds-cli.sh.sha512
222+
# Make an API call to GitHub to get the latest release with the Accept header
223+
response=$(curl -s -H "Accept: application/json" "https://api.github.com/repos/DeepSourceCorp/cli/releases/latest")
223224

224-
curl -fLso ./ds-cli.sh "https://deepsource.io/cli" || EXIT_CODE=125 ;
225+
# Check if the response is valid
226+
if [[ "$response" == *"Not Found"* ]]; then
227+
printf "::debug::%s\n" "Repository not found or no releases available."
228+
EXIT_CODE=125
229+
fi ;
225230

226231
if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
227-
printf "::debug::%s\n" "Downloaded ds-cli.sh for DeepSource" ;
232+
printf "::debug::%s\n" "Checking latest version for DeepSource" ;
233+
# Try to extract the tag name using jq
234+
if [[ ( -x "$(command -v jq)" ) ]]; then
235+
tag_name=$(printf "%s\n" "$response" | jq -r '.tag_name')
236+
else
237+
# Fallback to grep and sed if jq is not available
238+
tag_name=$(printf "%s\n" "$response" | grep -o '"tag_name": "[^"]*' | sed 's/"tag_name": "//')
239+
fi ;
228240
fi ;
229241

230-
for i in 1 256 512 ; do
231-
# test sha1/sha512 signatures if found and sha256 even if not found
232-
if [[ ( -r ds-cli.sh.sha${i} ) ]] || [[ ( ${i} -eq 256 ) ]] ; then
233-
if [[ ${i} -eq 1 ]]; then
234-
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)"
235-
fi
236-
shasum -a $i -c --ignore-missing ds-cli.sh.sha${i} || EXIT_CODE=126
237-
rm -vf ds-cli.sh.sha${i} 2>/dev/null ;
238-
fi
239-
done
242+
# Check if tag_name is empty
243+
if [[ ( -z "$tag_name" ) ]]; then
244+
printf "::debug::%s\n" "No tag name found in the response."
245+
EXIT_CODE=125
246+
else
247+
printf "::debug::%s\n" "Found version ${tag_name} for DeepSource" ;
248+
DS_TAG="${tag_name#v}"
249+
fi ;
250+
251+
if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
252+
printf "::debug::%s\n" "Creating ${BINDIR} directory for DeepSource" ;
253+
mkdir -m 755 "${BINDIR}" || EXIT_CODE=66 ;
254+
fi ;
255+
256+
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 ;
240257

241258
if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
242-
printf "::debug::%s\n" "Validated ds-cli.sh for DeepSource" ;
243-
chmod -v 751 ./ds-cli.sh || EXIT_CODE=77
259+
printf "::debug::%s\n" "Downloaded deepsource_${DS_TAG}_${CI_OS}_${ARCH}.tar.gz for DeepSource" ;
244260
fi ;
245261

262+
curl -fLso "checksums.txt" "https://github.com/DeepSourceCorp/cli/releases/download/v${DS_TAG}/checksums.txt" || EXIT_CODE=125 ;
263+
246264
if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
247-
printf "::debug::%s\n" "Creating ${BINDIR} directory for DeepSource" ;
248-
mkdir -v -m 755 "${BINDIR}" || EXIT_CODE=66
265+
printf "::debug::%s\n" "Downloaded checksums.txt for DeepSource" ;
266+
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 ;
272+
273+
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}" || EXIT_CODE=77 ;
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 || : ;
249278
fi ;
250279

251280
if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
252281
# ref: https://docs.deepsource.com/docs/analyzers-test-coverage#setup-test-coverage
253-
printf "::group::%s\n" "Running ./ds-cli.sh" ;
254-
time { cat ./ds-cli.sh | sh ;} ; wait ;
255-
printf "::endgroup::\n" ;
282+
#printf "::group::%s\n" "Running ./ds-cli.sh" ;
283+
#{ cat ./ds-cli.sh | sh - | grep -o "(:?version).{1}\s[0-9].[0-9].[0-9]" ;} ; wait ;
284+
#printf "::endgroup::\n" ;
256285
if [[ ( ${EXIT_CODE} -eq 0 ) ]] ; then
257286
printf "::debug::%s\n" "Checking for DeepSource CLI" ;
258287
if [[ ( -d "${BINDIR}" ) ]] ; then
@@ -304,4 +333,4 @@ cleanup 2>/dev/null || rm -f "${LOCK_FILE}" 2>/dev/null > /dev/null || : ; wait
304333
exit ${EXIT_CODE:-255} ;
305334

306335
# This file's code hash:
307-
b444b5d3e9093ee01e78a8fe991e60d0f6d48218fbb13cf8d3e6d06705a4289a7def2fcfe44758328c76572633cfd4ad -
336+
779f220ba3f753ed3e929121e0742fe6362d779be1dfff7dda258e04b4fb95412e740b5f4ad5319b8ca61c79151cd735 -

0 commit comments

Comments
 (0)