Skip to content

Commit f5c2661

Browse files
add build_num because coveralls parallel requires it
1 parent 79f05e0 commit f5c2661

File tree

3 files changed

+75
-10
lines changed

3 files changed

+75
-10
lines changed

examples/parallel_upload_example.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Example: Simple parallel coverage upload using process_and_upload
2+
# This demonstrates the easy way to use the new parallel features
3+
4+
using Coverage
5+
6+
# For simple parallel workflows, you can use process_and_upload with :both service
7+
# This automatically handles both Codecov and Coveralls with parallel options
8+
9+
# Example 1: Basic parallel upload
10+
results = Coverage.process_and_upload(;
11+
service=:both,
12+
folder="src",
13+
codecov_flags=["julia-1.9", "linux"],
14+
codecov_build_id=get(ENV, "BUILD_ID", nothing),
15+
coveralls_parallel=true,
16+
coveralls_job_flag="julia-1.9-linux",
17+
dry_run=false # Set to true for testing
18+
)
19+
20+
# Example 2: More comprehensive parallel setup
21+
julia_version = "julia-$(VERSION.major).$(VERSION.minor)"
22+
platform = Sys.islinux() ? "linux" : Sys.isapple() ? "macos" : "windows"
23+
build_id = get(ENV, "BUILDKITE_BUILD_NUMBER", get(ENV, "GITHUB_RUN_ID", nothing))
24+
25+
results = Coverage.process_and_upload(;
26+
service=:both,
27+
folder="src",
28+
codecov_flags=[julia_version, platform, "coverage"],
29+
codecov_name="coverage-$(platform)-$(julia_version)",
30+
codecov_build_id=build_id,
31+
coveralls_parallel=true,
32+
coveralls_job_flag="$(julia_version)-$(platform)",
33+
dry_run=false
34+
)
35+
36+
@info "Upload results" results
37+
38+
# After all parallel jobs complete, call finish_coveralls_parallel()
39+
# (Usually in a separate CI job)
40+
# Coverage.finish_coveralls_parallel()

src/ci_integration_functions.jl

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function upload_to_codecov(fcs::Vector{FileCoverage};
114114
end
115115

116116
"""
117-
upload_to_coveralls(fcs::Vector{FileCoverage}; format=:lcov, token=nothing, parallel=nothing, job_flag=nothing, dry_run=false, cleanup=true)
117+
upload_to_coveralls(fcs::Vector{FileCoverage}; format=:lcov, token=nothing, parallel=nothing, job_flag=nothing, build_num=nothing, dry_run=false, cleanup=true)
118118
119119
Process coverage data and upload to Coveralls using the Universal Coverage Reporter.
120120
@@ -124,27 +124,29 @@ Process coverage data and upload to Coveralls using the Universal Coverage Repor
124124
- `token`: Coveralls repo token (defaults to COVERALLS_REPO_TOKEN environment variable)
125125
- `parallel`: Set to true for parallel job uploads (requires calling finish_parallel afterwards)
126126
- `job_flag`: Flag to distinguish this job in parallel builds (e.g., "julia-1.9-linux")
127+
- `build_num`: Build number for grouping parallel jobs (overrides COVERALLS_SERVICE_NUMBER environment variable)
127128
- `dry_run`: If true, show what would be uploaded without actually uploading
128129
- `cleanup`: If true, remove temporary files after upload
129130
130131
# Parallel Job Usage
131132
For parallel CI jobs, set parallel=true and call finish_parallel when all jobs complete:
132133
```julia
133134
# Job 1: Upload with parallel flag
134-
upload_to_coveralls(fcs; parallel=true, job_flag="julia-1.9")
135+
upload_to_coveralls(fcs; parallel=true, job_flag="julia-1.9", build_num="123")
135136
136137
# Job 2: Upload with parallel flag
137-
upload_to_coveralls(fcs; parallel=true, job_flag="julia-1.10")
138+
upload_to_coveralls(fcs; parallel=true, job_flag="julia-1.10", build_num="123")
138139
139140
# After all jobs: Signal completion (typically in a separate "finalize" job)
140-
finish_coveralls_parallel()
141+
finish_coveralls_parallel(build_num="123")
141142
```
142143
"""
143144
function upload_to_coveralls(fcs::Vector{FileCoverage};
144145
format=:lcov,
145146
token=nothing,
146147
parallel=nothing,
147148
job_flag=nothing,
149+
build_num=nothing,
148150
dry_run=false,
149151
cleanup=true)
150152

@@ -187,6 +189,14 @@ function upload_to_coveralls(fcs::Vector{FileCoverage};
187189
env["COVERALLS_FLAG_NAME"] = job_flag
188190
end
189191

192+
# Set build number for grouping parallel jobs
193+
if build_num !== nothing
194+
env["COVERALLS_SERVICE_NUMBER"] = string(build_num)
195+
@debug "Using explicit build number for Coveralls" build_num=build_num
196+
elseif haskey(ENV, "COVERALLS_SERVICE_NUMBER")
197+
@debug "Using environment COVERALLS_SERVICE_NUMBER" service_number=ENV["COVERALLS_SERVICE_NUMBER"]
198+
end
199+
190200
# Execute command
191201
if dry_run
192202
@info "Would execute: $(join(cmd_args, " "))"
@@ -284,14 +294,18 @@ function process_and_upload(; service=:both,
284294
end
285295

286296
"""
287-
finish_coveralls_parallel(; token=nothing)
297+
finish_coveralls_parallel(; token=nothing, build_num=nothing)
288298
289299
Signal to Coveralls that all parallel jobs have completed and coverage can be processed.
290300
This should be called once after all parallel upload_to_coveralls() calls are complete.
291301
302+
# Arguments
303+
- `token`: Coveralls repo token (defaults to COVERALLS_REPO_TOKEN environment variable)
304+
- `build_num`: Build number for the parallel jobs (overrides COVERALLS_SERVICE_NUMBER environment variable)
305+
292306
Call this from a separate CI job that runs after all parallel coverage jobs finish.
293307
"""
294-
function finish_coveralls_parallel(; token=nothing)
308+
function finish_coveralls_parallel(; token=nothing, build_num=nothing)
295309
# Add token if provided or available in environment
296310
upload_token = token
297311
if upload_token === nothing
@@ -302,9 +316,20 @@ function finish_coveralls_parallel(; token=nothing)
302316
end
303317

304318
# Prepare the completion webhook payload
319+
payload_data = Dict("status" => "done")
320+
321+
# Add build number if provided or available in environment
322+
service_number = build_num !== nothing ? string(build_num) : get(ENV, "COVERALLS_SERVICE_NUMBER", nothing)
323+
if service_number !== nothing && service_number != ""
324+
payload_data["build_num"] = service_number
325+
@info "Using build number for parallel completion" build_num=service_number
326+
else
327+
@warn "No build number available for parallel completion - this may cause issues with parallel job grouping"
328+
end
329+
305330
payload = Dict(
306331
"repo_token" => upload_token,
307-
"payload" => Dict("status" => "done")
332+
"payload" => payload_data
308333
)
309334

310335
@info "Signaling Coveralls parallel job completion..."

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,15 +1254,15 @@ withenv(
12541254
@test_logs (:error, r"Failed to upload to TestService") (:warn, r"Check if the repository is registered with TestService") begin
12551255
@test Coverage.CoverageUtils.handle_upload_error(ErrorException("404 Not Found"), "TestService") == false
12561256
end
1257-
1257+
12581258
@test_logs (:error, r"Failed to upload to TestService") (:warn, r"Authentication failed. Check your TestService token") begin
12591259
@test Coverage.CoverageUtils.handle_upload_error(ErrorException("401 Unauthorized"), "TestService") == false
12601260
end
1261-
1261+
12621262
@test_logs (:error, r"Failed to upload to TestService") (:warn, r"Connection timeout. Check your network connection") begin
12631263
@test Coverage.CoverageUtils.handle_upload_error(ErrorException("Connection timeout"), "TestService") == false
12641264
end
1265-
1265+
12661266
@test_logs (:error, r"Failed to upload to TestService") begin
12671267
@test Coverage.CoverageUtils.handle_upload_error(ErrorException("Generic error"), "TestService") == false
12681268
end

0 commit comments

Comments
 (0)