Skip to content

Commit

Permalink
Fix CI bot detection based on the Julia-CI-Variables header (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
bauglir authored May 28, 2024
1 parent eefe6b5 commit 61bd2dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PkgServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function handle_request(http::HTTP.Stream)
# out which registry flavor they actually want, and if none is given,
# give them `conservative` by default, unless they are self-reporting
# as a CI bot, in which case we'll always point them to `eager`.
ci = any([v == "t" for (k, v) in filter(!isempty, split(HTTP.header(http, "Julia-CI-Variables", ""), ";"))])
ci = any(x -> occursin(r"=t$", x), split(HTTP.header(http, "Julia-CI-Variables", ""), ";"))
flavor = HTTP.header(http, "Julia-Registry-Preference", ci ? "eager" : "conservative")
serve_redirect(http, "/registries.$(flavor)")
return
Expand Down
7 changes: 7 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ end
response = HTTP.get("$(server_url)/registries"; redirect=false)
@test response.status == 302

# Hitting `/registries` while reporting as a CI service should default to
# serving the eager flavor and the conservative flavor otherwise
conservative_response = HTTP.get("$(server_url)/registries")
@test endswith(conservative_response.request.target, ".conservative")
eager_response = HTTP.get("$(server_url)/registries", ["Julia-CI-Variables" => "CI=t"])
@test endswith(eager_response.request.target, ".eager")

# Test asking for that registry directly, unpacking it and verifying the treehash
mktemp() do tarball_path, tarball_io
response = HTTP.get("$(server_url)/registry/$(registry_uuid)/$(registry_treehash)"; response_stream=tarball_io)
Expand Down

0 comments on commit 61bd2dd

Please sign in to comment.