Skip to content

Commit

Permalink
SetupDevEnv.jl: Check for QED package version and set it in the compa…
Browse files Browse the repository at this point in the history
…t section of other packages (#79)

If a QED package has increased its version, all other QED packages will
continue to work in the CI tests, even if they have not yet updated
their compat section.

- [x] CI must pass: QEDjl-project/QEDcore.jl#77
  • Loading branch information
SimeonEhrig authored Oct 28, 2024
2 parents 381783c + 19bdef0 commit 6316403
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 52 deletions.
35 changes: 30 additions & 5 deletions .ci/SetupDevEnv/src/SetupDevEnv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ Side effects of the function are:
# Args
- `repository_base_path::AbstractString`: Base folder into which the QED projects are to be cloned.
- `compat_changes::Dict{String,String}`: All QED package versions are added so that they can be set
correctly in the Compat section of the other QED packages. Existing entries are not changed.
- `custom_urls::Dict{String,String}`: By default, the URL pattern
`https://github.com/QEDjl-project/<package name>.jl` is used for the clone and the dev branch
is checked out. The dict allows the use of custom URLs and branches for each QED project. The
Expand All @@ -276,18 +278,25 @@ possible.
"""
function build_qed_dependency_graph!(
repository_base_path::AbstractString,
compat_changes::Dict{String,String},
custom_urls::Dict{String,String}=Dict{String,String}(),
)::Dict
@info "build QED dependency graph"
io = IOBuffer()
println(io, "input compat_changes: $(compat_changes)")

qed_dependency_graph = Dict()
qed_dependency_graph["QuantumElectrodynamics"] = _build_qed_dependency_graph!(
repository_base_path,
compat_changes,
custom_urls,
"QuantumElectrodynamics",
["QuantumElectrodynamics"],
)
println(io, "output compat_changes: $(compat_changes)")
with_logger(debuglogger) do
@debug "QED graph:\n$(_render_qed_tree(qed_dependency_graph))"
println(io, "QED graph:\n$(_render_qed_tree(qed_dependency_graph))")
@debug String(take!(io))
end
return qed_dependency_graph
end
Expand All @@ -303,6 +312,8 @@ end
# Args
- `repository_base_path::AbstractString`: Base folder into which the QED projects will be cloned.
- `compat_changes::Dict{String,String}`: All QED package versions are added so that they can be set
correctly in the Compat section of the other QED packages. Existing entries are not changed.
- `custom_urls::Dict{String,String}`: By default, the URL pattern
`https://github.com/QEDjl-project/<package name>.jl` is used for the clone and the dev branch
is checked out. The dict allows the use of custom URLs and branches for each QED project. The
Expand All @@ -318,6 +329,7 @@ possible.
"""
function _build_qed_dependency_graph!(
repository_base_path::AbstractString,
compat_changes::Dict{String,String},
custom_urls::Dict{String,String},
package_name::String,
origin::Vector{String},
Expand All @@ -339,6 +351,13 @@ function _build_qed_dependency_graph!(
# read dependencies from Project.toml and clone next packages until no
# QED dependencies are left
project_toml = TOML.parsefile(joinpath(repository_path, "Project.toml"))

# add package version to compat entires, that they can be set correctly in the compat section of
# other packages
if !(project_toml["name"] in keys(compat_changes))
compat_changes[project_toml["name"]] = project_toml["version"]
end

if haskey(project_toml, "deps")
for dep_pkg in keys(project_toml["deps"])
# check for circular dependency
Expand All @@ -359,7 +378,11 @@ function _build_qed_dependency_graph!(
# handle only dependency starting with QED
if startswith(dep_pkg, "QED")
qed_dependency_graph[dep_pkg] = _build_qed_dependency_graph!(
repository_base_path, custom_urls, dep_pkg, vcat(origin, [dep_pkg])
repository_base_path,
compat_changes,
custom_urls,
dep_pkg,
vcat(origin, [dep_pkg]),
)
end
end
Expand Down Expand Up @@ -593,14 +616,16 @@ function set_compat_helper(
name::AbstractString, version::AbstractString, project_path::AbstractString
)
project_toml_path = joinpath(project_path, "Project.toml")
@info "change compat of $project_toml_path: $(name) -> $(version)"

f = open(project_toml_path, "r")
project_toml = TOML.parse(f)
close(f)

if haskey(project_toml, "compat") && haskey(project_toml["compat"], name)
project_toml["compat"][name] = version
if project_toml["compat"][name] != version
@info "change compat of $project_toml_path: $(name) -> $(version)"
project_toml["compat"][name] = version
end
end

# for GitHub Actions to fix permission denied error
Expand All @@ -622,7 +647,7 @@ if abspath(PROGRAM_FILE) == @__FILE__

qed_path = mktempdir(; cleanup=false)

pkg_tree = build_qed_dependency_graph!(qed_path, custom_urls)
pkg_tree = build_qed_dependency_graph!(qed_path, compat_changes, custom_urls)
pkg_ordering = get_package_dependecy_list(pkg_tree)

required_deps = get_filtered_dependencies(
Expand Down
2 changes: 2 additions & 0 deletions .ci/integTestGen/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ version = "0.1.0"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
IntegrationTests = "6be7cfa2-1838-408e-bc49-3a824ac3a1fb"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
Expand Down
60 changes: 13 additions & 47 deletions .ci/integTestGen/src/integTestGen.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module integTestGen

include("get_target_branch.jl")
include("utils.jl")

using Pkg: Pkg
using YAML: YAML
Expand All @@ -22,49 +23,6 @@ mutable struct PackageInfo
PackageInfo(url, env_var) = new(url, "", env_var)
end

"""
create_working_env(project_path::AbstractString, package_infos::AbstractDict{String,PackageInfo})
Create a temporary folder, and set up a new Project.toml and activate it. Checking the dependencies of
a project only works, if it is a dependency of the integTestGen.jl. The package to be analyzed
is only a temporary dependency, it must not change the Project.toml of integTestGen.jl permanently.
Therefore, the script generates a temporary Julia environment and adds the package
to analyze as a dependency.
# Args
`project_path::AbstractString`: Absolute path to the project folder of the package to be analyzed
`package_infos::AbstractDict{String,PackageInfo}`: List depending QED pojects of QuantumElectrodynamics.jl. Use the list to
add the current dev branch version of the packages to the environment or a custom repository with
custom branch.
"""
function create_working_env(
project_path::AbstractString, package_infos::AbstractDict{String,PackageInfo}
)
tmp_path = mktempdir()
Pkg.activate(tmp_path)
# same dependency like in the Project.toml of integTestGen.jl
Pkg.add("Pkg")
Pkg.add("YAML")
# add main project as dependency
Pkg.develop(; path=project_path)

for package_info in values(package_infos)
if package_info.modified_url == ""
# add current dev branch version of the package
Pkg.add(; url=package_info.url)
continue
end
split_url = split(package_info.modified_url, "#")
if length(split_url) == 2
# add custom branch version of a custom repository
Pkg.add(; url=split_url[1], rev=split_url[2])
else
# add current dev branch version of a custom repository
Pkg.add(; url=split_url[1])
end
end
end

"""
extract_env_vars_from_git_message!(package_infos::AbstractDict{String, PackageInfo}, var_name = "CI_COMMIT_MESSAGE")
Expand Down Expand Up @@ -287,11 +245,19 @@ if abspath(PROGRAM_FILE) == @__FILE__
modify_package_url!(package_infos)
modified_pkg = modified_package_name(package_infos)

# the script is locate in ci/integTestGen/src
# so we need to go 3 steps upwards in hierarchy to get the QuantumElectrodynamics.jl Project.toml
create_working_env(abspath(joinpath((@__DIR__), "../../..")), package_infos)
# TODO(SimeonEhrig): refactor me, that the conversion is not required anymore
custom_urls = Dict{String,String}()
for (name, info) in package_infos
if info.modified_url != ""
custom_urls[name] = info.modified_url
end
end
qed_path = mktempdir(; cleanup=false)
compat_changes = Dict{String,String}()

pkg_tree = build_qed_dependency_graph!(qed_path, compat_changes, custom_urls)
depending_pkg = IntegrationTests.depending_projects(
modified_pkg, collect(keys(package_infos))
modified_pkg, collect(keys(package_infos)), pkg_tree
)

job_yaml = Dict()
Expand Down
Loading

0 comments on commit 6316403

Please sign in to comment.