Skip to content

Commit

Permalink
Put the General registry clone inside a bounded retry loop (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: Sascha Mann <git@mail.saschamann.eu>
  • Loading branch information
DilumAluthge and SaschaMann committed Jan 4, 2021
1 parent 78a53ba commit 8ff46c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions add_general_registry.jl
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 8ff46c6

Please sign in to comment.