diff --git a/.ci/integTestGen/Project.toml b/.ci/integTestGen/Project.toml index 5bb78f5..e6ac616 100644 --- a/.ci/integTestGen/Project.toml +++ b/.ci/integTestGen/Project.toml @@ -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] diff --git a/.ci/integTestGen/src/integTestGen.jl b/.ci/integTestGen/src/integTestGen.jl index b801802..0dfa26e 100644 --- a/.ci/integTestGen/src/integTestGen.jl +++ b/.ci/integTestGen/src/integTestGen.jl @@ -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. @@ -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) @@ -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) @@ -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() diff --git a/.ci/integTestGen/test/Project.toml b/.ci/integTestGen/test/Project.toml index b12d2e9..3d2eae6 100644 --- a/.ci/integTestGen/test/Project.toml +++ b/.ci/integTestGen/test/Project.toml @@ -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" diff --git a/.ci/integTestGen/test/integTestGen.jl b/.ci/integTestGen/test/integTestGen.jl deleted file mode 100644 index 46b2f85..0000000 --- a/.ci/integTestGen/test/integTestGen.jl +++ /dev/null @@ -1,160 +0,0 @@ -using PkgDependency - -import Term.Trees: Tree -import PkgDependency.PkgTree - -# set environment variable PRINTTREE=on to visualize the project trees of the testsets -# TODO(SimeonEhrig): add type ::Bool , when minimum version is Julia 1.9 -printTree = haskey(ENV, "PRINTTREE") - -@testset "direct dependency to main" begin - project_tree = [PkgTree("MyMainProject.jl 1.0.0", [PkgTree("MyDep1.jl 1.0.0", [])])] - - if printTree - display( - PkgDependency.Tree( - PkgTree("Direct dependency to main tree", project_tree); - printkeys=false, - print_node_function=PkgDependency.writenode, - ), - ) - end - - # dependency exist and prefix is correct - @test integTestGen.depending_projects( - "MyDep1.jl", ["MyMainProject.jl"], project_tree - ) == ["MyMainProject.jl"] - # dependency does not exist and prefix is correct - @test isempty( - integTestGen.depending_projects("MyDep2.jl", ["MyMainProject.jl"], project_tree) - ) - # dependency exist and prefix is incorrect - @test isempty( - integTestGen.depending_projects("MyDep1.jl", ["ExternProject.jl"], project_tree) - ) - # dependency does not exist and prefix is incorrect - @test isempty( - integTestGen.depending_projects("MyDep2.jl", ["ExternProject.jl"], project_tree) - ) -end - -@testset "complex dependencies" begin - #! format: off - project_tree = [ - PkgTree("MyMainProject.jl 1.0.0", [ - PkgTree("MyDep1.jl 1.0.0", []), - PkgTree("MyDep2.jl 1.0.0", [ - PkgTree("MyDep3.jl 1.0.0", []), - PkgTree("ForeignDep1.jl 1.0.0", []) - ]), - PkgTree("ForeignDep2.jl 1.0.0", [ - PkgTree("ForeignDep3.jl 1.0.0", []), - PkgTree("ForeignDep4.jl 1.0.0", []) - ]), - PkgTree("MyDep4.jl 1.0.0", [ - PkgTree("MyDep5.jl 1.0.0", [ - PkgTree("MyDep3.jl 1.0.0", []) - ]) - ]), - PkgTree("ForeignDep2.jl 1.0.0", [ - PkgTree("MyDep5.jl 1.0.0", [ - PkgTree("MyDep3.jl 1.0.0", []) - ]), - PkgTree("MyDep3.jl 1.0.0", []), - PkgTree("MyDep6.jl 1.0.0", [ - PkgTree("MyDep3.jl 1.0.0", []) - ]) - ]), - PkgTree("MyDep7.jl 1.0.0", [ - PkgTree("MyDep5.jl 1.0.0", [ - PkgTree("MyDep3.jl 1.0.0", []) - ]), - PkgTree("MyDep3.jl 1.0.0", []) - ]) - ]) - ] - #! format: on - if printTree - display( - PkgDependency.Tree( - PkgTree("Complex dependency tree", project_tree); - printkeys=false, - print_node_function=PkgDependency.writenode, - ), - ) - end - - package_filter = [ - "MyMainProject.jl", - "MyDep1.jl", - "MyDep2.jl", - "MyDep3.jl", - "MyDep4.jl", - "MyDep5.jl", - "MyDep6.jl", - "MyDep7.jl", - ] - - # sort all vectors to guaranty the same order -> guaranty is not important for the actual result, onyl for comparison - @test sort( - integTestGen.depending_projects("MyDep1.jl", package_filter, project_tree) - ) == sort(["MyMainProject.jl"]) - @test sort( - integTestGen.depending_projects("MyDep2.jl", package_filter, project_tree) - ) == sort(["MyMainProject.jl"]) - # MyDep5.jl should only appears one time -> MyDep4.jl and MyDep7.jl has the same MyDep5.jl dependency - @test sort( - integTestGen.depending_projects("MyDep3.jl", package_filter, project_tree) - ) == sort(["MyDep2.jl", "MyDep5.jl", "MyDep7.jl"]) - @test sort( - integTestGen.depending_projects("MyDep5.jl", package_filter, project_tree) - ) == sort(["MyDep4.jl", "MyDep7.jl"]) - # cannot find MyDep6.jl, because it is only a dependency of a foreign package - @test isempty( - integTestGen.depending_projects("MyDep6.jl", package_filter, project_tree) - ) - @test isempty(integTestGen.depending_projects("MyDep3.jl", ["Foo"], project_tree)) -end - -@testset "circular dependency" begin - # I cannot create a real circular dependency with this data structur, but if Circulation appears in an output, we passed MyDep1.jl and MyDep2.jl two times, which means it is a circle - - #! format: off - project_tree = [ - PkgTree("MyMainProject.jl 1.0.0", [ - PkgTree("MyDep1.jl 1.0.0", [ - PkgTree("MyDep2.jl 1.0.0", [ - PkgTree("MyDep1.jl 1.0.0", [ - PkgTree("MyDep2.jl 1.0.0", [ - PkgTree("Circulation", []) - ]) - ]) - ]) - ]) - ]) - ] - #! format: on - - if printTree - display( - PkgDependency.Tree( - PkgTree("Circular dependency tree", project_tree); - printkeys=false, - print_node_function=PkgDependency.writenode, - ), - ) - end - - package_filter = ["MyMainProject.jl", "MyDep1.jl", "MyDep2.jl"] - - @test sort( - integTestGen.depending_projects("MyDep1.jl", package_filter, project_tree) - ) == sort(["MyMainProject.jl", "MyDep2.jl"]) - @test sort( - integTestGen.depending_projects("MyDep2.jl", package_filter, project_tree) - ) == sort(["MyDep1.jl"]) - @test isempty(integTestGen.depending_projects("MyDep2.jl", ["Foo"], project_tree)) - @test isempty( - integTestGen.depending_projects("Circulation", package_filter, project_tree) - ) -end diff --git a/.ci/integTestGen/test/runtests.jl b/.ci/integTestGen/test/runtests.jl index db14431..deee341 100644 --- a/.ci/integTestGen/test/runtests.jl +++ b/.ci/integTestGen/test/runtests.jl @@ -1,6 +1,5 @@ using integTestGen using Test -include("./integTestGen.jl") include("./get_target_branch.jl") include("./generate_job_yaml.jl")