@@ -10,6 +10,24 @@ Pkg.precompile()
1010
1111import 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+
1331function 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,16 +94,90 @@ function print_coverage_summary(
7694 return nothing
7795end
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+ if strip (commit) == " HEAD"
118+ commit = head_rev_parse
119+ end
120+ if commit != = head_rev_parse
121+ msg = " mismatch"
122+ @error msg commit head_rev_parse
123+ throw (ErrorException (msg))
124+ end
125+ if ! occursin (r" ^[a-f0-9]{40}$" , commit)
126+ msg = " BUILDKITE_COMMIT does not look like a long commit SHA"
127+ @error msg commit
128+ throw (ErrorException (msg))
129+ end
130+ return (; branch, commit)
131+ end
132+
133+ function codecov_buildkite_add_local_to_kwargs ()
134+ branch, commit = buildkite_branch_and_commit ()
135+ kwargs = Coverage. Codecov. set_defaults (
136+ Dict ();
137+ branch,
138+ commit,
139+ )
140+ return kwargs
141+ end
142+
143+ function coveralls_buildkite_query_git_info ()
144+ branch, commit = buildkite_branch_and_commit ()
145+ remote_name = " origin"
146+ remote = buildkite_env (" BUILDKITE_REPO" )
147+ message = buildkite_env (" BUILDKITE_MESSAGE" )
148+ author_name = buildkite_env (
149+ " BUILDKITE_BUILD_AUTHOR" ,
150+ " BUILDKITE_BUILD_CREATOR" ,
151+ " " ,
152+ )
153+ author_email = buildkite_env (
154+ " BUILDKITE_BUILD_AUTHOR_EMAIL" ,
155+ " BUILDKITE_BUILD_CREATOR_EMAIL" ,
156+ " " ,
157+ )
158+ remotes = [
159+ Dict (
160+ " name" => remote_name,
161+ " url" => remote,
162+ )
163+ ]
164+ head = Dict (
165+ " id" => commit,
166+ " author_name" => author_name,
167+ " author_email" => author_email,
168+ " committer_name" => author_name,
169+ " committer_email" => author_email,
170+ " message" => message,
171+ )
172+ git_info = Dict (
173+ " branch" => branch,
174+ " remotes" => remotes,
175+ " head" => head,
176+ )
177+ return git_info
178+ end
179+
180+ const fcs = process_folders ()
89181
90182# Only include source code files. Exclude test files, benchmarking files, etc.
91183filter! (fcs) do fc
@@ -101,15 +193,27 @@ end;
101193# Exclude all stdlib JLLs (stdlibs of the form `stdlib/*_jll/`).
102194filter! (fcs) do fc
103195 ! occursin (r" ^stdlib\/ [A-Za-z0-9]*?_jll\/ " , fc. filename)
104- end
196+ end ;
105197
106- sort! (fcs; by = fc -> fc. filename)
198+ sort! (fcs; by = fc -> fc. filename);
107199
108200print_coverage_summary .(fcs);
109201print_coverage_summary (fcs, " Total" )
110202
111- # In order to upload to Codecov, you need to have the `CODECOV_TOKEN` environment variable defined.
112- Coverage. Codecov. submit_local (fcs)
203+ let
204+ git_info = coveralls_buildkite_query_git_info ()
205+ @info " " git_info
206+ @info " " git_info[" branch" ]
207+ @info " " git_info[" head" ]
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 Coveralls, you need to have the `COVERALLS_TOKEN` environment variable defined.
210+ Coverage. Coveralls. submit_local (fcs, git_info)
211+ end
212+
213+ let
214+ kwargs = codecov_buildkite_add_local_to_kwargs ()
215+ @info " " kwargs
216+
217+ # In order to upload to Codecov, you need to have the `CODECOV_TOKEN` environment variable defined.
218+ Coverage. Codecov. submit_generic (fcs, kwargs)
219+ end
0 commit comments