diff --git a/ReferenceUpdater/src/ReferenceUpdater.jl b/ReferenceUpdater/src/ReferenceUpdater.jl index 7ef6479dc2a..cdb9d003cf8 100644 --- a/ReferenceUpdater/src/ReferenceUpdater.jl +++ b/ReferenceUpdater/src/ReferenceUpdater.jl @@ -9,6 +9,16 @@ import ZipFile import REPL import TOML +function github_token() + get(ENV, "GITHUB_TOKEN") do + try + readchomp(`gh auth token`) + catch + error("""Could not find github authorization token, ENV["GITHUB_TOKEN"] is not defined and `gh auth token` failed as a fallback.""") + end + end +end + include("local_server.jl") include("image_download.jl") diff --git a/ReferenceUpdater/src/image_download.jl b/ReferenceUpdater/src/image_download.jl index 3dbe20d9365..063edf9860b 100644 --- a/ReferenceUpdater/src/image_download.jl +++ b/ReferenceUpdater/src/image_download.jl @@ -15,6 +15,6 @@ function upload_reference_images(path=basedir("recorded"), tag=last_major_versio mktempdir() do dir tarfile = joinpath(dir, "reference_images.tar") Tar.create(path, tarfile) - upload_release("MakieOrg", "Makie.jl", ENV["GITHUB_TOKEN"], tag, tarfile) + upload_release("MakieOrg", "Makie.jl", github_token(), tag, tarfile) end end diff --git a/ReferenceUpdater/src/local_server.jl b/ReferenceUpdater/src/local_server.jl index b76ba90eb2f..854ba474fad 100644 --- a/ReferenceUpdater/src/local_server.jl +++ b/ReferenceUpdater/src/local_server.jl @@ -77,7 +77,7 @@ function serve_update_page_from_dir(folder) end function serve_update_page(; commit = nothing, pr = nothing) - authget(url) = HTTP.get(url, Dict("Authorization" => "token $(ENV["GITHUB_TOKEN"])")) + authget(url) = HTTP.get(url, Dict("Authorization" => "token $(github_token())")) commit !== nothing && pr !== nothing && error("Keyword arguments `commit` and `pr` can't be set at once.") if pr !== nothing @@ -132,7 +132,7 @@ function serve_update_page(; commit = nothing, pr = nothing) download_url = a["archive_download_url"] if !haskey(URL_CACHE, download_url) @info "Downloading artifact from $download_url" - filepath = Downloads.download(download_url, headers = Dict("Authorization" => "token $(ENV["GITHUB_TOKEN"])")) + filepath = Downloads.download(download_url, headers = Dict("Authorization" => "token $(github_token())")) @info "Download successful" tmpdir = mktempdir() unzip(filepath, tmpdir)