-
Notifications
You must be signed in to change notification settings - Fork 74
/
action.yml
315 lines (289 loc) · 13.5 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# action.yml
name: 'Coveralls GitHub Action'
description: 'Send test coverage data to Coveralls.io for analysis, change tracking, and notifications.'
author: Coveralls.io
inputs:
github-token:
description: 'Put secrets.GITHUB_TOKEN here'
required: false
default: ${{ github.token }}
path-to-lcov:
description: 'Path to lcov file [DEPRECATED]'
required: false
file:
description: 'Coverage file'
required: false
files:
description: 'Space-separated list of coverage files'
required: false
format:
description: 'Force coverage format, supported formats: lcov, simplecov, cobertura, jacoco, gcov, golang, python'
required: false
flag-name:
description: 'Job flag name, e.g. "Unit", "Functional", or "Integration". Will be shown in the Coveralls UI.'
required: false
build-number:
description: 'Override the build number autodetected from CI. This is useful if your CI tool assigns a different build number per each parallel build.'
required: false
parallel:
description: 'Set to true if you are running parallel jobs, then use "parallel-finished: true" for the last action.'
required: false
parallel-finished:
description: 'Set to true for the last action when using "parallel: true".'
required: false
carryforward:
description: 'Comma separated flags used to carryforward results from previous builds if some of the parallel jobs are missing.'
required: false
coveralls-endpoint:
description: 'Coveralls Enterprise server (more info: https://enterprise.coveralls.io)'
required: false
default: 'https://coveralls.io'
allow-empty:
description: "Don't fail when coverage report file is empty or contains no data"
required: false
default: 'false'
base-path:
description: 'The root folder of the project that originally ran the tests'
required: false
git-branch:
description: 'Override the branch name'
required: false
git-commit:
description: 'Override the commit sha'
required: false
compare-ref:
description: 'Branch name to use as the base for coverage results'
required: false
compare-sha:
description: 'Commit SHA to use as the base for coverage results'
required: false
debug:
description: 'Enable debug output'
required: false
default: 'false'
measure:
description: 'Show execution time of parsing and reporting'
required: false
default: 'false'
fail-on-error:
description: 'Whether to fail (exit code 1) on any issues while uploading the coverage'
required: false
default: 'true'
coverage-reporter-version:
description: "Version of coverage-reporter to use. Make sure to prefix the version number with 'v'. For example: v0.6.9"
required: false
default: 'latest'
coverage-reporter-platform:
description: "Platform of coverage-reporter to use on Linux runners. Supported values: x86_64 (default) and aarch64 (or arm64)"
required: false
default: 'x86_64'
branding:
color: 'green'
icon: 'percent'
runs:
using: 'composite'
steps:
- name: Report coverage-reporter-version exception for macOS
if: ${{ runner.os == 'macOS' && inputs.coverage-reporter-version != 'latest' }}
shell: bash
run: |
echo "Warning: The coverage-reporter-version parameter is not available on macOS. The latest version will be installed via Homebrew." >&2
- name: Report coverage-reporter-platform exception for macOS
if: ${{ runner.os == 'macOS' && inputs.coverage-reporter-platform != '' }}
shell: bash
run: |
echo "Warning: The coverage-reporter-platform parameter is not available on macOS. The default version for macOS will be used." >&2
- name: Install coveralls reporter (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
# Enable debugging if 'debug' is true
[ "${{ inputs.debug }}" == "true" ] && set -x
# Try to install coverage-reporter via Homebrew
brew tap coverallsapp/coveralls --quiet
brew install coveralls --quiet
# Check if the binary exists in the possible locations
if [ -f /usr/local/bin/coveralls ]; then
echo "/usr/local/bin" >> $GITHUB_PATH
elif [ -f /opt/homebrew/bin/coveralls ]; then
echo "/opt/homebrew/bin" >> $GITHUB_PATH
else
echo "Coveralls binary not found after installation (MacOS)."
exit 1
fi
- name: Install coveralls reporter (Linux)
if: runner.os == 'Linux'
env:
COVERAGE_REPORTER_VERSION: ${{ inputs.coverage-reporter-version }}
COVERAGE_REPORTER_PLATFORM: ${{ inputs.coverage-reporter-platform }}
shell: bash
run: |
# Enable debugging if 'debug' is true
[ "${{ inputs.debug }}" == "true" ] && set -x
mkdir -p ~/bin/
cd ~/bin/
# Determine which version of coverage-reporter to download
if [ -z "$COVERAGE_REPORTER_VERSION" ] || [ "$COVERAGE_REPORTER_VERSION" == "latest" ]; then
asset_path="latest/download"
version_message="latest"
else
asset_path="download/${COVERAGE_REPORTER_VERSION}"
version_message="$COVERAGE_REPORTER_VERSION"
fi
# Function to compare version numbers
version_ge() {
# Compare two version numbers
[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]
}
# Determine the platform-specific filename:
# This logic is necessary due to the introduction of multiple platform support starting from v0.6.15.
# It selects the correct filename based on the specified platform and version, while ensuring
# backward compatibility with earlier versions that only supported a generic Linux binary for x86_64.
case "$COVERAGE_REPORTER_PLATFORM" in
x86_64|"")
if version_ge "$COVERAGE_REPORTER_VERSION" "v0.6.15"; then
platform_filename="coveralls-linux-x86_64.tar.gz"
else
platform_filename="coveralls-linux.tar.gz"
fi
;;
aarch64|arm64)
if version_ge "$COVERAGE_REPORTER_VERSION" "v0.6.15"; then
platform_filename="coveralls-linux-aarch64.tar.gz"
else
echo "Warning: The aarch64/arm64 platform is only supported from version v0.6.15 onwards. Proceeding with v0.6.15." >&2
asset_path="download/v0.6.15"
platform_filename="coveralls-linux-aarch64.tar.gz"
fi
;;
*)
echo "Warning: Unsupported platform: $COVERAGE_REPORTER_PLATFORM. The default x86_64 version ($version_message) will be used." >&2
if version_ge "$COVERAGE_REPORTER_VERSION" "v0.6.15"; then
platform_filename="coveralls-linux-x86_64.tar.gz"
else
platform_filename="coveralls-linux.tar.gz"
fi
;;
esac
# Checksum verification:
# The following code was chosen to replace the more simple `sha256sum -c` because it provides
# clearer debugging information around our new matrix of supported coverage-reporter versions and platforms.
# We may drop back to `${platform_filename}" coveralls-checksums.txt | sha256sum -c` when we're more confidently handling these.
# Try to download the binary and checksum file
if ! curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/${platform_filename}" ||
! curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/coveralls-checksums.txt"; then
echo "Failed to download coveralls binary or checksum (Linux)."
[ "${{ inputs.fail-on-error }}" == "false" ] && exit 0
exit 1
fi
# DEBUG: Print contents of checksum file for debugging
echo "Contents of coveralls-checksums.txt:"
cat coveralls-checksums.txt
# Extract expected checksum
expected_checksum=$(grep "${platform_filename}" coveralls-checksums.txt | awk '{print $1}')
if [ -z "$expected_checksum" ]; then
echo "Failed to extract checksum for ${platform_filename}"
[ "${{ inputs.fail-on-error }}" == "false" ] && exit 0
exit 1
fi
# Compute actual checksum
actual_checksum=$(sha256sum "${platform_filename}" | awk '{print $1}')
# Perform verification by comparing expected and actual checksums
if [ "$expected_checksum" != "$actual_checksum" ]; then
echo "Checksum verification failed (Linux)."
echo "Expected: $expected_checksum"
echo "Actual: $actual_checksum"
[ "${{ inputs.fail-on-error }}" == "false" ] && exit 0
exit 1
fi
tar -xzf "${platform_filename}"
# Check if the binary exists
if [ ! -f ~/bin/coveralls ]; then
echo "Coveralls binary not found after extraction (Linux)."
exit 1
fi
# Cleanup
rm coveralls-checksums.txt
echo ~/bin >> $GITHUB_PATH
- name: Report coverage-reporter-platform exception for Windows
if: ${{ startsWith(runner.os, 'Windows') && inputs.coverage-reporter-platform != '' }}
shell: pwsh
run: |
Write-Host "Warning: The coverage-reporter-platform parameter is not available on Windows. The default version for Windows will be used." -ForegroundColor Yellow
- name: Install coveralls reporter (Windows)
if: startsWith(runner.os, 'Windows')
env:
COVERAGE_REPORTER_VERSION: ${{ inputs.coverage-reporter-version }}
shell: pwsh
run: |
# Enable debugging if 'debug' is true
if ("${{ inputs.debug }}" -eq "true") {
Set-PSDebug -Trace 1
}
# Try to download the binary and checksum file
New-Item -Path $env:HOME\bin -ItemType directory -Force
Push-Location $env:HOME\bin
if ([string]::IsNullOrEmpty($env:COVERAGE_REPORTER_VERSION) -or $env:COVERAGE_REPORTER_VERSION -eq "latest") {
Invoke-WebRequest -Uri "https://github.com/coverallsapp/coverage-reporter/releases/latest/download/coveralls-windows.exe" -OutFile "coveralls.exe"
Invoke-WebRequest -Uri "https://github.com/coverallsapp/coverage-reporter/releases/latest/download/coveralls-checksums.txt" -OutFile "sha256sums.txt"
} else {
Invoke-WebRequest -Uri "https://github.com/coverallsapp/coverage-reporter/releases/download/$env:COVERAGE_REPORTER_VERSION/coveralls-windows.exe" -OutFile "coveralls.exe"
Invoke-WebRequest -Uri "https://github.com/coverallsapp/coverage-reporter/releases/download/$env:COVERAGE_REPORTER_VERSION/coveralls-checksums.txt" -OutFile "sha256sums.txt"
}
# Try to verify the downloaded binary
if ((Get-FileHash coveralls.exe).Hash -ne (Get-Content sha256sums.txt | Select-String 'windows.exe' | ForEach-Object { ($_ -split "\s+")[0] })) {
Write-Host "Checksum verification failed (Windows)."
exit 1
}
# Check if the binary exists
if (!(Test-Path -Path "$env:HOME\bin\coveralls.exe")) {
Write-Host "Coveralls binary not found after download and verification (Windows)."
exit 1
}
# Cleanup
Remove-Item sha256sums.txt -Force
echo $env:HOME\bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Done report
if: inputs.parallel-finished == 'true'
shell: ${{ startsWith(runner.os, 'Windows') && 'pwsh' || 'bash' }}
run: >-
coveralls done
${{ inputs.debug == 'true' && '--debug' || '' }}
${{ inputs.measure == 'true' && '--measure' || '' }}
${{ inputs.build-number && format('--build-number {0}', inputs.build-number) || '' }}
${{ inputs.fail-on-error == 'false' && '--no-fail' || '' }}
env:
COVERALLS_DEBUG: ${{ inputs.debug }}
COVERALLS_CARRYFORWARD_FLAGS: ${{ inputs.carryforward }}
COVERALLS_FLAG_NAME: ${{ inputs.flag-name }}
COVERALLS_PARALLEL: ${{ inputs.parallel }}
COVERALLS_ENDPOINT: ${{ inputs.coveralls-endpoint }}
COVERALLS_GIT_BRANCH: ${{ inputs.git-branch }}
COVERALLS_GIT_COMMIT: ${{ inputs.git-commit }}
COVERALLS_REPO_TOKEN: ${{ inputs.github-token }}
- name: Coverage report
if: inputs.parallel-finished != 'true'
shell: ${{ startsWith(runner.os, 'Windows') && 'pwsh' || 'bash' }}
run: >-
coveralls report
${{ inputs.debug == 'true' && '--debug' || '' }}
${{ inputs.measure == 'true' && '--measure' || '' }}
${{ inputs.fail-on-error == 'false' && '--no-fail' || '' }}
${{ inputs.allow-empty == 'true' && '--allow-empty' || '' }}
${{ inputs.base-path && format('--base-path {0}', inputs.base-path) || '' }}
${{ inputs.build-number && format('--build-number {0}', inputs.build-number) || '' }}
${{ inputs.format && format('--format {0}', inputs.format) || '' }}
${{ inputs.file || inputs.path-to-lcov }}
${{ inputs.files }}
env:
COVERALLS_DEBUG: ${{ inputs.debug }}
COVERALLS_CARRYFORWARD_FLAGS: ${{ inputs.carryforward }}
COVERALLS_FLAG_NAME: ${{ inputs.flag-name }}
COVERALLS_PARALLEL: ${{ inputs.parallel }}
COVERALLS_ENDPOINT: ${{ inputs.coveralls-endpoint }}
COVERALLS_GIT_BRANCH: ${{ inputs.git-branch }}
COVERALLS_GIT_COMMIT: ${{ inputs.git-commit }}
COVERALLS_REPO_TOKEN: ${{ inputs.github-token }}
COVERALLS_COMPARE_REF: ${{ inputs.compare-ref }}
COVERALLS_COMPARE_SHA: ${{ inputs.compare-sha }}
COVERALLS_SOURCE_HEADER: github-action