Skip to content

Commit

Permalink
Overwrite inventory version in deploydocs
Browse files Browse the repository at this point in the history
This unconditionally overwrites an existing inventory `version` with the
version determined by `deploydocs`. This only happens when `deploydocs`
actually knows the version. For `dev`-deployments, an existing `version`
is left unchanged.

Under normal circumstances, the existing `version` will already be the
correct one, so this should do nothing. If the `deploydocs` actually has
to *change* the version, that would indicate that something is set up
incorrectly, and thus a warning will be printed.
  • Loading branch information
goerz committed Feb 12, 2024
1 parent 1430232 commit bf40a7c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
22 changes: 21 additions & 1 deletion src/deploydocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ function deploydocs(;
inventory_version = _get_inventory_version(objects_inv)
deploy_version = _get_deploy_version(deploy_subfolder)
if !isempty(deploy_version) && (inventory_version != deploy_version)
error("Inventory declares version `$inventory_version`, but `deploydocs` is for version `$deploy_version`")
if !isempty(inventory_version)
@warn "Inventory declares version `$inventory_version`, but `deploydocs` is for version `$deploy_version`. Overwriting inventory version."
end
_patch_inventory_version(objects_inv, deploy_version)
end
end
@debug "pushing new documentation to remote: '$deploy_repo:$deploy_branch'."
Expand Down Expand Up @@ -303,6 +306,23 @@ function _get_inventory_version(objects_inv)
end


function _patch_inventory_version(objects_inv, version)
objects_inv_patched = tempname()
open(objects_inv) do input
open(objects_inv_patched, "w") do output
for line in eachline(input; keep=true)
if startswith(line, "# Version:")
@debug "Patched $objects_inv with version=$version"
line = "# Version: $version\n"
end
write(output, line)
end
end
end
mv(objects_inv_patched, objects_inv; force=true)
end


function _get_deploy_version(foldername)
try
return string(VersionNumber(foldername)) # strips the leading "v" from foldername
Expand Down
3 changes: 2 additions & 1 deletion src/html/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ The [format of the `objects.inv` file](https://juliadocs.org/DocInventories.jl/s
is borrowed from the [Sphinx project](https://www.sphinx-doc.org/en/master/). It consists
of a plain text header that includes the project name, taken from the `sitename` argument
to [`Documenter.makedocs`](@ref), and a project `version` obtained from the closest
`Project.toml` or `VERSION` file.
`Project.toml`, `JuliaProject.toml`, or `VERSION` file that defines a `version`,
respectively from the deployment tag in [`Documenter.deploydocs`](@ref).
The bulk of the file is a list of plain text records, compressed with gzip. See
[Inventory Generation](http://juliadocs.org/DocumenterInterLinks.jl/stable/write_inventory/)
Expand Down
21 changes: 3 additions & 18 deletions test/deploydocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,16 @@ Documenter.authenticated_repo_url(c::TestDeployConfig) = c.repo_path
devbranch = "master",
)
# Deploy 1.0.0 tag
@test_throws ErrorException("Inventory declares version ``, but `deploydocs` is for version `1.0.0`") begin
deploydocs(
root = pwd(),
deploy_config = TestDeployConfig(full_repo_path, "1.0.0"),
repo = full_repo_path,
devbranch = "master",
)
end
DocInventories.save(objects_inv, Inventory(project="test", version="1.0.0"))
@quietly deploydocs(
root = pwd(),
deploy_config = TestDeployConfig(full_repo_path, "1.0.0"),
repo = full_repo_path,
devbranch = "master",
)
# Deploy 1.1.0 tag
@test_throws ErrorException("Inventory declares version `1.0.0`, but `deploydocs` is for version `1.1.0`") begin
deploydocs(
root = pwd(),
deploy_config = TestDeployConfig(full_repo_path, "1.1.0"),
repo = full_repo_path,
devbranch = "master",
)
end
DocInventories.save(objects_inv, Inventory(project="test", version="1.1.0"))
# (note that the inventory still declares 1.0.0 as the version, so
# this implicitly tests that `deploydocs` overwrites it with the
# correct version)
@quietly deploydocs(
root = pwd(),
deploy_config = TestDeployConfig(full_repo_path, "1.1.0"),
Expand Down

0 comments on commit bf40a7c

Please sign in to comment.