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

Extend the release script to tag and create the releases. #10496

Merged
merged 12 commits into from
Aug 3, 2021
22 changes: 16 additions & 6 deletions scripts-dev/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from click.exceptions import ClickException
from github import Github
from packaging import version
from redbaron import RedBaron


@click.group()
Expand All @@ -55,6 +54,7 @@ def cli():
# ... wait for asssets to build ...

./scripts-dev/release.py publish
./scripts-dev/release.py upload

If the env var GH_TOKEN (or GITHUB_TOKEN) is set, or passed into the
`tag`/`publish` command, then a new draft release will be created/published.
Expand Down Expand Up @@ -267,7 +267,7 @@ def tag(gh_token: Optional[str]):

# Check we haven't released this version.
if tag_name in repo.tags:
raise click.ClickException(f"Tag already exists for {current_version}!\n")
raise click.ClickException(f"Tag {tag_name} already exists!\n")

# Get the appropriate changelogs and tag.
changes = get_changes_for_version(current_version)
Expand Down Expand Up @@ -316,7 +316,7 @@ def tag(gh_token: Optional[str]):
@cli.command()
@click.option("--gh-token", envvar=["GH_TOKEN", "GITHUB_TOKEN"])
def publish(gh_token: Optional[str]):
"""Publish release and upload to PyPI."""
"""Publish release."""

# Make sure we're in a git repo.
try:
Expand All @@ -334,7 +334,7 @@ def publish(gh_token: Optional[str]):
return

if gh_token:
richvdh marked this conversation as resolved.
Show resolved Hide resolved
# Create a new draft release
# Publish the draft release
gh = Github(gh_token)
gh_repo = gh.get_repo("matrix-org/synapse")
for release in gh_repo.get_releases():
Expand All @@ -357,6 +357,14 @@ def publish(gh_token: Optional[str]):
draft=False,
)


@cli.command()
def upload(gh_token: Optional[str]):
"""Upload release to pypi."""

current_version, _, _ = parse_version_from_module()
tag_name = f"v{current_version}"

pypi_asset_names = [
f"matrix_synapse-{current_version}-py3-none-any.whl",
f"matrix-synapse-{current_version}.tar.gz",
Expand All @@ -378,11 +386,13 @@ def publish(gh_token: Optional[str]):
)


def parse_version_from_module() -> Tuple[version.Version, RedBaron, redbaron.Node]:
def parse_version_from_module() -> Tuple[
version.Version, redbaron.RedBaron, redbaron.Node
]:
# Parse the AST and load the `__version__` node so that we can edit it
# later.
with open("synapse/__init__.py") as f:
red = RedBaron(f.read())
red = redbaron.RedBaron(f.read())

version_node = None
for node in red:
Expand Down