@@ -6,22 +6,111 @@ if [ "${COVERALLS_DEBUG}" == "1" ] || [ "${COVERALLS_VERBOSE}" == "1" ]; then
66fi
77
88# Determine which version of coverage-reporter to download
9- if [ -z " $COVERALLS_REPORTER_VERSION " ] || [ " $COVERALLS_REPORTER_VERSION " == " latest" ]; then
9+ if [ -z " $COVERAGE_REPORTER_VERSION " ] || [ " $COVERAGE_REPORTER_VERSION " == " latest" ]; then
1010 asset_path=" latest/download"
1111else
12- asset_path=" download/${COVERALLS_REPORTER_VERSION } "
12+ asset_path=" download/${COVERAGE_REPORTER_VERSION } "
1313fi
1414
15- # Download the Coveralls binary and verify the checksum
16- if ! curl -sLO " https://github.com/coverallsapp/coverage-reporter/releases/${asset_path} /coveralls-linux.tar.gz" ||
17- ! curl -sLO " https://github.com/coverallsapp/coverage-reporter/releases/${asset_path} /coveralls-checksums.txt" ||
18- ! grep coveralls-linux.tar.gz coveralls-checksums.txt | sha256sum --check ||
19- ! tar -xzf coveralls-linux.tar.gz; then
20- echo " Failed to download or verify coveralls binary."
15+ # Determine the platform-specific filename:
16+ # This logic is necessary due to the introduction of multiple platform support starting from v0.6.15.
17+ # It selects the correct filename based on the specified platform, and version, while ensuring
18+ # backward compatibility with earlier versions that only supported a generic Linux binary (for x86_64).
19+
20+ # Function to compare version numbers
21+ version_ge () {
22+ # Compare two version numbers
23+ [ " $( printf ' %s\n' " $@ " | sort -V | head -n 1) " != " $1 " ]
24+ }
25+
26+ # Determine platform-specific filename
27+ case " ${COVERAGE_REPORTER_PLATFORM} " in
28+ x86_64|" " )
29+ if version_ge " $COVERAGE_REPORTER_VERSION " " v0.6.15" ; then
30+ platform_filename=" coveralls-linux-x86_64.tar.gz"
31+ else
32+ platform_filename=" coveralls-linux.tar.gz"
33+ fi
34+ ;;
35+ aarch64|arm64)
36+ if version_ge " $COVERAGE_REPORTER_VERSION " " v0.6.15" ; then
37+ platform_filename=" coveralls-linux-aarch64.tar.gz"
38+ else
39+ echo " Warning: The aarch64/arm64 platform is only supported from version v0.6.15 onwards. Proceeding with v0.6.15." >&2
40+ asset_path=" download/v0.6.15"
41+ platform_filename=" coveralls-linux-aarch64.tar.gz"
42+ fi
43+ ;;
44+ * )
45+ echo " Warning: Unsupported platform: ${COVERAGE_REPORTER_PLATFORM} . The default x86_64 version will be used." >&2
46+ if version_ge " $COVERAGE_REPORTER_VERSION " " v0.6.15" ; then
47+ platform_filename=" coveralls-linux-x86_64.tar.gz"
48+ else
49+ platform_filename=" coveralls-linux.tar.gz"
50+ fi
51+ ;;
52+ esac
53+
54+ # Attempt to download the Coveralls binary and checksum file
55+ if ! curl -sfLO " https://github.com/coverallsapp/coverage-reporter/releases/${asset_path} /${platform_filename} " ||
56+ ! curl -sfLO " https://github.com/coverallsapp/coverage-reporter/releases/${asset_path} /coveralls-checksums.txt" ; then
57+ echo " Failed to download coveralls binary or checksum for version: ${COVERAGE_REPORTER_VERSION} ."
58+ echo " This may be due to an invalid version. Please check the available versions at https://github.com/coverallsapp/coverage-reporter/releases."
2159 [ " ${COVERALLS_FAIL_ON_ERROR} " != " 1" ] && exit 0
2260 exit 1
2361fi
2462
63+ # Verify the downloaded binary:
64+ # The following code was chosen to replace the more simple `sha256sum -c` because it provides
65+ # clearer debugging information re: our matrix of supported coverage-reporter versions and platforms.
66+ # We may drop back to `${platform_filename}" coveralls-checksums.txt | sha256sum -c` when we're more confidently handling these.
67+
68+ # DEBUG: Print contents of checksum file for debugging
69+ echo " Contents of coveralls-checksums.txt:"
70+ cat coveralls-checksums.txt
71+
72+ # Extract expected checksum
73+ expected_checksum=$( grep " ${platform_filename} " coveralls-checksums.txt | awk ' {print $1}' )
74+ if [ -z " $expected_checksum " ]; then
75+ echo " Failed to extract checksum for ${platform_filename} . This may indicate an invalid version."
76+ [ " ${COVERALLS_FAIL_ON_ERROR} " != " 1" ] && exit 0
77+ exit 1
78+ fi
79+
80+ # Compute actual checksum
81+ actual_checksum=$( sha256sum " ${platform_filename} " | awk ' {print $1}' )
82+
83+ # Perform verification by comparing expected and actual checksums
84+ if [ " $expected_checksum " != " $actual_checksum " ]; then
85+ echo " Checksum verification failed."
86+ echo " Expected: $expected_checksum "
87+ echo " Actual: $actual_checksum "
88+ [ " ${COVERALLS_FAIL_ON_ERROR} " != " 1" ] && exit 0
89+ exit 1
90+ fi
91+
92+ # Extract / install the binary
93+ if ! tar -xzf " ${platform_filename} " ; then
94+ echo " Failed to extract coveralls binary."
95+ [ " ${COVERALLS_FAIL_ON_ERROR} " != " 1" ] && exit 0
96+ exit 1
97+ fi
98+
99+ # Check architecture compatibility before attempting any execution
100+ if [ -f ./coveralls ]; then
101+ SYSTEM_ARCH=$( uname -m)
102+ # For versions >= v0.6.15, we need to check architecture even when platform isn't specified
103+ if version_ge " $COVERAGE_REPORTER_VERSION " " v0.6.15" ; then
104+ if [[ -z " ${COVERAGE_REPORTER_PLATFORM} " && " ${SYSTEM_ARCH} " != " x86_64" ]] || \
105+ [[ " ${COVERAGE_REPORTER_PLATFORM} " == " aarch64" && " ${SYSTEM_ARCH} " != " aarch64" ]] || \
106+ [[ " ${COVERAGE_REPORTER_PLATFORM} " == " x86_64" && " ${SYSTEM_ARCH} " != " x86_64" ]]; then
107+ echo " Error: Architecture mismatch. Platform: ${COVERAGE_REPORTER_PLATFORM:- x86_64} , Runner: ${SYSTEM_ARCH} "
108+ [ " ${COVERALLS_FAIL_ON_ERROR} " != " 1" ] && exit 0
109+ exit 1
110+ fi
111+ fi
112+ fi
113+
25114# Ensure the binary exists before attempting to run it
26115if [ ! -f ./coveralls ]; then
27116 echo " Coveralls binary not found after extraction."
@@ -30,7 +119,7 @@ if [ ! -f ./coveralls ]; then
30119fi
31120
32121# Output the version of the installed coverage reporter
33- echo " Installed coverage reporter version:"
122+ echo " Installed coverage reporter version: ${COVERAGE_REPORTER_VERSION} "
34123./coveralls --version || echo " Failed to retrieve version"
35124
36125# Pass the --debug flag to coverage-reporter if COVERALLS_DEBUG or COVERALLS_VERBOSE (deprecated) is set to "1"
0 commit comments