Skip to content
Merged
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
4 changes: 3 additions & 1 deletion tools/create_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,11 @@ def stage_push(self) -> None:

def has_tarballs(self, version: str) -> bool:
"""Check if there are tarball assets for the given version."""
project_name = self.github.repository_name()
bare_version = version[1:] if version.startswith("v") else version
assets = self.github.release_assets(version)
return all(
any(a.name == f"{version}.tar.{ext}" for a in assets)
any(a.name == f"{project_name}-{bare_version}.tar.{ext}" for a in assets)
for ext in ("gz", "xz")
)

Expand Down
17 changes: 12 additions & 5 deletions tools/create_tarballs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,23 @@ def parse_args() -> Config:
return Config(**vars(args))


def _strip_v(tag: str) -> str:
"""Strip leading 'v' from a tag to get the bare version number."""
return tag[1:] if tag.startswith("v") else tag


def create_tarballs(project_name: str, tag: str, tmpdir: str) -> None:
"""Create source tarballs with both .gz and .xz for the given tag."""
version = _strip_v(tag)
for prog in ("gzip", "xz"):
tarname = f"{os.path.join(tmpdir, tag)}.tar"
tarname = f"{os.path.join(tmpdir, project_name)}-{version}.tar"
print(f"Creating {prog} tarball for {tag}")
subprocess.run( # nosec
[
"git",
"archive",
"--format=tar",
f"--prefix={project_name}-{tag}/",
f"--prefix={project_name}-{version}/",
tag,
f"--output={tarname}",
],
Expand All @@ -64,14 +70,15 @@ def create_tarballs(project_name: str, tag: str, tmpdir: str) -> None:
subprocess.run([prog, "-f", tarname], check=True) # nosec


def upload_tarballs(tag: str, tmpdir: str) -> None:
def upload_tarballs(project_name: str, tag: str, tmpdir: str) -> None:
"""Upload the tarballs to GitHub."""
version = _strip_v(tag)
content_type = {
"gz": "application/gzip",
"xz": "application/x-xz",
}
for ext in ("gz", "xz"):
filename = f"{tag}.tar.{ext}"
filename = f"{project_name}-{version}.tar.{ext}"
print(f"Uploading {filename} to GitHub release {tag}")
with open(os.path.join(tmpdir, filename), "rb") as f:
github.upload_asset(tag, filename, content_type[ext], f)
Expand All @@ -81,7 +88,7 @@ def main(config: Config) -> None:
if config.upload:
with tempfile.TemporaryDirectory() as tmpdir:
create_tarballs(config.project_name, config.tag, tmpdir)
upload_tarballs(config.tag, tmpdir)
upload_tarballs(config.project_name, config.tag, tmpdir)
else:
create_tarballs(config.project_name, config.tag, ".")

Expand Down
8 changes: 4 additions & 4 deletions tools/create_tarballs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_upload_create(
mock_tmp.return_value.__enter__.return_value = "/tmp/dir" # nosec
main(self.config)
mock_create.assert_called_once_with("ci-tools", "v1.0.0", "/tmp/dir") # nosec
mock_upload.assert_called_once_with("v1.0.0", "/tmp/dir") # nosec
mock_upload.assert_called_once_with("ci-tools", "v1.0.0", "/tmp/dir") # nosec

@patch("subprocess.run")
@patch("create_tarballs.os.path.join")
Expand All @@ -49,14 +49,14 @@ def test_create_tarballs_logic(
"git",
"archive",
"--format=tar",
"--prefix=ci-tools-v1.0.0/",
"--prefix=ci-tools-1.0.0/",
"v1.0.0",
"--output=/tmp/dir/v1.0.0.tar", # nosec
"--output=/tmp/dir/ci-tools-1.0.0.tar", # nosec
],
check=True,
)
mock_run.assert_any_call(
["gzip", "-nf", "/tmp/dir/v1.0.0.tar"], check=True # nosec
["gzip", "-nf", "/tmp/dir/ci-tools-1.0.0.tar"], check=True # nosec
)


Expand Down
Loading