Skip to content

Commit 1f07055

Browse files
authored
Add coverage_reporter_platform parameter (#49)
* Add support for coverage_reporter_platform input parameter. * Add logic to select correct architecture-specific binary of coverage-reporter when coverage_reporter_platform is supplied. * Add tests.
1 parent 2d6de2e commit 1f07055

File tree

3 files changed

+174
-28
lines changed

3 files changed

+174
-28
lines changed

.circleci/test-deploy.yml

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
22
version: 2.1
3+
34
orbs:
45
orb-tools: circleci/orb-tools@12.1
6+
57
filters: &filters
68
tags:
79
only: /.*/
10+
811
jobs:
912
command-tests:
1013
docker:
@@ -17,53 +20,98 @@ jobs:
1720
COVERALLS_REPO_TOKEN: test-token
1821
steps:
1922
- checkout
23+
24+
# Test with all defaults (ie. no specified version or platform)
2025
- coveralls/upload:
2126
dry_run: true
27+
verbose: true
28+
measure: true
29+
30+
# Test with parallel, coverage file and fail_on_error: false
31+
- coveralls/upload:
2232
debug: true
33+
parallel: true
2334
measure: true
35+
coverage_file: test/main.c.gcov
36+
fail_on_error: false
37+
38+
# test with parallel_finished
2439
- coveralls/upload:
2540
dry_run: true
2641
debug: true
2742
measure: true
43+
parallel_finished: true
44+
45+
# Test with specified version (latest)
46+
- coveralls/upload:
47+
dry_run: true
48+
debug: true
2849
coverage_reporter_version: latest
50+
51+
# Test with specified version (v0.6.14)
2952
- coveralls/upload:
53+
dry_run: true
3054
debug: true
3155
parallel: true
3256
coverage_file: test/main.c.gcov
33-
coverage_reporter_version: v0.6.9
34-
fail_on_error: false
57+
coverage_reporter_version: v0.6.14
58+
59+
# Test with invalid version
3560
- coveralls/upload:
3661
dry_run: true
3762
debug: true
3863
coverage_reporter_version: invalid-version
3964
fail_on_error: false
65+
66+
# Test with specified platform (x86_64)
67+
- coveralls/upload:
68+
dry_run: true
69+
debug: true
70+
coverage_reporter_platform: x86_64
71+
72+
# Test with specified platform (aarch64)
73+
- coveralls/upload:
74+
dry_run: true
75+
debug: true
76+
coverage_reporter_platform: aarch64
77+
fail_on_error: false
78+
79+
# Test with specified platform (arm64)
80+
- coveralls/upload:
81+
dry_run: true
82+
debug: true
83+
coverage_reporter_platform: arm64
84+
fail_on_error: false
85+
86+
# Standalone ARM test
87+
arm-test:
88+
machine:
89+
image: ubuntu-2204:current
90+
resource_class: arm.large
91+
steps:
92+
- checkout
93+
# Verify ARM architecture
4094
- run:
41-
name: Verify coverage reporter version
95+
name: Verify architecture
4296
command: |
43-
INSTALLED_VERSION=$(./coveralls --version | awk '{print $NF}')
44-
EXPECTED_VERSION="<< parameters.coverage_reporter_version >>"
45-
GITHUB_RELEASES_URL="https://github.com/coverallsapp/coverage-reporter/releases"
46-
47-
if [ "$EXPECTED_VERSION" = "latest" ]; then
48-
echo "The version of coverage reporter chosen was 'latest' and the version installed is $INSTALLED_VERSION."
49-
echo "Please check releases at $GITHUB_RELEASES_URL to ensure this is the latest release."
50-
elif [ "$INSTALLED_VERSION" = "$EXPECTED_VERSION" ]; then
51-
echo "Correct version ($EXPECTED_VERSION) installed"
52-
else
53-
echo "Version mismatch. Expected $EXPECTED_VERSION, but got $INSTALLED_VERSION"
54-
echo "Please check releases at $GITHUB_RELEASES_URL for available versions."
55-
exit 1
56-
fi
97+
echo "uname -m reports: $(uname -m)"
98+
echo "arch reports: $(arch)"
99+
echo "uname -a reports: $(uname -a)"
100+
# Test with aarch64 platform on ARM machine
57101
- coveralls/upload:
58102
dry_run: true
59103
debug: true
60-
parallel_finished: true
104+
coverage_reporter_platform: aarch64
105+
coverage_reporter_version: v0.6.15
106+
61107
workflows:
62108
test-deploy:
63109
jobs:
64110
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
65111
- command-tests:
66112
filters: *filters
113+
- arm-test:
114+
filters: *filters
67115
- orb-tools/pack:
68116
filters: *filters
69117
- orb-tools/publish:
@@ -73,6 +121,7 @@ workflows:
73121
requires:
74122
- orb-tools/pack
75123
- command-tests
124+
- arm-test
76125
context: publishing
77126
filters:
78127
branches:

src/@orb.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ commands:
119119
Version of coverage-reporter to use. Prefix the version number
120120
with 'v'. For example: v0.6.14. Set to 'latest' for the latest
121121
version.
122+
coverage_reporter_platform:
123+
type: enum
124+
default: "x86_64"
125+
description: >
126+
Platform of coverage-reporter to use. Supported values: x86_64
127+
(default) and aarch64 (or arm64).
128+
enum: ["x86_64", "aarch64", "arm64"]
122129
steps:
123130
- run:
124131
name: Upload Coverage Results To Coveralls
@@ -140,6 +147,7 @@ commands:
140147
COVERALLS_COVERAGE_FORMAT: << parameters.coverage_format >>
141148
COVERALLS_MEASURE: << parameters.measure >>
142149
COVERALLS_FAIL_ON_ERROR: << parameters.fail_on_error >>
143-
COVERALLS_REPORTER_VERSION: << parameters.coverage_reporter_version >> # yamllint disable-line rule:line-length
150+
COVERAGE_REPORTER_VERSION: << parameters.coverage_reporter_version >> # yamllint disable-line rule:line-length
151+
COVERAGE_REPORTER_PLATFORM: << parameters.coverage_reporter_platform >> # yamllint disable-line rule:line-length
144152
COVERALLS_SOURCE_HEADER: circleci-orb
145153
command: <<include(scripts/coveralls.sh)>>

src/scripts/coveralls.sh

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,111 @@ if [ "${COVERALLS_DEBUG}" == "1" ] || [ "${COVERALLS_VERBOSE}" == "1" ]; then
66
fi
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"
1111
else
12-
asset_path="download/${COVERALLS_REPORTER_VERSION}"
12+
asset_path="download/${COVERAGE_REPORTER_VERSION}"
1313
fi
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
2361
fi
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
26115
if [ ! -f ./coveralls ]; then
27116
echo "Coveralls binary not found after extraction."
@@ -30,7 +119,7 @@ if [ ! -f ./coveralls ]; then
30119
fi
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

Comments
 (0)