Skip to content

Commit cfd0633

Browse files
authored
Add coverage-reporter-platform input option (#233)
* Add coverage-reporter-platform input option to control which architecture-specific version of coverage-reporter is downloaded and run by the github-action. * Since this option is not available for MacOS or Windows, we deliver warning messages if the option is set, but continue processing with default behavior. * We have also stepped back from returning exit code 1 when coverage-reporter-version is set on MacOS and, instead, now deliver a warning message and allowing processing to proceed with the latest version installed by Homebrew. * We have also added tests for different values of coverage-reporter-platform. * We've added logic to handle the introduction of new platform-specific filenames available in versions from v0.6.15 up and the different contents of coveralls-checksums.txt to be backwards compatible with versions <= v0.6.14.
1 parent 0db2c3c commit cfd0633

File tree

2 files changed

+89
-15
lines changed

2 files changed

+89
-15
lines changed

.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
build-number: ${{ (matrix.action == 'build-number-report' || matrix.action == 'build-number-done') && github.sha || '' }} # Only set 'build-number' to `${{ github.sha }}` when testing `build-number-report` or `build-number-done`
4747
parallel-finished: ${{ matrix.action == 'done' || matrix.action == 'build-number-done' }} # Only set `parallel-finished` to `true` when testing `done` or `build-number-done`
4848
coverage-reporter-version: ${{ matrix.coverage_reporter_version != '' && matrix.coverage_reporter_version || '' }}
49+
coverage-reporter-platform: ${{ matrix.coverage_reporter_platform }}
4950
env:
5051
CI: true
5152
continue-on-error: true

action.yml

+88-15
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,28 @@ inputs:
7373
description: "Version of coverage-reporter to use. Make sure to prefix the version number with 'v'. For example: v0.6.9"
7474
required: false
7575
default: 'latest'
76+
coverage-reporter-platform:
77+
description: "Platform of coverage-reporter to use on Linux runners. Supported values: x86_64 (default) and aarch64 (or arm64)"
78+
required: false
79+
default: 'x86_64'
7680
branding:
7781
color: 'green'
7882
icon: 'percent'
7983
runs:
8084
using: 'composite'
8185
steps:
86+
- name: Report coverage-reporter-version exception for macOS
87+
if: ${{ runner.os == 'macOS' && inputs.coverage-reporter-version != 'latest' }}
88+
shell: bash
89+
run: |
90+
echo "Warning: The coverage-reporter-version parameter is not available on macOS. The latest version will be installed via Homebrew." >&2
91+
92+
- name: Report coverage-reporter-platform exception for macOS
93+
if: ${{ runner.os == 'macOS' && inputs.coverage-reporter-platform != '' }}
94+
shell: bash
95+
run: |
96+
echo "Warning: The coverage-reporter-platform parameter is not available on macOS. The default version for macOS will be used." >&2
97+
8298
- name: Install coveralls reporter (macOS)
8399
if: runner.os == 'macOS'
84100
shell: bash
@@ -100,21 +116,11 @@ runs:
100116
exit 1
101117
fi
102118
103-
- name: Report coverage-reporter-version exception for macOS
104-
if: ${{ runner.os == 'macOS' && inputs.coverage-reporter-version != 'latest' }}
105-
shell: bash
106-
run: |
107-
echo "The coverage-reporter-version parameter is not available on macOS." >&2
108-
if [[ "${{ inputs.fail-on-error }}" == "true" ]]; then
109-
exit 1
110-
else
111-
exit 0
112-
fi
113-
114119
- name: Install coveralls reporter (Linux)
115120
if: runner.os == 'Linux'
116121
env:
117122
COVERAGE_REPORTER_VERSION: ${{ inputs.coverage-reporter-version }}
123+
COVERAGE_REPORTER_PLATFORM: ${{ inputs.coverage-reporter-platform }}
118124
shell: bash
119125
run: |
120126
# Enable debugging if 'debug' is true
@@ -126,26 +132,87 @@ runs:
126132
# Determine which version of coverage-reporter to download
127133
if [ -z "$COVERAGE_REPORTER_VERSION" ] || [ "$COVERAGE_REPORTER_VERSION" == "latest" ]; then
128134
asset_path="latest/download"
135+
version_message="latest"
129136
else
130137
asset_path="download/${COVERAGE_REPORTER_VERSION}"
138+
version_message="$COVERAGE_REPORTER_VERSION"
131139
fi
132140
141+
# Function to compare version numbers
142+
version_ge() {
143+
# Compare two version numbers
144+
[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]
145+
}
146+
147+
# Determine the platform-specific filename:
148+
# This logic is necessary due to the introduction of multiple platform support starting from v0.6.15.
149+
# It selects the correct filename based on the specified platform and version, while ensuring
150+
# backward compatibility with earlier versions that only supported a generic Linux binary for x86_64.
151+
case "$COVERAGE_REPORTER_PLATFORM" in
152+
x86_64|"")
153+
if version_ge "$COVERAGE_REPORTER_VERSION" "v0.6.15"; then
154+
platform_filename="coveralls-linux-x86_64.tar.gz"
155+
else
156+
platform_filename="coveralls-linux.tar.gz"
157+
fi
158+
;;
159+
aarch64|arm64)
160+
if version_ge "$COVERAGE_REPORTER_VERSION" "v0.6.15"; then
161+
platform_filename="coveralls-linux-aarch64.tar.gz"
162+
else
163+
echo "Warning: The aarch64/arm64 platform is only supported from version v0.6.15 onwards. Proceeding with v0.6.15." >&2
164+
asset_path="download/v0.6.15"
165+
platform_filename="coveralls-linux-aarch64.tar.gz"
166+
fi
167+
;;
168+
*)
169+
echo "Warning: Unsupported platform: $COVERAGE_REPORTER_PLATFORM. The default x86_64 version ($version_message) will be used." >&2
170+
if version_ge "$COVERAGE_REPORTER_VERSION" "v0.6.15"; then
171+
platform_filename="coveralls-linux-x86_64.tar.gz"
172+
else
173+
platform_filename="coveralls-linux.tar.gz"
174+
fi
175+
;;
176+
esac
177+
178+
# Checksum verification:
179+
# The following code was chosen to replace the more simple `sha256sum -c` because it provides
180+
# clearer debugging information around our new matrix of supported coverage-reporter versions and platforms.
181+
# We may drop back to `${platform_filename}" coveralls-checksums.txt | sha256sum -c` when we're more confidently handling these.
182+
133183
# Try to download the binary and checksum file
134-
if ! curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/coveralls-linux.tar.gz" ||
184+
if ! curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/${platform_filename}" ||
135185
! curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/coveralls-checksums.txt"; then
136186
echo "Failed to download coveralls binary or checksum (Linux)."
137187
[ "${{ inputs.fail-on-error }}" == "false" ] && exit 0
138188
exit 1
139189
fi
140190
141-
# Try to verify the downloaded binary
142-
if ! grep coveralls-linux.tar.gz coveralls-checksums.txt | sha256sum -c; then
191+
# DEBUG: Print contents of checksum file for debugging
192+
echo "Contents of coveralls-checksums.txt:"
193+
cat coveralls-checksums.txt
194+
195+
# Extract expected checksum
196+
expected_checksum=$(grep "${platform_filename}" coveralls-checksums.txt | awk '{print $1}')
197+
if [ -z "$expected_checksum" ]; then
198+
echo "Failed to extract checksum for ${platform_filename}"
199+
[ "${{ inputs.fail-on-error }}" == "false" ] && exit 0
200+
exit 1
201+
fi
202+
203+
# Compute actual checksum
204+
actual_checksum=$(sha256sum "${platform_filename}" | awk '{print $1}')
205+
206+
# Perform verification by comparing expected and actual checksums
207+
if [ "$expected_checksum" != "$actual_checksum" ]; then
143208
echo "Checksum verification failed (Linux)."
209+
echo "Expected: $expected_checksum"
210+
echo "Actual: $actual_checksum"
144211
[ "${{ inputs.fail-on-error }}" == "false" ] && exit 0
145212
exit 1
146213
fi
147214
148-
tar -xzf coveralls-linux.tar.gz
215+
tar -xzf "${platform_filename}"
149216
150217
# Check if the binary exists
151218
if [ ! -f ~/bin/coveralls ]; then
@@ -157,6 +224,12 @@ runs:
157224
rm coveralls-checksums.txt
158225
echo ~/bin >> $GITHUB_PATH
159226
227+
- name: Report coverage-reporter-platform exception for Windows
228+
if: ${{ startsWith(runner.os, 'Windows') && inputs.coverage-reporter-platform != '' }}
229+
shell: pwsh
230+
run: |
231+
Write-Host "Warning: The coverage-reporter-platform parameter is not available on Windows. The default version for Windows will be used." -ForegroundColor Yellow
232+
160233
- name: Install coveralls reporter (Windows)
161234
if: startsWith(runner.os, 'Windows')
162235
env:

0 commit comments

Comments
 (0)