Skip to content

Commit e2be560

Browse files
committed
Code coverage: fix the code coverage pipeline
1 parent 12e7223 commit e2be560

File tree

2 files changed

+124
-17
lines changed

2 files changed

+124
-17
lines changed

.buildkite/coverage-linux64/run_tests_base.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const ncores = min(Sys.CPU_THREADS, Threads.nthreads())
3030
@info "" ncores Sys.CPU_THREADS Threads.nthreads()
3131

3232
try
33-
Base.runtests(tests; ncores)
33+
# Base.runtests(tests; ncores) # TODO: uncomment this line
34+
Base.runtests(["compiler"]; ncores) # TODO: delete this line
3435
catch ex
3536
@error "" exception=(ex, catch_backtrace())
3637
end

.buildkite/coverage-linux64/upload_coverage.jl

Lines changed: 122 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ Pkg.precompile()
1010

1111
import Coverage
1212

13+
function process_folders()
14+
# `Coverage.process_folder` will have a LOT of `@info` statements that will make the log
15+
# way too long. So before we run `Coverage.process_folder`, we disable logging for `@info`
16+
# statements. After we run `Coverage.process_folder`, we re-enable logging for `@info`
17+
# statements.
18+
Logging.disable_logging(Logging.Info)
19+
fcs_base = Coverage.process_folder("base")
20+
fcs_stdlib = Coverage.process_folder("stdlib")
21+
Logging.disable_logging(Logging.Debug)
22+
23+
fcs = Coverage.merge_coverage_counts(
24+
fcs_base,
25+
fcs_stdlib,
26+
)
27+
28+
return fcs
29+
end
30+
1331
function get_external_stdlib_names(stdlib_dir::AbstractString)
1432
filename_list = filter(x -> isfile(joinpath(stdlib_dir, x)), readdir(stdlib_dir))
1533
# find all of the files like `Pkg.version`, `Statistics.version`, etc.
@@ -76,27 +94,103 @@ function print_coverage_summary(
7694
return nothing
7795
end
7896

79-
# `Coverage.process_folder` will have a LOT of `@info` statements that will make the log
80-
# way too long. So before we run `Coverage.process_folder`, we disable logging for `@info`
81-
# statements. After we run `Coverage.process_folder`, we re-enable logging for `@info`
82-
# statements.
83-
Logging.disable_logging(Logging.Info)
84-
const fcs = Coverage.merge_coverage_counts(
85-
Coverage.process_folder("base"),
86-
Coverage.process_folder("stdlib"),
87-
);
88-
Logging.disable_logging(Logging.Debug)
97+
function buildkite_env(name::String)
98+
value = String(strip(ENV[name]))
99+
if isempty(value)
100+
throw(ErrorException("environment variable $(name) is empty"))
101+
end
102+
return value
103+
end
104+
105+
function buildkite_env(name_1::String, name_2::String, default::String)
106+
value_1 = String(strip(ENV[name_1]))
107+
value_2 = String(strip(ENV[name_2]))
108+
!isempty(value_1) && return value_1
109+
!isempty(value_2) && return value_2
110+
return default
111+
end
112+
113+
function buildkite_branch_and_commit()
114+
branch = buildkite_env("BUILDKITE_BRANCH")
115+
commit = buildkite_env("BUILDKITE_COMMIT")
116+
head_rev_parse = String(strip(read(`git rev-parse HEAD`, String)))
117+
@info "" branch commit head_rev_parse
118+
if strip(commit) == "HEAD"
119+
commit = head_rev_parse
120+
end
121+
if commit !== head_rev_parse
122+
msg = "mismatch"
123+
@error msg commit head_rev_parse
124+
throw(ErrorException(msg))
125+
end
126+
if !occursin(r"^[a-f0-9]{40}$", commit)
127+
msg = "BUILDKITE_COMMIT does not look like a long commit SHA"
128+
@error msg commit
129+
throw(ErrorException(msg))
130+
end
131+
@info "" branch commit head_rev_parse
132+
return (; branch, commit)
133+
end
134+
135+
function codecov_buildkite_add_local_to_kwargs()
136+
branch, commit = buildkite_branch_and_commit()
137+
kwargs = Coverage.Codecov.set_defaults(
138+
Dict();
139+
branch,
140+
commit,
141+
)
142+
return kwargs
143+
end
144+
145+
function coveralls_buildkite_query_git_info()
146+
branch, commit = buildkite_branch_and_commit()
147+
remote_name = "origin"
148+
remote = buildkite_env("BUILDKITE_REPO")
149+
message = buildkite_env("BUILDKITE_MESSAGE")
150+
author_name = buildkite_env(
151+
"BUILDKITE_BUILD_AUTHOR",
152+
"BUILDKITE_BUILD_CREATOR",
153+
"",
154+
)
155+
author_email = buildkite_env(
156+
"BUILDKITE_BUILD_AUTHOR_EMAIL",
157+
"BUILDKITE_BUILD_CREATOR_EMAIL",
158+
"",
159+
)
160+
remotes = [
161+
Dict(
162+
"name" => remote_name,
163+
"url" => remote,
164+
)
165+
]
166+
head = Dict(
167+
"id" => commit,
168+
"author_name" => author_name,
169+
"author_email" => author_email,
170+
"committer_name" => author_name,
171+
"committer_email" => author_email,
172+
"message" => message,
173+
)
174+
git_info = Dict(
175+
"branch" => branch,
176+
"remotes" => remotes
177+
"head" => head,
178+
)
179+
return git_info
180+
end
181+
182+
const fcs = process_folders()
89183

90184
# Only include source code files. Exclude test files, benchmarking files, etc.
91185
filter!(fcs) do fc
92186
occursin(r"^base\/", fc.filename) || occursin("/src/", fc.filename)
93-
end;
187+
end
94188

95189
# Exclude all external stdlibs (stdlibs that live in external repos).
96190
const external_stdlib_prefixes = get_external_stdlib_prefixes("stdlib")
97191
filter!(fcs) do fc
98192
all(x -> !startswith(fc.filename, x), external_stdlib_prefixes)
99-
end;
193+
end
100194

101195
# Exclude all stdlib JLLs (stdlibs of the form `stdlib/*_jll/`).
102196
filter!(fcs) do fc
@@ -108,8 +202,20 @@ sort!(fcs; by = fc -> fc.filename)
108202
print_coverage_summary.(fcs);
109203
print_coverage_summary(fcs, "Total")
110204

111-
# In order to upload to Codecov, you need to have the `CODECOV_TOKEN` environment variable defined.
112-
Coverage.Codecov.submit_local(fcs)
205+
let
206+
kwargs = codecov_buildkite_add_local_to_kwargs()
207+
@info "" kwargs
113208

114-
# In order to upload to Coveralls, you need to have the `COVERALLS_TOKEN` environment variable defined.
115-
Coverage.Coveralls.submit_local(fcs)
209+
# In order to upload to Codecov, you need to have the `CODECOV_TOKEN` environment variable defined.
210+
Coverage.Codecov.submit_generic(fcs, kwargs)
211+
end
212+
213+
let
214+
git_info = coveralls_buildkite_query_git_info()
215+
@info "" git_info["branch"]
216+
@info "" git_info["head"]
217+
@info "" git_info["head"]["id"]
218+
219+
# In order to upload to Coveralls, you need to have the `COVERALLS_TOKEN` environment variable defined.
220+
Coverage.Coveralls.submit_local(fcs, git_info)
221+
end

0 commit comments

Comments
 (0)