Skip to content

Commit aefcf2d

Browse files
committed
add support for commit hash information
1 parent 10a0449 commit aefcf2d

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

src/AutoMerge/guidelines.jl

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,17 +619,22 @@ const guideline_src_names_OK = Guideline(;
619619
)
620620

621621
function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_path)
622-
uuid, package_repo, subdir, tree_hash_from_toml = parse_registry_pkg_info(
622+
uuid, package_repo, subdir, tree_hash_from_toml, commit_hash_from_toml, tag_hash_from_toml, tag_name_from_toml = parse_registry_pkg_info(
623623
registry_head, pkg, version
624624
)
625625

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

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

632-
local tree_hash_from_commit, tree_hash_from_commit_success
637+
local tree_hash_from_commit, tree_hash_from_commit_success, tag_success
633638
clone_success = load_files_from_url_and_tree_hash(
634639
pkg_code_path, package_repo, tree_hash_from_toml
635640
) do dir
@@ -639,6 +644,23 @@ function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_
639644
@error e
640645
"", false
641646
end
647+
648+
tag_success = try
649+
if !isnothing(tag_hash_from_toml)
650+
commit_hash_from_tag = readchomp(Cmd(`git rev-parse $(tag_hash_from_toml)^\{commit\}`; dir=dir))
651+
@assert commit_hash_from_tag == commit_hash_from_toml
652+
end
653+
if !isnothing(tag_name_from_toml)
654+
hash_from_tag_name = readchomp(Cmd(`git rev-parse $(tag_name_from_toml)`; dir=dir))
655+
# if an annotated tag, should point to the tag object
656+
# if a lightweight tag, should point to the commit object
657+
@assert hash_from_tag_name == something(tag_hash_from_toml, commit_hash_from_toml)
658+
end
659+
true
660+
catch e
661+
@error e
662+
false
663+
end
642664
end
643665

644666
if !clone_success
@@ -654,9 +676,13 @@ function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_
654676
@error "`tree_hash_from_commit != tree_hash_from_toml`" tree_hash_from_commit tree_hash_from_toml
655677
return false,
656678
"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."
657-
else
658-
return true, ""
659679
end
680+
681+
if !tag_success
682+
return false, "Tag information in .toml does not match information in repository"
683+
end
684+
685+
return true
660686
end
661687

662688
function _generate_pkg_add_command(pkg::String, version::VersionNumber)::String

src/AutoMerge/util.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,21 @@ function parse_registry_pkg_info(registry_path, pkg, version=nothing)
7575
subdir = convert(String, get(package, "subdir", ""))
7676
if version === nothing
7777
tree_hash = nothing
78+
commit_hash = nothing
79+
tag_hash = nothing
80+
tag_name = nothing
7881
else
7982
versions = TOML.parsefile(
8083
joinpath(registry_path, packages[uuid]["path"], "Versions.toml")
8184
)
82-
tree_hash = convert(String, versions[string(version)]["git-tree-sha1"])
85+
version_info = versions[string(version)]
86+
tree_hash = convert(String, version_info["git-tree-sha1"])
87+
commit_hash = get(version_info, "git-commit-sha1", nothing)
88+
tag_hash = get(version_info, "git-tag-sha1", nothing)
89+
tag_name = get(version_info, "git-tag-name", nothing)
90+
subdir = get(version_info, "subdir", subdir) # use version-specific subdir if it exists
8391
end
84-
return (; uuid=uuid, repo=repo, subdir=subdir, tree_hash=tree_hash)
92+
return (; uuid=uuid, repo=repo, subdir=subdir, tree_hash=tree_hash, commit_hash=commit_hash, tag_hash=tag_hash, tag_name=tag_name)
8593
end
8694

8795
function _comment_disclaimer(; point_to_slack::Bool=false)

src/registry_testing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function test(path=pwd(); registry_deps::Vector{<:AbstractString}=String[])
176176
# https://github.com/JuliaRegistries/RegistryCI.jl/issues/523
177177
# "yanked" is correct.
178178
# "yank" (and all other variants) are incorrect.
179-
Test.@test keys(data) ["git-tree-sha1", "yanked"]
179+
Test.@test keys(data) ["git-tree-sha1", "git-commit-sha1", "git-tag-sha1", "git-tag-name", "subdir", "yanked"]
180180
end
181181

182182
# Deps.toml testing

0 commit comments

Comments
 (0)