Skip to content

Commit

Permalink
get reference updater github token automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel committed Mar 18, 2024
1 parent 88ffa6e commit d06140d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions ReferenceUpdater/src/ReferenceUpdater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion ReferenceUpdater/src/image_download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions ReferenceUpdater/src/local_server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d06140d

Please sign in to comment.