diff --git a/action.yml b/action.yml index 00b6e9f..4d3e9b5 100644 --- a/action.yml +++ b/action.yml @@ -35,7 +35,7 @@ runs: # * https://github.com/JuliaLang/Pkg.jl/issues/2011 # * https://github.com/JuliaRegistries/General/issues/16777 # * https://github.com/JuliaPackaging/PkgServer.jl/issues/60 - - run: julia --color=yes -e 'using Pkg; VERSION >= v"1.5-" && !isdir(joinpath(DEPOT_PATH[1], "registries", "General")) && Pkg.Registry.add("General")' + - run: julia --color=yes "$GITHUB_ACTION_PATH"/add_general_registry.jl shell: bash env: # We set `JULIA_PKG_SERVER` only for this step to enforce diff --git a/add_general_registry.jl b/add_general_registry.jl new file mode 100644 index 0000000..4da8bf1 --- /dev/null +++ b/add_general_registry.jl @@ -0,0 +1,49 @@ +using Pkg + +function general_registry_location() + general_registry_dir = joinpath(DEPOT_PATH[1], "registries", "General") + registry_toml_file = joinpath(general_registry_dir, "Registry.toml") + return general_registry_dir, registry_toml_file +end + +function general_registry_exists() + general_registry_dir, registry_toml_file = general_registry_location() + if !isdir(general_registry_dir) + return false + elseif !isfile(registry_toml_file) + return false + else + return true + end +end + +function add_general_registry() + @info("Attempting to clone the General registry") + general_registry_dir, registry_toml_file = general_registry_location() + rm(general_registry_dir; force = true, recursive = true) + Pkg.Registry.add("General") + isfile(registry_toml_file) || throw(ErrorException("the Registry.toml file does not exist")) + return nothing +end + +function main(; n = 10, max_delay = 120) + VERSION >= v"1.5-" || return + + if general_registry_exists() + @info("The General registry already exists locally") + return + end + + delays = ExponentialBackOff(; n = n, max_delay = max_delay) + try + retry(add_general_registry; delays = delays)() + @info("Successfully add the General registry") + catch ex + msg = "I was unable to added the General registry. However, the build will continue." + @error(msg, exception=(ex,catch_backtrace())) + end + + return +end + +main()