Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix the release script not publishing binary wheels. #13850

Merged
merged 3 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions changelog.d/13850.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the release script not publishing binary wheels.
58 changes: 47 additions & 11 deletions scripts-dev/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,12 @@ def _publish(gh_token: str) -> None:


@cli.command()
def upload() -> None:
_upload()
@click.option("--gh-token", envvar=["GH_TOKEN", "GITHUB_TOKEN"], required=False)
def upload(gh_token: Optional[str]) -> None:
_upload(gh_token)


def _upload() -> None:
def _upload(gh_token: Optional[str]) -> None:
"""Upload release to pypi."""

current_version = get_package_version()
Expand All @@ -444,18 +445,53 @@ def _upload() -> None:
click.echo("Tag {tag_name} (tag.commit) is not currently checked out!")
click.get_current_context().abort()

pypi_asset_names = [
f"matrix_synapse-{current_version}-py3-none-any.whl",
f"matrix-synapse-{current_version}.tar.gz",
]
headers = {"Accept": "application/vnd.github+json"}
if gh_token is not None:
headers["authorization"] = f"token {gh_token}"

# First load info about the release
try:
url = (
f"https://api.github.com/repos/matrix-org/synapse/releases/tags/{tag_name}"
)
req = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(req)
release_info_resp = json.loads(response.read())
reivilibre marked this conversation as resolved.
Show resolved Hide resolved
except Exception:
raise RuntimeError(f"Failed to look up release by tag name '{tag_name}'!")

# Then load the list of assets
req = urllib.request.Request(release_info_resp["assets_url"], headers=headers)
response = urllib.request.urlopen(req)
asset_list_resp = json.loads(response.read())

# Only accept the wheels and sdist.
# Notably: we don't care about debs.tar.xz.
asset_names_and_urls = sorted(
(asset["name"], asset["browser_download_url"])
for asset in asset_list_resp
if asset["name"].endswith((".whl", ".tar.gz"))
)

# Print out what we've determined.
print("Found relevant assets:")
for asset_name, _ in asset_names_and_urls:
print(f" - {asset_name}")

ignored_asset_names = sorted(
{asset["name"] for asset in asset_list_resp}
- {asset_name for asset_name, _ in asset_names_and_urls}
)
print("\nIgnoring irrelevant assets:")
for asset_name in ignored_asset_names:
print(f" - {asset_name}")

with TemporaryDirectory(prefix=f"synapse_upload_{tag_name}_") as tmpdir:
for name in pypi_asset_names:
for name, asset_download_url in asset_names_and_urls:
filename = path.join(tmpdir, name)
url = f"https://github.com/matrix-org/synapse/releases/download/{tag_name}/{name}"

click.echo(f"Downloading {name} into {filename}")
urllib.request.urlretrieve(url, filename=filename)
urllib.request.urlretrieve(asset_download_url, filename=filename)

if click.confirm("Upload to PyPI?", default=True):
subprocess.run("twine upload *", shell=True, cwd=tmpdir)
Expand Down Expand Up @@ -672,7 +708,7 @@ def full(gh_token: str) -> None:
_publish(gh_token)

click.echo("\n*** upload ***")
_upload()
_upload(gh_token)

click.echo("\n*** merge back ***")
_merge_back()
Expand Down