Skip to content

Commit cb96d1b

Browse files
Merge #398
398: Use Pkg registries r=ericphanson a=SebastianM-C This implements the suggestion in #395 and it should also adress #396 By using the already stored registries the code is simplified and `clone_all_registries` is no longer needed. I have commented out the code and if that function is no longer needed, I will remove it. The new implementation relies on the user depot, defined as the first entry of the `DEPOT_PATH` by the [Pkg manual](https://pkgdocs.julialang.org/v1/glossary/). Due to how registries are stored in the depot, I had to move the test registries in a `registries` folder. This doesn't seem to affect other tests. I have tested this locally (in WSL) and I'm getting the following error ```julia Initialized empty Git repository in /tmp/jl_Ir9E2F/.git/ error: refname refs/heads/master not found fatal: Branch rename failed master branch: Error During Test at /mnt/c/Users/sebastian/.julia/dev/CompatHelper/test/utilities/git.jl:349 Got exception outside of a `@test` failed process: Process(`git branch -m main`, ProcessExited(128)) [128] Stacktrace: [1] pipeline_error @ ./process.jl:525 [inlined] [2] run(::Cmd; wait::Bool) @ Base ./process.jl:440 [3] run @ ./process.jl:438 [inlined] [4] (::var"#94#98"{String})() @ Main /mnt/c/Users/sebastian/.julia/dev/CompatHelper/test/utilities/git.jl:354 [5] cd(f::var"#94#98"{String}, dir::String) @ Base.Filesystem ./file.jl:106 [6] #93 @ /mnt/c/Users/sebastian/.julia/dev/CompatHelper/test/utilities/git.jl:352 [inlined] [7] mktempdir(fn::var"#93#97"{String}, parent::String; prefix::String) @ Base.Filesystem ./file.jl:729 [8] mktempdir(fn::Function, parent::String) (repeats 2 times) @ Base.Filesystem ./file.jl:727 [9] macro expansion @ /mnt/c/Users/sebastian/.julia/dev/CompatHelper/test/utilities/git.jl:351 [inlined] [10] macro expansion @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined] [11] macro expansion @ /mnt/c/Users/sebastian/.julia/dev/CompatHelper/test/utilities/git.jl:350 [inlined] [12] macro expansion @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined] [13] top-level scope @ /mnt/c/Users/sebastian/.julia/dev/CompatHelper/test/utilities/git.jl:333 [14] include(fname::String) @ Base.MainInclude ./client.jl:444 [15] macro expansion @ /mnt/c/Users/sebastian/.julia/dev/CompatHelper/test/runtests.jl:25 [inlined] [16] macro expansion @ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined] [17] top-level scope @ /mnt/c/Users/sebastian/.julia/dev/CompatHelper/test/runtests.jl:24 [18] include(fname::String) @ Base.MainInclude ./client.jl:444 [19] top-level scope @ none:6 [20] eval @ ./boot.jl:360 [inlined] [21] exec_options(opts::Base.JLOptions) @ Base ./client.jl:261 [22] _start() @ Base ./client.jl:485 ``` but I'm not sure if it's related to the changes in this PR. Let me kow what you think about this approach. cc `@DilumAluthge` Co-authored-by: Sebastian Micluța-Câmpeanu <[email protected]> Co-authored-by: Sebastian Micluța-Câmpeanu <[email protected]>
2 parents 3d2049f + 2d7f963 commit cb96d1b

File tree

13 files changed

+135
-25
lines changed

13 files changed

+135
-25
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CompatHelper"
22
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
33
authors = ["Dilum Aluthge", "Brown Center for Biomedical Informatics", "contributors"]
4-
version = "3.0.8"
4+
version = "3.1.0"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

docs/src/options.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ my_registries = [Pkg.RegistrySpec(name = "General",
2626
CompatHelper.main(; registries=my_registries)
2727
```
2828

29+
Using the above option will clone the registries, but if you want to use already existing registries,
30+
you can use the `use_existing_registries` option. This will use all the registries present in the user depot,
31+
defined as the first entry of the `DEPOT_PATH` by the [Pkg manual](https://pkgdocs.julialang.org/v1/glossary/).
32+
```julia
33+
CompatHelper.main(; use_existing_registries=true)
34+
```
35+
36+
If you want to use a different location, you can specify that using the `depot` keyword.
37+
Note that the directroy indicated by `depot` should contain a subdirectory named `registries` where the registries
38+
are stored in order to reproduce the structure of the Julia depot.
39+
40+
!!! info
41+
Using the above mentioned `use_existing_registries` can be used in conjunction with the [`add-julia-registry`](https://github.com/julia-actions/add-julia-registry) GitHub action to easily add custom private registries in GitHub Actions CI.
42+
2943
## Overriding the default branch
3044

3145
By default, CompatHelper will open pull requests against your repository's default branch. If you would like to override this behavior, set the `master_branch` keyword argument. For example:
@@ -61,6 +75,5 @@ When a compat Pull Request is created, you might want the user that generated th
6175
This will use the `GITHUB_ACTOR` or `GITLAB_USER_LOGIN` environment variables to determine which user to mention.
6276

6377
```julia
64-
CompatHElper.main(; cc_user=true)
78+
CompatHelper.main(; cc_user=true)
6579
```
66-

src/dependencies.jl

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,43 @@ function clone_all_registries(f::Function, registry_list::Vector{Pkg.RegistrySpe
7676
end
7777
end
7878

79+
function get_latest_version!(deps, registries)
80+
for registry in registries
81+
registry_toml_path = joinpath(registry, "Registry.toml")
82+
registry_toml = TOML.parsefile(registry_toml_path)
83+
packages = registry_toml["packages"]
84+
85+
for dep in deps
86+
uuid = string(dep.package.uuid)
87+
88+
if uuid in keys(packages)
89+
versions_toml_path = joinpath(
90+
registry, packages[uuid]["path"], "Versions.toml"
91+
)
92+
versions =
93+
VersionNumber.(collect(keys(TOML.parsefile(versions_toml_path))))
94+
95+
max_version = maximum(versions)
96+
dep.latest_version = _max(dep.latest_version, max_version)
97+
end
98+
end
99+
end
100+
end
101+
102+
function get_existing_registries!(
103+
deps::Set{DepInfo}, depot::String
104+
)
105+
registries = readdir(joinpath(depot, "registries"), join=true)
106+
get_latest_version!(deps, registries)
107+
108+
return deps
109+
end
110+
79111
function get_latest_version_from_registries!(
80112
deps::Set{DepInfo}, registry_list::Vector{Pkg.RegistrySpec}
81113
)
82114
@mock clone_all_registries(registry_list) do registry_temp_dirs
83-
for registry in registry_temp_dirs
84-
registry_toml_path = joinpath(registry, "Registry.toml")
85-
registry_toml = TOML.parsefile(joinpath(registry_toml_path))
86-
packages = registry_toml["packages"]
87-
88-
for dep in deps
89-
uuid = string(dep.package.uuid)
90-
91-
if uuid in keys(packages)
92-
versions_toml_path = joinpath(
93-
registry, packages[uuid]["path"], "Versions.toml"
94-
)
95-
versions =
96-
VersionNumber.(collect(keys(TOML.parsefile(versions_toml_path))))
97-
98-
max_version = maximum(versions)
99-
dep.latest_version = _max(dep.latest_version, max_version)
100-
end
101-
end
102-
end
115+
get_latest_version!(deps, registry_temp_dirs)
103116
end
104117

105118
return deps

src/main.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const DEFAULT_REGISTRIES = Pkg.RegistrySpec[Pkg.RegistrySpec(;
1010
ci_cfg::CIService=auto_detect_ci_service(; env=env);
1111
entry_type::EntryType=KeepEntry(),
1212
registries::Vector{Pkg.RegistrySpec}=DEFAULT_REGISTRIES,
13+
use_existing_registries::Bool=false,
14+
depot::String=DEPOT_PATH[1],
1315
subdirs::AbstractVector{<:AbstractString}=[""],
1416
master_branch::Union{DefaultBranch,AbstractString}=DefaultBranch(),
1517
bump_compat_containing_equality_specifier=true,
@@ -29,6 +31,8 @@ Main entry point for the package.
2931
# Keywords
3032
- `entry_type::EntryType=KeepEntry()`: How to handle bumps for entry types
3133
- `registries::Vector{Pkg.RegistrySpec}=DEFAULT_REGISTRIES`: RegistrySpec of all registries to use
34+
- `use_existing_registries::Bool=false`: Specify whether to use the registries available at the `depot` location
35+
- `depot::String=DEPOT_PATH[1]`: The user depot path to use
3236
- `subdirs::AbstractVector{<:AbstractString}=[""]`: Subdirectories for nested packages
3337
- `master_branch::Union{DefaultBranch,AbstractString}=DefaultBranch()`: Name of the master branch
3438
- `bump_compat_containing_equality_specifier=true`: Bump compat entries with equality specifiers
@@ -43,6 +47,8 @@ function main(
4347
ci_cfg::CIService=auto_detect_ci_service(; env=env);
4448
entry_type::EntryType=KeepEntry(),
4549
registries::Vector{Pkg.RegistrySpec}=DEFAULT_REGISTRIES,
50+
use_existing_registries::Bool=false,
51+
depot::String=DEPOT_PATH[1],
4652
subdirs::AbstractVector{<:AbstractString}=[""],
4753
master_branch::Union{DefaultBranch,AbstractString}=DefaultBranch(),
4854
bump_compat_containing_equality_specifier=true,
@@ -65,7 +71,12 @@ function main(
6571
include_jll=include_jll,
6672
master_branch=master_branch,
6773
)
68-
get_latest_version_from_registries!(deps, registries)
74+
75+
if use_existing_registries
76+
get_existing_registries!(deps, depot)
77+
else
78+
get_latest_version_from_registries!(deps, registries)
79+
end
6980

7081
for dep in deps
7182
pr = @mock make_pr_for_new_version(

test/dependencies.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ end
6161
CompatHelper.Package(packageC, UUID(2)); latest_version=VersionNumber("3")
6262
),
6363
])
64+
6465
apply([clone_all_registries_patch, rm_patch]) do
6566
result = CompatHelper.get_latest_version_from_registries!(
6667
deps, Vector{Pkg.RegistrySpec}()
@@ -79,3 +80,40 @@ end
7980
end
8081
end
8182
end
83+
84+
@testset "get_existing_registries!" begin
85+
packageA = "PackageA"
86+
packageB = "PackageB"
87+
packageC = "PackageC"
88+
89+
deps = Set{CompatHelper.DepInfo}([
90+
# No version specified
91+
CompatHelper.DepInfo(CompatHelper.Package(packageA, UUID(0))),
92+
93+
# Version is less than what is in registry
94+
CompatHelper.DepInfo(
95+
CompatHelper.Package(packageB, UUID(1)); latest_version=VersionNumber(1)
96+
),
97+
98+
# Version is greater than what is in registry
99+
CompatHelper.DepInfo(
100+
CompatHelper.Package(packageC, UUID(2)); latest_version=VersionNumber("3")
101+
),
102+
])
103+
104+
result = CompatHelper.get_existing_registries!(
105+
deps, joinpath(@__DIR__, "deps")
106+
)
107+
108+
@test length(result) == 3
109+
110+
for res in result
111+
if res.package.name == packageA
112+
@test res.latest_version == VersionNumber("1")
113+
elseif res.package.name == packageB
114+
@test res.latest_version == VersionNumber("2")
115+
elseif res.package.name == packageC
116+
@test res.latest_version == VersionNumber("3")
117+
end
118+
end
119+
end

0 commit comments

Comments
 (0)