Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for commit hash information #537

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/AutoMerge/guidelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,17 +619,22 @@ const guideline_src_names_OK = Guideline(;
)

function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_path)
uuid, package_repo, subdir, tree_hash_from_toml = parse_registry_pkg_info(
uuid, package_repo, subdir, tree_hash_from_toml, commit_hash_from_toml, tag_name_from_toml = parse_registry_pkg_info(
simonbyrne marked this conversation as resolved.
Show resolved Hide resolved
registry_head, pkg, version
)

# We get the `tree_hash` two ways and check they agree, which helps ensures the `subdir` parameter is correct. Two ways:
# 1. By the commit hash in the PR body and the subdir parameter
# 1. By the commit hash and the subdir parameter
# 2. By the tree hash in the Versions.toml

commit_hash = commit_from_pull_request_body(pr)
if isnothing(commit_hash_from_toml)
# git-commit-sha1 is an optional registry key: if it isn't in the .toml, then we query the PR
commit_hash = commit_from_pull_request_body(pr)
else
commit_hash = commit_hash_from_toml
end

local tree_hash_from_commit, tree_hash_from_commit_success
local tree_hash_from_commit, tree_hash_from_commit_success, tag_success
clone_success = load_files_from_url_and_tree_hash(
pkg_code_path, package_repo, tree_hash_from_toml
) do dir
Expand All @@ -639,6 +644,18 @@ function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_
@error e
"", false
end

tag_success = try
if !isnothing(tag_name_from_toml)
# if an annotated tag, need to dereference to commit
commit_hash_from_tag = readchomp(Cmd(`git rev-parse $(tag_name_from_toml)^\{commit\}`; dir=dir))
@assert commit_hash_from_tag == commit_hash_from_toml
end
true
catch e
@error e
false
end
end

if !clone_success
Expand All @@ -654,9 +671,13 @@ function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_
@error "`tree_hash_from_commit != tree_hash_from_toml`" tree_hash_from_commit tree_hash_from_toml
return false,
"Tree hash obtained from the commit message and subdirectory does not match the tree hash in the Versions.toml file. Possibly this indicates that an incorrect `subdir` parameter was passed during registration."
else
return true, ""
end

if !tag_success
return false, "Tag information in .toml does not match information in repository"
end

return true
end

function _generate_pkg_add_command(pkg::String, version::VersionNumber)::String
Expand Down
26 changes: 23 additions & 3 deletions src/AutoMerge/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ function load_files_from_url_and_tree_hash(
end

"""
parse_registry_pkg_info(registry_path, pkg, version=nothing) -> @NamedTuple{uuid::String, repo::String, subdir::String, tree_hash::Union{Nothing, String}}
parse_registry_pkg_info(
registry_path::AbstractString,
pkg::AbstractString,
version=nothing
) :: @NamedTuple{
uuid::String,
repo::String,
subdir::String,
tree_hash::Union{Nothing, String},
commit_hash::Union{Nothing, String},
tag_name::Union{Nothing, String}
}

Searches the registry located at `registry_path` for a package with name `pkg`. Upon finding it,
it parses the associated `Package.toml` file and returns the UUID and repository URI, and `subdir`.
Expand All @@ -75,13 +86,22 @@ function parse_registry_pkg_info(registry_path, pkg, version=nothing)
subdir = convert(String, get(package, "subdir", ""))
if version === nothing
tree_hash = nothing
commit_hash = nothing
tag_name = nothing
else
versions = TOML.parsefile(
joinpath(registry_path, packages[uuid]["path"], "Versions.toml")
)
tree_hash = convert(String, versions[string(version)]["git-tree-sha1"])
version_info = versions[string(version)]
tree_hash = convert(String, version_info["git-tree-sha1"])
commit_hash = get(version_info, "git-commit-sha1", nothing)
tag_name = get(version_info, "git-tag-name", nothing)
if !isnothing(commit_hash)
# use version-specific subdir if commit_hash is defined.
subdir = get(version_info, "subdir", "")
end
end
return (; uuid=uuid, repo=repo, subdir=subdir, tree_hash=tree_hash)
return (; uuid=uuid, repo=repo, subdir=subdir, tree_hash=tree_hash, commit_hash=commit_hash, tag_name=tag_name)
end

function _comment_disclaimer(; point_to_slack::Bool=false)
Expand Down
2 changes: 1 addition & 1 deletion src/registry_testing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function test(path=pwd(); registry_deps::Vector{<:AbstractString}=String[])
# https://github.com/JuliaRegistries/RegistryCI.jl/issues/523
# "yanked" is correct.
# "yank" (and all other variants) are incorrect.
Test.@test keys(data) ⊆ ["git-tree-sha1", "yanked"]
Test.@test keys(data) ⊆ ["git-tree-sha1", "git-commit-sha1", "git-tag-name", "subdir", "yanked"]
end

# Deps.toml testing
Expand Down
6 changes: 6 additions & 0 deletions test/automerge-unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ end
repo="https://github.com/JuliaRegistries/RegistryCI.jl.git",
subdir="",
tree_hash="1036c9c4d600468785fbd9dae87587e59d2f66a9",
commit_hash=nothing,
tag_name=nothing
)
result = AutoMerge.parse_registry_pkg_info(registry_path, "RegistryCI")
@test result == (;
uuid="0c95cc5f-2f7e-43fe-82dd-79dbcba86b32",
repo="https://github.com/JuliaRegistries/RegistryCI.jl.git",
subdir="",
tree_hash=nothing,
commit_hash=nothing,
tag_name=nothing
)

result = AutoMerge.parse_registry_pkg_info(
Expand All @@ -71,6 +75,8 @@ end
repo="https://github.com/timholy/SnoopCompile.jl.git",
subdir="SnoopCompileCore",
tree_hash="bb6d6df44d9aa3494c997aebdee85b713b92c0de",
commit_hash=nothing,
tag_name=nothing
)
end
end
Expand Down
Loading