Skip to content

Commit

Permalink
use IntegrationTests.jl in .ci/src/integTestGen.jl (#70)
Browse files Browse the repository at this point in the history
~Open it as draft, because I want to test the package with the QED
ecosystem, before I release.~

fix #27
  • Loading branch information
SimeonEhrig authored Sep 25, 2024
2 parents 8a59462 + f3b1c95 commit 71ffbcc
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 239 deletions.
2 changes: 1 addition & 1 deletion .ci/integTestGen/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ version = "0.1.0"

[deps]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
IntegrationTests = "6be7cfa2-1838-408e-bc49-3a824ac3a1fb"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PkgDependency = "9eb5382b-762c-48ca-8139-e736883fe800"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
Expand Down
80 changes: 4 additions & 76 deletions .ci/integTestGen/src/integTestGen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module integTestGen
include("get_target_branch.jl")

using Pkg: Pkg
using PkgDependency: PkgDependency
using YAML: YAML
using Logging
using IntegrationTests

"""
Contains all git-related information about a package.
Expand Down Expand Up @@ -44,7 +44,6 @@ function create_working_env(
Pkg.activate(tmp_path)
# same dependency like in the Project.toml of integTestGen.jl
Pkg.add("Pkg")
Pkg.add("PkgDependency")
Pkg.add("YAML")
# add main project as dependency
Pkg.develop(; path=project_path)
Expand Down Expand Up @@ -125,84 +124,11 @@ function modified_package_name(package_infos::AbstractDict{String,PackageInfo})
end
end

"""
depending_projects(package_name, package_prefix, project_tree)
Return a list of packages, which have the package `package_name` as a dependency. Ignore all packages, which do not start with `package_prefix`.
# Arguments
- `package_name::String`: Name of the dependency
- `package_filter`: If the package name is not included in package_filter, the dependency is not checked.
- `project_tree=PkgDependency.builddict(Pkg.project().uuid, Pkg.project())`: Project tree, where to search the dependent packages. Needs to be a nested dict.
Each (sub-) package needs to be AbstractDict{String, AbstractDict}
# Returns
- `::AbstractVector{String}`: all packages which have the search dependency
"""
function depending_projects(
package_name::String,
package_filter::AbstractVector{<:AbstractString},
project_tree=PkgDependency.builddict(Pkg.project().uuid, Pkg.project()),
)::AbstractVector{String}
packages::AbstractVector{String} = []
visited_packages::AbstractVector{String} = []
traverse_tree!(package_name, package_filter, project_tree, packages, visited_packages)
return packages
end

function clean_pkg_name(pkg_name::AbstractString)
# remove color tags (?) from the package names
return replace(pkg_name, r"\{[^}]*\}" => "")
end

"""
traverse_tree!(package_name::String, package_filter, project_tree, packages::AbstractVector{String}, visited_packages::AbstractVector{String})
Traverse a project tree and add any package to `packages`, that has the package `package_name` as a dependency. Ignore all packages that are not included in `package_filter`.
See [`depending_projects`](@ref)
"""
function traverse_tree!(
package_name::String,
package_filter::AbstractVector{<:AbstractString},
project_tree::AbstractVector{<:PkgDependency.PkgTree},
packages::AbstractVector{String},
visited_packages::AbstractVector{String},
)
for pkg_tree in project_tree
project_name_version = clean_pkg_name(pkg_tree.name)

# remove project version from string -> usual shape: `packageName.jl version`
project_name = split(project_name_version)[1]
# fullfil the requirements
# - package starts with the prefix
# - the dependency is not nothing (I think this representate, that the package was already set as dependency of a another package and therefore do not repead the dependencies)
# - has dependency
# - was not already checked

if project_name in package_filter &&
!isempty(pkg_tree.children) &&
!(project_name in visited_packages)
# only investigate each package one time
# assumption: package name with it's dependency is unique
push!(visited_packages, project_name)
for dependency in pkg_tree.children
dependency_name_version = clean_pkg_name(dependency.name)
# dependency matches, add to packages
if startswith(dependency_name_version, package_name)
push!(packages, project_name)
break
end
end
# independent of a match, investigate all dependencies too, because they can also have the package as dependency
traverse_tree!(
package_name, package_filter, pkg_tree.children, packages, visited_packages
)
end
end
end

"""
generate_job_yaml!(package_name::String, job_yaml::Dict)
Expand Down Expand Up @@ -350,7 +276,9 @@ if abspath(PROGRAM_FILE) == @__FILE__
# 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)
depending_pkg = depending_projects(modified_pkg, collect(keys(package_infos)))
depending_pkg = IntegrationTests.depending_projects(
modified_pkg, collect(keys(package_infos))
)

job_yaml = Dict()

Expand Down
1 change: 0 additions & 1 deletion .ci/integTestGen/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[deps]
PkgDependency = "9eb5382b-762c-48ca-8139-e736883fe800"
Term = "22787eb5-b846-44ae-b979-8e399b8463ab"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
160 changes: 0 additions & 160 deletions .ci/integTestGen/test/integTestGen.jl

This file was deleted.

1 change: 0 additions & 1 deletion .ci/integTestGen/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using integTestGen
using Test

include("./integTestGen.jl")
include("./get_target_branch.jl")
include("./generate_job_yaml.jl")

0 comments on commit 71ffbcc

Please sign in to comment.