Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ If you want to disable tag prefixes for subdirectory packages altogether, you ca
`tag_prefix` to `NO_PREFIX`. Note that this is only recommended if you only have a single
Julia package in the repository.

If the repository root is itself a package, subpackage releases are not marked as the repository's latest release, so that badge stays with the top-level package.

**:information_source: Monorepo-specific changelog behavior**

Each subpackage will include all issues and pull requests in its changelogs, such that a single issue will be duplicated up in all of the repository's subpackages' release notes. Careful [`changelog_ignore` and/or custom changelog settings](#changelogs) on a per-subpackage basis can mitigate this duplication.
Expand Down
20 changes: 20 additions & 0 deletions tagbot/action/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,22 @@ def _project(self, k: str) -> str:
raise InvalidProject(f"Failed to parse Project.toml (encoding error): {e}")
return str(self.__project[k])

def _root_is_package(self, sha: str) -> bool:
"""Determine whether the repository root holds a package at a commit."""
names = self._git.command(
"ls-tree", "--name-only", sha, "--", "Project.toml", "JuliaProject.toml"
).splitlines()
# Julia prefers JuliaProject.toml over Project.toml.
for name in ["JuliaProject.toml", "Project.toml"]:
if name in names:
try:
project = toml.loads(self._git.command("show", f"{sha}:{name}"))
except toml.TomlDecodeError:
return False
# A project without a name and UUID is an environment, not a package.
return "name" in project and "uuid" in project
return False

@property
def _registry_clone_dir(self) -> str:
if self.__registry_clone_dir is not None:
Expand Down Expand Up @@ -1644,6 +1660,10 @@ def create_release(self, version: str, sha: str, is_latest: bool = True) -> None
# https://github.com/JuliaRegistries/TagBot/issues/239#issuecomment-2246021651
self._git.create_tag(version_tag, sha, log)
logger.info(f"Creating GitHub release {version_tag} at {sha}")
if is_latest and self.__subdir and self._root_is_package(sha):
# The top-level package owns the repository's "Latest" release.
logger.info(f"Not marking {version_tag} as latest: the root is a package")
is_latest = False
# Use make_latest=False for backfilled old releases to avoid marking them
# as the "Latest" release on GitHub
make_latest_str = "true" if is_latest else "false"
Expand Down
31 changes: 31 additions & 0 deletions test/action/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ def test_create_release_subdir():
r._repo.create_git_tag.return_value.sha = "t"
r._repo.get_releases = Mock(return_value=[])
r._changelog.get = Mock(return_value="l")
r._root_is_package = Mock(return_value=False)
r.create_release("v1", "a")
r._git.create_tag.assert_called_with("Foo-v1", "a", "l")
r._repo.create_git_release.assert_called_with(
Expand Down Expand Up @@ -1429,6 +1430,36 @@ def test_create_release_subdir():
make_latest="true",
generate_release_notes=False,
)
# A top-level package keeps the "Latest" release for itself.
r._draft = False
r._root_is_package.return_value = True
r.create_release("v2", "e")
assert r._repo.create_git_release.call_args.kwargs["make_latest"] == "false"
r._root_is_package.assert_called_with("e")


def test_root_is_package():
r = _repo()
files = {}

def command(*args):
if args[0] == "ls-tree":
assert args[2] == "a"
return "\n".join(files)
sha, name = args[1].split(":")
assert sha == "a"
return files[name]

r._git.command = Mock(side_effect=command)
assert not r._root_is_package("a")
files["Project.toml"] = '[deps]\nFoo = "abc"\n'
assert not r._root_is_package("a")
files["Project.toml"] = 'name = "Bar"\nuuid = "abc"\n'
assert r._root_is_package("a")
files["JuliaProject.toml"] = "[deps]\n"
assert not r._root_is_package("a")
files["JuliaProject.toml"] = "not toml"
assert not r._root_is_package("a")


@patch("tagbot.action.repo.logger")
Expand Down
Loading