diff --git a/src/AutoMerge/guidelines.jl b/src/AutoMerge/guidelines.jl index eda343bb..4b22bef5 100644 --- a/src/AutoMerge/guidelines.jl +++ b/src/AutoMerge/guidelines.jl @@ -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( 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 @@ -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 @@ -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 diff --git a/src/AutoMerge/util.jl b/src/AutoMerge/util.jl index e887d168..e4aab6bc 100644 --- a/src/AutoMerge/util.jl +++ b/src/AutoMerge/util.jl @@ -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`. @@ -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) diff --git a/src/registry_testing.jl b/src/registry_testing.jl index e5b4c9a3..aad7d2b9 100644 --- a/src/registry_testing.jl +++ b/src/registry_testing.jl @@ -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 diff --git a/test/automerge-unit.jl b/test/automerge-unit.jl index 6d844e47..5edebdb0 100644 --- a/test/automerge-unit.jl +++ b/test/automerge-unit.jl @@ -54,6 +54,8 @@ 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 == (; @@ -61,6 +63,8 @@ end repo="https://github.com/JuliaRegistries/RegistryCI.jl.git", subdir="", tree_hash=nothing, + commit_hash=nothing, + tag_name=nothing ) result = AutoMerge.parse_registry_pkg_info( @@ -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