A shareable package of CircleCI configuration to integrate with coveralls, written by coveralls
PartnerCode AnalysisTestingUse CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1Add the orbs stanza below your version, invoking the orb:
1
2
orbs:
coveralls: coveralls/coveralls@2.2.5Use coveralls elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Coveralls parallel build. 'build' jobs uploads coverage, then 'done' job hits parallel complete webhook to finish the build. Demo: https://github.com/coverallsapp/actions-demo
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
version: '2.1'
orbs:
coveralls: coveralls/coveralls@x.y.z
jobs:
build-1:
build-2:
docker:
- image: circleci/node:10.0.0
steps:
- checkout
- run:
command: npm install && make test-coverage-2
name: Install and Make 2
- coveralls/upload:
flag_name: job2
parallel: true
docker:
- image: circleci/node:10.0.0
steps:
- checkout
- run:
command: npm install && make test-coverage-1
name: Install and Make 1
- coveralls/upload:
flag_name: job1
parallel: true
done:
docker:
- image: circleci/node:10.0.0
steps:
- coveralls/upload:
carryforward: job1,job2
parallel_finished: true
workflows:
test_parallel_then_upload:
jobs:
- build-1
- build-2
- done:
requires:
- build-1
- build-2
workflows: null
Build and upload to Coveralls in single job. Demo: https://github.com/coverallsapp/actions-demo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
version: '2.1'
orbs:
coveralls: coveralls/coveralls@1.0.6
jobs:
build:
docker:
- image: circleci/node:10.0.0
steps:
- checkout
- run:
command: npm install && make test-coverage
name: Install and Make
- coveralls/upload
workflows: null
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
base_path Path to the root folder of the project the coverage was collected in.
| Path to the root folder of the project the coverage was collected in.
| No | '' type: string | string |
carryforward References for jobs to carry-forward from previous builds (if missing).
| References for jobs to carry-forward from previous builds (if missing).
| No | '' type: string | string |
compare_ref Branch name to compare coverage with. Specify if you want to always check coverage change for PRs against one branch.
| Branch name to compare coverage with. Specify if you want to always check coverage change for PRs against one branch.
| No | '' type: string | string |
compare_sha Commit SHA to compare coverage with. | Commit SHA to compare coverage with. | No | '' type: string | string |
coverage_file Local path to the coverage output file produced by your test suite. An error will be thrown if the file can't be found. This is the file that will be sent to the Coveralls API.
| Local path to the coverage output file produced by your test suite. An error will be thrown if the file can't be found. This is the file that will be sent to the Coveralls API.
| No | '' type: string | string |
coverage_files Space-separated list of coverage reports to be uploaded.
| Space-separated list of coverage reports to be uploaded.
| No | '' type: string | string |
coverage_format Force coverage report format. If not specified coveralls will try to determine the format automatically based on file extension and/or content. Supported formats are - lcov, simplecov, cobertura, jacoco, gcov, golang, python.
| Force coverage report format. If not specified coveralls will try to determine the format automatically based on file extension and/or content. Supported formats are - lcov, simplecov, cobertura, jacoco, gcov, golang, python.
| No | '' type: string | string |
coverage_reporter_platform Platform of coverage-reporter to use. Supported values: x86_64 (default) and aarch64 (or arm64).
| Platform of coverage-reporter to use. Supported values: x86_64 (default) and aarch64 (or arm64).
| No | x86_64 type: enum | enum |
coverage_reporter_version Version of coverage-reporter to use. Prefix the version number with 'v'. For example: v0.6.14. Set to 'latest' for the latest version.
| Version of coverage-reporter to use. Prefix the version number with 'v'. For example: v0.6.14. Set to 'latest' for the latest version.
| No | latest type: string | string |
coveralls_endpoint Hostname and protocol (https://<host>). Specifies a Coveralls Enterprise hostname. You can also define this in your Circle's Environment Variables as COVERALLS_ENDPOINT
| Hostname and protocol (https://<host>). Specifies a Coveralls Enterprise hostname. You can also define this in your Circle's Environment Variables as COVERALLS_ENDPOINT
| No | https://coveralls.io type: string | string |
debug Set to true for debug output. Replaces verbose. | Set to true for debug output. Replaces verbose. | No | false type: boolean | boolean |
dry_run Do not send anything but do the parsing | Do not send anything but do the parsing | No | false type: boolean | boolean |
fail_on_error Whether to fail (exit code 1) on parsing or upload issues | Whether to fail (exit code 1) on parsing or upload issues | No | true type: boolean | boolean |
flag_name Options flag name of the job, e.g. "Unit Tests", "Integration Tests", etc.
| Options flag name of the job, e.g. "Unit Tests", "Integration Tests", etc.
| No | '' type: string | string |
measure Enable time measurement logging | Enable time measurement logging | No | false type: boolean | boolean |
parallel Set to true for parallel jobs, where multiple posts to Coveralls will be performed before completing the build with `parallel_finished`.
| Set to true for parallel jobs, where multiple posts to Coveralls will be performed before completing the build with `parallel_finished`.
| No | false type: boolean | boolean |
parallel_finished Set to true in the final job, after the other parallel jobs steps have completed. This will send a webhook to Coveralls to set the build complete.
| Set to true in the final job, after the other parallel jobs steps have completed. This will send a webhook to Coveralls to set the build complete.
| No | false type: boolean | boolean |
token Your Coveralls Repo token defined in your Circle's Environment Variables.
| Your Coveralls Repo token defined in your Circle's Environment Variables.
| No | COVERALLS_REPO_TOKEN type: env_var_name | env_var_name |
verbose Set to true for debug output. Deprecated, use debug instead.
| Set to true for debug output. Deprecated, use debug instead.
| No | false type: boolean | boolean |
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
This Orb posts your test suite's coverage data to coveralls.io for analysis, change tracking, and notifications.
When running on Pull Request builds, a comment will be added to the PR with details about how coverage will be affected if merged.
display:
home_url: https://coveralls.io/
source_url: https://github.com/coverallsapp/orb
commands:
upload:
parameters:
base_path:
default: ""
description: |
Path to the root folder of the project the coverage was collected in.
type: string
carryforward:
default: ""
description: |
References for jobs to carry-forward from previous builds (if missing).
type: string
compare_ref:
default: ""
description: |
Branch name to compare coverage with. Specify if you want to always check coverage change for PRs against one branch.
type: string
compare_sha:
default: ""
description: Commit SHA to compare coverage with.
type: string
coverage_file:
default: ""
description: |
Local path to the coverage output file produced by your test suite. An error will be thrown if the file can't be found. This is the file that will be sent to the Coveralls API.
type: string
coverage_files:
default: ""
description: |
Space-separated list of coverage reports to be uploaded.
type: string
coverage_format:
default: ""
description: |
Force coverage report format. If not specified coveralls will try to determine the format automatically based on file extension and/or content. Supported formats are - lcov, simplecov, cobertura, jacoco, gcov, golang, python.
type: string
coverage_reporter_platform:
default: x86_64
description: |
Platform of coverage-reporter to use. Supported values: x86_64 (default) and aarch64 (or arm64).
enum:
- x86_64
- aarch64
- arm64
type: enum
coverage_reporter_version:
default: latest
description: |
Version of coverage-reporter to use. Prefix the version number with 'v'. For example: v0.6.14. Set to 'latest' for the latest version.
type: string
coveralls_endpoint:
default: https://coveralls.io
description: |
Hostname and protocol (https://<host>). Specifies a Coveralls Enterprise hostname. You can also define this in your Circle's Environment Variables as COVERALLS_ENDPOINT
type: string
debug:
default: false
description: Set to true for debug output. Replaces verbose.
type: boolean
dry_run:
default: false
description: Do not send anything but do the parsing
type: boolean
fail_on_error:
default: true
description: Whether to fail (exit code 1) on parsing or upload issues
type: boolean
flag_name:
default: ""
description: |
Options flag name of the job, e.g. "Unit Tests", "Integration Tests", etc.
type: string
measure:
default: false
description: Enable time measurement logging
type: boolean
parallel:
default: false
description: |
Set to true for parallel jobs, where multiple posts to Coveralls will be performed before completing the build with `parallel_finished`.
type: boolean
parallel_finished:
default: false
description: |
Set to true in the final job, after the other parallel jobs steps have completed. This will send a webhook to Coveralls to set the build complete.
type: boolean
token:
default: COVERALLS_REPO_TOKEN
description: |
Your Coveralls Repo token defined in your Circle's Environment Variables.
type: env_var_name
verbose:
default: false
description: |
Set to true for debug output. Deprecated, use debug instead.
type: boolean
steps:
- run:
command: |
#!/bin/bash
# Enable set -x debugging if COVERALLS_DEBUG or COVERALLS_VERBOSE (deprecated) is set to "1"
if [ "${COVERALLS_DEBUG}" == "1" ] || [ "${COVERALLS_VERBOSE}" == "1" ]; then
set -x
fi
# Determine which version of coverage-reporter to download
if [ -z "$COVERAGE_REPORTER_VERSION" ] || [ "$COVERAGE_REPORTER_VERSION" == "latest" ]; then
asset_path="latest/download"
else
asset_path="download/${COVERAGE_REPORTER_VERSION}"
fi
# 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).
# Function to compare version numbers
version_ge() {
# Compare two version numbers
[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ]
}
# Determine platform-specific filename
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 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
# Attempt to download the Coveralls binary and checksum file
if ! curl -sfLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/${platform_filename}" ||
! curl -sfLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/coveralls-checksums.txt"; then
echo "Failed to download coveralls binary or checksum for version: ${COVERAGE_REPORTER_VERSION}."
echo "This may be due to an invalid version. Please check the available versions at https://github.com/coverallsapp/coverage-reporter/releases."
[ "${COVERALLS_FAIL_ON_ERROR}" != "1" ] && exit 0
exit 1
fi
# Verify the downloaded binary:
# The following code was chosen to replace the more simple `sha256sum -c` because it provides
# clearer debugging information re: our 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.
# 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}. This may indicate an invalid version."
[ "${COVERALLS_FAIL_ON_ERROR}" != "1" ] && 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."
echo "Expected: $expected_checksum"
echo "Actual: $actual_checksum"
[ "${COVERALLS_FAIL_ON_ERROR}" != "1" ] && exit 0
exit 1
fi
# Extract / install the binary
if ! tar -xzf "${platform_filename}"; then
echo "Failed to extract coveralls binary."
[ "${COVERALLS_FAIL_ON_ERROR}" != "1" ] && exit 0
exit 1
fi
# Check architecture compatibility before attempting any execution
if [ -f ./coveralls ]; then
SYSTEM_ARCH=$(uname -m)
# For versions >= v0.6.15, we need to check architecture even when platform isn't specified
if version_ge "$COVERAGE_REPORTER_VERSION" "v0.6.15"; then
if [[ -z "${COVERAGE_REPORTER_PLATFORM}" && "${SYSTEM_ARCH}" != "x86_64" ]] || \
[[ "${COVERAGE_REPORTER_PLATFORM}" == "aarch64" && "${SYSTEM_ARCH}" != "aarch64" ]] || \
[[ "${COVERAGE_REPORTER_PLATFORM}" == "x86_64" && "${SYSTEM_ARCH}" != "x86_64" ]]; then
echo "Error: Architecture mismatch. Platform: ${COVERAGE_REPORTER_PLATFORM:-x86_64}, Runner: ${SYSTEM_ARCH}"
[ "${COVERALLS_FAIL_ON_ERROR}" != "1" ] && exit 0
exit 1
fi
fi
fi
# Ensure the binary exists before attempting to run it
if [ ! -f ./coveralls ]; then
echo "Coveralls binary not found after extraction."
[ "${COVERALLS_FAIL_ON_ERROR}" != "1" ] && exit 0
exit 1
fi
# Output the version of the installed coverage reporter
echo "Installed coverage reporter version: ${COVERAGE_REPORTER_VERSION}"
./coveralls --version || echo "Failed to retrieve version"
# Pass the --debug flag to coverage-reporter if COVERALLS_DEBUG or COVERALLS_VERBOSE (deprecated) is set to "1"
echo "Parsing args"
if [ "${COVERALLS_DEBUG}" == "1" ] || [ "${COVERALLS_VERBOSE}" == "1" ]; then
args="${args} --debug"
fi
if [ "${COVERALLS_DRY_RUN}" == "1" ]; then
echo Dry run - "${COVERALLS_DRY_RUN}"
args="${args} --dry-run"
fi
if [ -z "${COVERALLS_REPO_TOKEN}" ]; then
# shellcheck disable=SC2155
export COVERALLS_REPO_TOKEN=$(printenv "${COVERALLS_REPO_TOKEN_ENV}")
fi
if [ "${COVERALLS_MEASURE}" == "1" ]; then
args="${args} --measure"
fi
if [ "${COVERALLS_FAIL_ON_ERROR}" != "1" ]; then
args="${args} --no-fail"
fi
if [ "${COVERALLS_DONE}" == "1" ]; then
echo "Reporting parallel done"
set -x
# shellcheck disable=SC2086
if ! ./coveralls 'done' ${args}; then
# If fail_on_error is not set to "1", override the exit status to 0
[ "${COVERALLS_FAIL_ON_ERROR}" != "1" ] && exit 0
exit 1
fi
exit 0
fi
if [ -n "${COVERALLS_BASE_PATH}" ]; then
args="${args} --base-path ${COVERALLS_BASE_PATH}"
fi
if [ -n "${COVERALLS_COVERAGE_FORMAT}" ]; then
args="${args} --format ${COVERALLS_COVERAGE_FORMAT}"
fi
# Check for coverage file presence
if [ -n "${COVERALLS_COVERAGE_FILE}" ]; then
coverage_file="$(readlink -f "$COVERALLS_COVERAGE_FILE")"
if [ ! -e "${coverage_file}" ]; then
echo "Please specify a valid 'coverage_file' parameter. File doesn't exist. Filename: ${COVERALLS_COVERAGE_FILE}"
exit 1
elif [ ! -r "${coverage_file}" ]; then
echo "Please specify a valid 'coverage_file' parameter. File is not readable. Filename: ${COVERALLS_COVERAGE_FILE}"
exit 1
elif [ ! -f "${coverage_file}" ]; then
echo "Please specify a valid 'coverage_file' parameter. File specified is not a regular file. Filename: ${COVERALLS_COVERAGE_FILE}"
exit 1
fi
args="${args} ${coverage_file}"
fi
if [ -n "${COVERALLS_COVERAGE_FILES}" ]; then
args="${args} ${COVERALLS_COVERAGE_FILES}"
fi
echo "Reporting coverage"
set -x
# shellcheck disable=SC2086
if ! ./coveralls report $args; then
# If fail_on_error is not set to "1", override the exit status to 0
[ "${COVERALLS_FAIL_ON_ERROR}" != "1" ] && exit 0
exit 1
fi
environment:
COVERAGE_REPORTER_PLATFORM: << parameters.coverage_reporter_platform >>
COVERAGE_REPORTER_VERSION: << parameters.coverage_reporter_version >>
COVERALLS_BASE_PATH: << parameters.base_path >>
COVERALLS_CARRYFORWARD_FLAGS: << parameters.carryforward >>
COVERALLS_COMPARE_REF: << parameters.compare_ref >>
COVERALLS_COMPARE_SHA: << parameters.compare_sha >>
COVERALLS_COVERAGE_FILE: << parameters.coverage_file >>
COVERALLS_COVERAGE_FILES: << parameters.coverage_files >>
COVERALLS_COVERAGE_FORMAT: << parameters.coverage_format >>
COVERALLS_DEBUG: << parameters.debug >>
COVERALLS_DONE: << parameters.parallel_finished >>
COVERALLS_DRY_RUN: << parameters.dry_run >>
COVERALLS_ENDPOINT: << parameters.coveralls_endpoint >>
COVERALLS_FAIL_ON_ERROR: << parameters.fail_on_error >>
COVERALLS_FLAG_NAME: << parameters.flag_name >>
COVERALLS_MEASURE: << parameters.measure >>
COVERALLS_PARALLEL: << parameters.parallel >>
COVERALLS_REPO_TOKEN_ENV: << parameters.token >>
COVERALLS_SOURCE_HEADER: circleci-orb
COVERALLS_VERBOSE: << parameters.verbose >>
name: Upload Coverage Results To Coveralls
examples:
parallel:
description: |
Coveralls parallel build. 'build' jobs uploads coverage, then 'done' job hits parallel complete webhook to finish the build. Demo: https://github.com/coverallsapp/actions-demo
usage:
version: "2.1"
orbs:
coveralls: coveralls/coveralls@x.y.z
jobs:
build-1:
build-2:
docker:
- image: circleci/node:10.0.0
steps:
- checkout
- run:
command: npm install && make test-coverage-2
name: Install and Make 2
- coveralls/upload:
flag_name: job2
parallel: true
docker:
- image: circleci/node:10.0.0
steps:
- checkout
- run:
command: npm install && make test-coverage-1
name: Install and Make 1
- coveralls/upload:
flag_name: job1
parallel: true
done:
docker:
- image: circleci/node:10.0.0
steps:
- coveralls/upload:
carryforward: job1,job2
parallel_finished: true
workflows:
test_parallel_then_upload:
jobs:
- build-1
- build-2
- done:
requires:
- build-1
- build-2
workflows: null
simple:
description: |
Build and upload to Coveralls in single job. Demo: https://github.com/coverallsapp/actions-demo
usage:
version: "2.1"
orbs:
coveralls: coveralls/coveralls@1.0.6
jobs:
build:
docker:
- image: circleci/node:10.0.0
steps:
- checkout
- run:
command: npm install && make test-coverage
name: Install and Make
- coveralls/upload
workflows: null