Skip to content

Commit

Permalink
add commit hash information to registry
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Dec 31, 2023
1 parent 77e2a02 commit 0ceb204
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/register.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,25 @@ end
function update_versions_file(pkg::Project,
versions_file::AbstractString,
versions_data::Dict{String, Any},
tree_hash::AbstractString)
tree_hash::AbstractString;
commit_hash::Union{AbstractString,Nothing}=nothing,
tag_hash::Union{AbstractString,Nothing}=nothing,
tag_name::Union{AbstractString,Nothing}=nothing,
subdir::AbstractString="",
)
version_info = Dict{String, Any}("git-tree-sha1" => string(tree_hash))
if !isnothing(commit_hash)
version_info["git-commit-sha1"] = commit_hash
end
if !isnothing(tag_hash)
version_info["git-tag-sha1"] = tag_hash

Check warning on line 340 in src/register.jl

View check run for this annotation

Codecov / codecov/patch

src/register.jl#L340

Added line #L340 was not covered by tests
end
if !isnothing(tag_name)
version_info["git-tag-name"] = tag_name

Check warning on line 343 in src/register.jl

View check run for this annotation

Codecov / codecov/patch

src/register.jl#L343

Added line #L343 was not covered by tests
end
if subdir != ""
version_info["git-tree-path"] = subdir
end
versions_data[string(pkg.version)] = version_info

open(versions_file, "w") do io
Expand All @@ -341,10 +358,18 @@ function update_versions_file(pkg::Project,
else
if x == "git-tree-sha1"
return 1
elseif x == "yanked"
elseif x == "git-commit-sha1"
return 2
else
elseif x == "git-tag-sha1"
return 3
elseif x == "git-tag-name"
return 4

Check warning on line 366 in src/register.jl

View check run for this annotation

Codecov / codecov/patch

src/register.jl#L366

Added line #L366 was not covered by tests
elseif x == "git-tree-path"
return 5
elseif x == "yanked"
return 100
else
return 200
end
end
end
Expand Down Expand Up @@ -528,7 +553,8 @@ end

function check_and_update_registry_files(pkg::Project, package_repo, tree_hash,
registry_path, registry_deps_paths,
status; subdir = "")
status;
commit_hash = nothing, tag_hash = nothing, tag_name = nothing, subdir = "")
# find package in registry
@debug("find package in registry")
registry_file = joinpath(registry_path, "Registry.toml")
Expand All @@ -548,7 +574,7 @@ function check_and_update_registry_files(pkg::Project, package_repo, tree_hash,
versions_file, versions_data = get_versions_file(package_path)
old_versions = check_versions!(pkg, versions_data, status)
haserror(status) && return
update_versions_file(pkg, versions_file, versions_data, tree_hash)
update_versions_file(pkg, versions_file, versions_data, tree_hash; commit_hash, tag_hash, tag_name, subdir)

# update package data: deps file
@debug("update package data: deps file")
Expand Down Expand Up @@ -586,7 +612,10 @@ errors or warnings that occurred.
* `registry_fork::AbstractString=registry: the git repository URL for a fork of the registry
* `registry_deps::Vector{String}=[]`: the git repository URLs for any registries containing
packages depended on by `pkg`
* `subdir::AbstractString=""`: path to package within `package_repo`
* `commit_hash::Union{AbstractString, Nothing}`: commit hash of the package revision (optional)
* `tag_hash::Union{AbstractString, Nothing}`: tag hash of the package revision (optional)
* `tag_name::Union{AbstractString, Nothing}`: tag name of the package revision (optional)
* `subdir::AbstractString=""`: path to package tree within `package_repo`
* `push::Bool=false`: whether to push a registration branch to `registry` for consideration
* `gitconfig::Dict=Dict()`: dictionary of configuration options for the `git` command
"""
Expand All @@ -595,6 +624,9 @@ function register(
registry::AbstractString = DEFAULT_REGISTRY_URL,
registry_fork::AbstractString = registry,
registry_deps::Vector{<:AbstractString} = AbstractString[],
commit_hash::Union{AbstractString,Nothing} = nothing,
tag_hash::Union{AbstractString,Nothing} = nothing,
tag_name::Union{AbstractString,Nothing} = nothing,
subdir::AbstractString = "",
checks_triggering_error = registrator_errors,
push::Bool = false,
Expand Down Expand Up @@ -643,7 +675,8 @@ function register(

check_and_update_registry_files(pkg, package_repo, tree_hash,
registry_path, registry_deps_paths,
status, subdir = subdir)
status;
commit_hash, tag_hash, tag_name, subdir)
haserror(status) && return set_metadata!(regbr, status)

regtreesha = get_registrator_tree_sha()
Expand Down
13 changes: 13 additions & 0 deletions test/regedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ end
@test collect(keys(data["1.0.0"])) == ["git-tree-sha1"]
@test data["1.0.0"]["git-tree-sha1"] == tree_hash

commit_hash = repeat("1", 40)
subdir = "sub/dir"
update_versions_file(pkg, filename, data, tree_hash; commit_hash, subdir)

_, data = get_versions_file(temp_dir)
@test data isa Dict
@test collect(keys(data)) == ["1.0.0"]
@test data["1.0.0"] isa Dict
@test sort!(collect(keys(data["1.0.0"]))) == ["git-commit-sha1", "git-tree-path", "git-tree-sha1"]
@test data["1.0.0"]["git-tree-sha1"] == tree_hash
@test data["1.0.0"]["git-commit-sha1"] == commit_hash
@test data["1.0.0"]["git-tree-path"] == subdir

check_versions!(pkg, data, status)
# This version was just registered, should be a complaint now.
@test haserror(status)
Expand Down

0 comments on commit 0ceb204

Please sign in to comment.