This commit is contained in:
2 files changed
+53
-3
No files matched your search
@@ -41,6 +41,28 @@ def command(*args: str, cwd: Path | None = None) -> str:
|
|||||||
) from error
|
) from error
|
||||||
|
|
||||||
|
|
||||||
|
def remote_tag_commit(tag_output: str, tag: str) -> str | None:
|
||||||
|
if not tag_output:
|
||||||
|
return None
|
||||||
|
|
||||||
|
direct_ref = f"refs/tags/{tag}"
|
||||||
|
peeled_ref = f"{direct_ref}^{{}}"
|
||||||
|
revisions: dict[str, str] = {}
|
||||||
|
for line in tag_output.splitlines():
|
||||||
|
fields = line.split()
|
||||||
|
if len(fields) != 2:
|
||||||
|
raise ReleaseError(f"invalid ls-remote output for tag {tag}")
|
||||||
|
revision, reference = fields
|
||||||
|
if reference in (direct_ref, peeled_ref):
|
||||||
|
revisions[reference] = revision
|
||||||
|
|
||||||
|
if peeled_ref in revisions:
|
||||||
|
return revisions[peeled_ref]
|
||||||
|
if direct_ref in revisions:
|
||||||
|
return revisions[direct_ref]
|
||||||
|
raise ReleaseError(f"ls-remote did not return the requested tag {tag}")
|
||||||
|
|
||||||
|
|
||||||
def root_product_version(cmake_text: str) -> str:
|
def root_product_version(cmake_text: str) -> str:
|
||||||
matches = PROJECT_RE.findall(cmake_text)
|
matches = PROJECT_RE.findall(cmake_text)
|
||||||
if len(matches) != 1:
|
if len(matches) != 1:
|
||||||
@@ -214,9 +236,16 @@ def resolve_component(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
expected_tag = f"v{version}"
|
expected_tag = f"v{version}"
|
||||||
tag_line = command("git", "ls-remote", "--tags", url, expected_tag)
|
tag_output = command(
|
||||||
if tag_line:
|
"git",
|
||||||
tag_revision = tag_line.split()[0]
|
"ls-remote",
|
||||||
|
"--tags",
|
||||||
|
url,
|
||||||
|
f"refs/tags/{expected_tag}",
|
||||||
|
f"refs/tags/{expected_tag}^{{}}",
|
||||||
|
)
|
||||||
|
tag_revision = remote_tag_commit(tag_output, expected_tag)
|
||||||
|
if tag_revision is not None:
|
||||||
if tag_revision != revision:
|
if tag_revision != revision:
|
||||||
raise ReleaseError(
|
raise ReleaseError(
|
||||||
f"{component_id} tag {expected_tag} points at "
|
f"{component_id} tag {expected_tag} points at "
|
||||||
|
|||||||
@@ -15,6 +15,27 @@ SPEC.loader.exec_module(MODULE)
|
|||||||
|
|
||||||
|
|
||||||
class PrepareReleaseTests(unittest.TestCase):
|
class PrepareReleaseTests(unittest.TestCase):
|
||||||
|
def test_remote_tag_commit_accepts_lightweight_tag(self) -> None:
|
||||||
|
revision = "a" * 40
|
||||||
|
self.assertEqual(
|
||||||
|
MODULE.remote_tag_commit(
|
||||||
|
f"{revision}\trefs/tags/v2.0.0", "v2.0.0"
|
||||||
|
),
|
||||||
|
revision,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_remote_tag_commit_peels_signed_annotated_tag(self) -> None:
|
||||||
|
tag_object = "a" * 40
|
||||||
|
revision = "b" * 40
|
||||||
|
self.assertEqual(
|
||||||
|
MODULE.remote_tag_commit(
|
||||||
|
f"{tag_object}\trefs/tags/v2.0.0\n"
|
||||||
|
f"{revision}\trefs/tags/v2.0.0^{{}}",
|
||||||
|
"v2.0.0",
|
||||||
|
),
|
||||||
|
revision,
|
||||||
|
)
|
||||||
|
|
||||||
def test_root_version_is_the_only_product_version(self) -> None:
|
def test_root_version_is_the_only_product_version(self) -> None:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
MODULE.root_product_version(
|
MODULE.root_product_version(
|
||||||
|
|||||||
Reference in new issue
Block a user