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

Obtain inventory version from Project.toml #2442

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions src/deploydocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@
@debug "running extra build steps."
make()
end
objects_inv = joinpath(realpath(target), "objects.inv")
if isfile(objects_inv)
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`")
end
end
Comment on lines +271 to +278
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mortenpi This is the bit of code in deploydocs that would guarantee that there is never a mismatch between the automatic version extracted from the Project.toml and what is shown in the versions-selection menu for tagged releases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think the error is too harsh or might be considered semver-breaking, I'd also be okay making it an @error, and potentially even overwriting the inventory_version with the deploy_version. That would be extremely close to #2448, but the "fallback" would happen in makedocs instead of deploydocs, which I'd much prefer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2449, which might be starting to become my preferred solution (since I actually agree with you that for a tagged release, the version that comes out of deploydocs is kinda authoritative).

@debug "pushing new documentation to remote: '$deploy_repo:$deploy_branch'."
mktempdir() do temp
git_push(
Expand All @@ -282,6 +290,28 @@
end
end


function _get_inventory_version(objects_inv)
open(objects_inv) do input
for line in eachline(input)
if startswith(line, "# Version:")
return strip(line[11:end])
end
end
error("Invalid $objects_inv: missing or invalid version line")

Check warning on line 301 in src/deploydocs.jl

View check run for this annotation

Codecov / codecov/patch

src/deploydocs.jl#L301

Added line #L301 was not covered by tests
end
end


function _get_deploy_version(foldername)
try
return string(VersionNumber(foldername)) # strips the leading "v" from foldername
catch
return ""
end
end


"""
git_push(
root, tmp, repo;
Expand Down
38 changes: 35 additions & 3 deletions test/deploydocs.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Documenter: Documenter, deploydocs, git
using DocInventories: DocInventories, Inventory
using Test
include("TestUtilities.jl"); using Main.TestUtilities

Expand All @@ -21,6 +22,9 @@ Documenter.authenticated_repo_url(c::TestDeployConfig) = c.repo_path
# Pseudo makedocs products in build/
mkdir("build")
write("build/page.html", "...")
inventory = Inventory(project="test", version="")
objects_inv = joinpath("build", "objects.inv")
DocInventories.save(objects_inv, inventory)
# Create gh-pages and deploy dev/
@quietly deploydocs(
root = pwd(),
Expand All @@ -29,20 +33,39 @@ 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"))
@quietly deploydocs(
root = pwd(),
deploy_config = TestDeployConfig(full_repo_path, "1.1.0"),
repo = full_repo_path,
devbranch = "master",
)
# Deploy 2.0.0 tag, but into an archive (so nothing pushed to gh-pages)
DocInventories.save(objects_inv, Inventory(project="test", version="2.0.0"))
@quietly deploydocs(
root = pwd(),
deploy_config = TestDeployConfig(full_repo_path, "2.0.0"),
Expand All @@ -51,6 +74,7 @@ Documenter.authenticated_repo_url(c::TestDeployConfig) = c.repo_path
archive = joinpath(pwd(), "ghpages.tar.gz"),
)
# Deploy 3.0.0 tag with a tag_prefix---which does not change deployment behavior
DocInventories.save(objects_inv, Inventory(project="test", version="3.0.0"))
@quietly deploydocs(;
root = pwd(),
deploy_config = TestDeployConfig(full_repo_path, "3.0"),
Expand Down Expand Up @@ -78,10 +102,18 @@ Documenter.authenticated_repo_url(c::TestDeployConfig) = c.repo_path
@test islink(joinpath("worktree", "v3"))
@test islink(joinpath("worktree", "v3.0"))
@test islink(joinpath("worktree", "v3.0.0"))

inv_v11 = Inventory(joinpath("worktree", "v1.1", "objects.inv"))
@test inv_v11.version == "1.1.0"
inv_v30 = Inventory(joinpath("worktree", "v3.0", "objects.inv"))
@test inv_v30.version == "3.0.0"
inv_stable = Inventory(joinpath("worktree", "stable", "objects.inv"))
@test inv_stable.version == "3.0.0"
inv_dev = Inventory(joinpath("worktree", "dev", "objects.inv"))
@test inv_dev.version == ""

# key_prefix does not affect/is not present in worktree directories
@test issetequal([".git", "1.0.0", "1.1.0", "3.0", "dev", "index.html",
"stable", "v1", "v1.0", "v1.0.0", "v1.1", "v1.1.0",
@test issetequal([".git", "1.0.0", "1.1.0", "3.0", "dev", "index.html",
"stable", "v1", "v1.0", "v1.0.0", "v1.1", "v1.1.0",
"v3", "v3.0", "v3.0.0", "versions.js"], readdir("worktree"))
end
end
Expand Down
Loading