Skip to content

Commit 9294e3e

Browse files
committed
CI: use refactored custom URL functions Bootloader.jl
1 parent c84193a commit 9294e3e

File tree

6 files changed

+74
-282
lines changed

6 files changed

+74
-282
lines changed

.ci/CI/src/Bootloader.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,16 @@ function main()
501501
end
502502

503503
if is_integ
504+
custom_dependency_urls = CustomDependencyUrls()
505+
append_custom_dependency_urls_from_git_message!(custom_dependency_urls)
506+
append_custom_dependency_urls_from_env_var!(custom_dependency_urls)
507+
504508
add_integration_test_job_yaml!(
505-
cpu_job_yaml, test_package, target_branch, tools_git_repo
509+
cpu_job_yaml,
510+
test_package,
511+
target_branch,
512+
custom_dependency_urls.integ,
513+
tools_git_repo,
506514
)
507515
end
508516

.ci/CI/src/modules/IntegTest.jl

Lines changed: 11 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,6 @@ using YAML: YAML
33
using Logging
44
using IntegrationTests
55

6-
"""
7-
Contains all git-related information about a package.
8-
9-
# Fields
10-
- `url`: Git url of the original project.
11-
- `modified_url`: Stores the Git url set by the environment variable.
12-
- `env_var`: Name of the environment variable to set the modified_url.
13-
"""
14-
mutable struct PackageInfo
15-
url::String
16-
modified_url::String
17-
env_var::String
18-
PackageInfo(url, env_var) = new(url, "", env_var)
19-
end
20-
21-
"""
22-
extract_env_vars_from_git_message!(package_infos::AbstractDict{String, PackageInfo}, var_name = "CI_COMMIT_MESSAGE")
23-
24-
Parse the commit message, if set via variable (usual `CI_COMMIT_MESSAGE`), and set custom URLs.
25-
"""
26-
function extract_env_vars_from_git_message!(
27-
package_infos::AbstractDict{String,PackageInfo}, var_name="CI_COMMIT_MESSAGE"
28-
)
29-
if haskey(ENV, var_name)
30-
for line in split(ENV[var_name], "\n")
31-
line = strip(line)
32-
for pkg_info in values(package_infos)
33-
if startswith(line, pkg_info.env_var * ": ")
34-
ENV[pkg_info.env_var] = SubString(
35-
line, length(pkg_info.env_var * ": ") + 1
36-
)
37-
end
38-
end
39-
end
40-
end
41-
end
42-
43-
"""
44-
modify_package_url!(package_infos::AbstractDict{String, PackageInfo})
45-
46-
Iterate over all entries of package_info. If an environment variable exists with the same name as,
47-
the `env_var` entry, set the value of the environment variable to `modified_url`.
48-
"""
49-
function modify_package_url!(package_infos::AbstractDict{String,PackageInfo})
50-
for package_info in values(package_infos)
51-
if haskey(ENV, package_info.env_var)
52-
package_info.modified_url = ENV[package_info.env_var]
53-
end
54-
end
55-
end
56-
57-
"""
58-
modified_package_name(package_infos::AbstractDict{String, PackageInfo})
59-
60-
Read the name of the modified (project) package from the environment variable `CI_DEV_PKG_NAME`.
61-
62-
# Returns
63-
- The name of the modified (project) package
64-
"""
65-
function modified_package_name(package_infos::AbstractDict{String,PackageInfo})
66-
for env_var in ["CI_DEV_PKG_NAME", "CI_PROJECT_DIR"]
67-
if !haskey(ENV, env_var)
68-
error("Environment variable $env_var is not set.")
69-
end
70-
end
71-
72-
if !haskey(package_infos, ENV["CI_DEV_PKG_NAME"])
73-
package_name = ENV["CI_DEV_PKG_NAME"]
74-
error("Error unknown package name $package_name}")
75-
else
76-
return ENV["CI_DEV_PKG_NAME"]
77-
end
78-
end
79-
80-
function clean_pkg_name(pkg_name::AbstractString)
81-
# remove color tags (?) from the package names
82-
return replace(pkg_name, r"\{[^}]*\}" => "")
83-
end
84-
856
"""
867
generate_job_yaml!(
878
package_name::String,
@@ -114,17 +35,15 @@ function generate_job_yaml!(
11435
test_package::TestPackage,
11536
target_branch::AbstractString,
11637
job_yaml::Dict,
117-
package_infos::AbstractDict{String,PackageInfo},
38+
custom_urls::Dict{String,String},
11839
tools_git_repo::ToolsGitRepo,
11940
stage::AbstractString="",
12041
can_fail::Bool=false,
12142
)
122-
package_info = package_infos[package_name]
123-
# if modified_url is empty, use original url
124-
if package_info.modified_url == ""
125-
url = package_info.url
43+
if haskey(custom_urls, package_name)
44+
url = custom_urls[package_name]
12645
else
127-
url = package_info.modified_url
46+
url = "https://github.com/QEDjl-project/$(package_name).jl.git"
12847
end
12948

13049
script = ["apt update", "apt install -y git", "cd /"]
@@ -201,38 +120,6 @@ function generate_dummy_job_yaml!(job_yaml::Dict)
201120
)
202121
end
203122

204-
"""
205-
get_package_info()::Dict{String,PackageInfo}
206-
207-
Returns a list with QED project package information.
208-
"""
209-
function get_package_info()::Dict{String,PackageInfo}
210-
return Dict(
211-
"QuantumElectrodynamics" => PackageInfo(
212-
"https://github.com/QEDjl-project/QuantumElectrodynamics.jl.git",
213-
"CI_INTG_PKG_URL_QED",
214-
),
215-
"QEDfields" => PackageInfo(
216-
"https://github.com/QEDjl-project/QEDfields.jl.git",
217-
"CI_INTG_PKG_URL_QEDfields",
218-
),
219-
"QEDbase" => PackageInfo(
220-
"https://github.com/QEDjl-project/QEDbase.jl.git", "CI_INTG_PKG_URL_QEDbase"
221-
),
222-
"QEDevents" => PackageInfo(
223-
"https://github.com/QEDjl-project/QEDevents.jl.git",
224-
"CI_INTG_PKG_URL_QEDevents",
225-
),
226-
"QEDprocesses" => PackageInfo(
227-
"https://github.com/QEDjl-project/QEDprocesses.jl.git",
228-
"CI_INTG_PKG_URL_QEDprocesses",
229-
),
230-
"QEDcore" => PackageInfo(
231-
"https://github.com/QEDjl-project/QEDcore.jl.git", "CI_INTG_PKG_URL_QEDcore"
232-
),
233-
)
234-
end
235-
236123
"""
237124
add_integration_test_job_yaml!(
238125
job_dict::Dict,
@@ -255,28 +142,21 @@ function add_integration_test_job_yaml!(
255142
job_dict::Dict,
256143
test_package::TestPackage,
257144
target_branch::AbstractString,
145+
custom_urls::Dict{String,String},
258146
tools_git_repo::ToolsGitRepo,
259147
)
260148
_add_stage_once!(job_dict, "integ-test")
261149

262-
package_infos = get_package_info()
263-
if target_branch != "main"
264-
extract_env_vars_from_git_message!(package_infos)
150+
if target_branch == "main"
151+
empty!(custom_urls)
265152
end
266-
modify_package_url!(package_infos)
267153

268-
custom_urls = Dict{String,String}()
269-
for (name, info) in package_infos
270-
if info.modified_url != ""
271-
custom_urls[name] = info.modified_url
272-
end
273-
end
274154
qed_path = mktempdir(; cleanup=false)
275155
compat_changes = Dict{String,String}()
276156

277157
pkg_tree = build_qed_dependency_graph!(qed_path, compat_changes, custom_urls)
278158
depending_pkg = IntegrationTests.depending_projects(
279-
test_package.name, collect(keys(package_infos)), pkg_tree
159+
test_package.name, r"^QED*|^QuantumElectrodynamics$", pkg_tree
280160
)
281161

282162
if isempty(depending_pkg)
@@ -299,20 +179,14 @@ function add_integration_test_job_yaml!(
299179
# because of their current compat entries.
300180
if target_branch == "main" && is_pull_request()
301181
generate_job_yaml!(
302-
p,
303-
test_package,
304-
"dev",
305-
job_dict,
306-
package_infos,
307-
tools_git_repo,
308-
"integ-test",
182+
p, test_package, "dev", job_dict, custom_urls, tools_git_repo, "integ-test"
309183
)
310184
generate_job_yaml!(
311185
p,
312186
test_package,
313187
"main",
314188
job_dict,
315-
package_infos,
189+
custom_urls,
316190
tools_git_repo,
317191
"integ-test",
318192
true,
@@ -326,7 +200,7 @@ function add_integration_test_job_yaml!(
326200
# simplify the interface
327201
"dev",
328202
job_dict,
329-
package_infos,
203+
custom_urls,
330204
tools_git_repo,
331205
"integ-test",
332206
)

.ci/CI/src/modules/Utils.jl

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ struct ToolsGitRepo
6565
branch::String
6666
end
6767

68+
"""
69+
struct CustomDependencyUrls
70+
71+
Stores custom repository URLs for QED packages which are dependency of the project to be tested.
72+
73+
# Members
74+
- `unit::Dict{String,String}`: Custom dependencies of the unit tests
75+
- `integ::Dict{String,String}`: Custom dependencies of the integration tests
76+
77+
"""
6878
struct CustomDependencyUrls
6979
unit::Dict{String,String}
7080
integ::Dict{String,String}
@@ -445,42 +455,6 @@ function append_custom_dependency_urls_from_git_message!(
445455
end
446456
end
447457

448-
"""
449-
extract_env_vars_from_git_message!(
450-
env_prefix::AbstractString, var_name::AbstractString="CI_COMMIT_MESSAGE"
451-
)
452-
453-
Parse the commit message, if set via variable (usual `CI_COMMIT_MESSAGE`) and set custom URLs.
454-
A line is parsed if it has the shape of:
455-
456-
<env_prefix>_rest_of_the_env_name: <value>
457-
458-
Each parsed line is added to the environment variables:
459-
460-
ENV[<env_prefix>_rest_of_the_env_name] = <value>
461-
462-
# Args
463-
- `env_prefix::AbstractString`: Parse all lines starting with the env_prefix
464-
- `var_name::AbstractString``: Environemnt variable where git message is stored
465-
(default: "CI_COMMIT_MESSAGE").
466-
467-
"""
468-
function extract_env_vars_from_git_message!(
469-
env_prefix::AbstractString, var_name::AbstractString="CI_COMMIT_MESSAGE"
470-
)
471-
if haskey(ENV, var_name)
472-
@info "Found env variable $var_name"
473-
for line in split(ENV[var_name], "\n")
474-
line = strip(line)
475-
if startswith(line, env_prefix)
476-
(pkg_name, url) = split(line, ":"; limit=2)
477-
@info "add " * pkg_name * "=" * strip(url)
478-
ENV[pkg_name] = strip(url)
479-
end
480-
end
481-
end
482-
end
483-
484458
"""
485459
_add_stage_once!(job_dict::Dict, stage_name::AbstractString)
486460

.ci/CI/test/Util/extract_custom_url_test.jl

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -156,48 +156,52 @@ end
156156
end
157157

158158
@testset "wrong custom integration test dependency URL" begin
159-
custom_dependency_urls = CI.CustomDependencyUrls()
160-
@test_throws ErrorException CI.append_custom_dependency_urls_from_git_message!(
161-
custom_dependency_urls,
162-
Dict{String,String}(
163-
"CI_COMMIT_MESSAGE" => """Git headline
159+
disable_info_logger_output() do
160+
custom_dependency_urls = CI.CustomDependencyUrls()
161+
@test_throws ErrorException CI.append_custom_dependency_urls_from_git_message!(
162+
custom_dependency_urls,
163+
Dict{String,String}(
164+
"CI_COMMIT_MESSAGE" => """Git headline
164165
165-
This is a nice message.
166-
And another line.
166+
This is a nice message.
167+
And another line.
167168
168-
CI_INTG_PKG_URL_QEDfields=https//github.com/integ/QEDfields
169-
""",
170-
),
171-
)
169+
CI_INTG_PKG_URL_QEDfields=https//github.com/integ/QEDfields
170+
""",
171+
),
172+
)
172173

173-
@test_throws ErrorException CI.append_custom_dependency_urls_from_git_message!(
174-
custom_dependency_urls,
175-
Dict{String,String}(
176-
"CI_COMMIT_MESSAGE" => """Git headline
174+
@test_throws ErrorException CI.append_custom_dependency_urls_from_git_message!(
175+
custom_dependency_urls,
176+
Dict{String,String}(
177+
"CI_COMMIT_MESSAGE" => """Git headline
177178
178-
This is a nice message.
179-
And another line.
179+
This is a nice message.
180+
And another line.
180181
181-
CI_INTG_PKG_URL_QEDfields=https://github.com/integ/QEDfields
182-
""",
183-
),
184-
)
182+
CI_INTG_PKG_URL_QEDfields=https://github.com/integ/QEDfields
183+
""",
184+
),
185+
)
186+
end
185187
end
186188

187189
@testset "wrong custom unit test dependency URL" begin
188-
custom_dependency_urls = CI.CustomDependencyUrls()
189-
@test_throws ErrorException CI.append_custom_dependency_urls_from_git_message!(
190-
custom_dependency_urls,
191-
Dict{String,String}(
192-
"CI_COMMIT_MESSAGE" => """Git headline
190+
disable_info_logger_output() do
191+
custom_dependency_urls = CI.CustomDependencyUrls()
192+
@test_throws ErrorException CI.append_custom_dependency_urls_from_git_message!(
193+
custom_dependency_urls,
194+
Dict{String,String}(
195+
"CI_COMMIT_MESSAGE" => """Git headline
193196
194-
This is a nice message.
195-
And another line.
197+
This is a nice message.
198+
And another line.
196199
197-
CI_UNIT_PKG_URL_QEDfields=https://github.com/integ/QEDfields
198-
""",
199-
),
200-
)
200+
CI_UNIT_PKG_URL_QEDfields=https://github.com/integ/QEDfields
201+
""",
202+
),
203+
)
204+
end
201205
end
202206
end
203207

0 commit comments

Comments
 (0)