From fcafde1b68caaf9ff39c4a2dbbf148562314e6ce Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Mon, 13 Mar 2023 12:20:47 +0100 Subject: [PATCH] Use eager Pkg server registry instead of git cloning (#31) * Use eager Pkg server registry instead of git cloning This patch removes the git cloning of General and instead uses the eager registry flavor. In addition, the action exits early if no deps/build.jl file exist. * Use env: key instead. --- action.yml | 20 +++------ add_general_registry.buildpkg.jl | 73 -------------------------------- 2 files changed, 7 insertions(+), 86 deletions(-) delete mode 100644 add_general_registry.buildpkg.jl diff --git a/action.yml b/action.yml index b3aab38..008c40b 100644 --- a/action.yml +++ b/action.yml @@ -17,18 +17,12 @@ inputs: runs: using: 'composite' steps: - # Occasionally, there are rather large delays (> a few hours) - # between the time a package is registered in General and - # propagated to pkg.julialang.org. We can avoid this by manually - # cloning ~/.julia/registries/General/ in Julia 1.5 and later. - # See: - # * 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 "$GITHUB_ACTION_PATH"/add_general_registry.buildpkg.jl - shell: bash - - - run: julia --color=yes --project=${{ inputs.project }} -e 'using Pkg; if VERSION >= v"1.1.0-rc1"; Pkg.build(verbose=true); else Pkg.build(); end' - shell: bash + - run: | + isfile("deps/build.jl") || exit() + import Pkg + VERSION >= v"1.5-" && Pkg.Registry.add("General") + VERSION >= v"1.1.0-rc1" ? Pkg.build(verbose=true) : Pkg.build() + shell: julia --color=yes --project=${{ inputs.project }} {0} env: + JULIA_PKG_SERVER_REGISTRY_PREFERENCE: "${{ env.JULIA_PKG_SERVER_REGISTRY_PREFERENCE == '' && 'eager' || env.JULIA_PKG_SERVER_REGISTRY_PREFERENCE }}" JULIA_PKG_PRECOMPILE_AUTO: "${{ inputs.precompile }}" diff --git a/add_general_registry.buildpkg.jl b/add_general_registry.buildpkg.jl deleted file mode 100644 index 40446ca..0000000 --- a/add_general_registry.buildpkg.jl +++ /dev/null @@ -1,73 +0,0 @@ -using Pkg - -function tarball_general_registry_location() - reg_dir = joinpath(DEPOT_PATH[1], "registries") - general_registry_tarball = joinpath(reg_dir, "General.tar.gz") - registry_toml_file = joinpath(reg_dir, "General.toml") - return general_registry_tarball, registry_toml_file -end - -function cloned_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_tarball, registry_toml_file = tarball_general_registry_location() - if isfile(general_registry_tarball) && isfile(registry_toml_file) - return true - end - - general_registry_dir, registry_toml_file = cloned_general_registry_location() - if isdir(general_registry_dir) && isfile(registry_toml_file) - return true - end - - return false -end - -function add_general_registry() - @info("Attempting to install the General registry") - - general_registry_tarball, registry_toml_file = tarball_general_registry_location() - rm(general_registry_tarball; force = true, recursive = true) - rm(registry_toml_file; force = true, recursive = true) - - general_registry_dir, registry_toml_file = cloned_general_registry_location() - rm(general_registry_dir; force = true, recursive = true) - - # If not already set, We set `JULIA_PKG_SERVER` to enforce - # `Pkg.Registry.add` to use Git. This way, Pkg.jl can send - # the request metadata to pkg.julialang.org when installing - # packages via `Pkg.test`. - pkg_server = get(ENV, "JULIA_PKG_SERVER", "") - withenv("JULIA_PKG_SERVER" => pkg_server) do - Pkg.Registry.add("General") - end - - general_registry_exists() || throw(ErrorException("The Registry was not intalled properly")) - 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 added the General registry") - catch ex - msg = "I was unable to add the General registry. However, the build will continue." - @error(msg, exception=(ex,catch_backtrace())) - end - - return -end - -main()