Skip to content

Commit

Permalink
chore: Fix releaser to support checking the current latest release.
Browse files Browse the repository at this point in the history
This addresses the situation where release candidates go wrong and we
don't actually release them.
  • Loading branch information
iphydf committed Jan 3, 2025
1 parent b592664 commit 3e85d4b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-test-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
git checkout master
git checkout release-head
fi
echo "prev-version=$(git describe --tags --abbrev=0 --match 'v*')" >>$GITHUB_OUTPUT
- name: Verify release
if: steps.create-identity.outputs.next-version != ''
env:
Expand All @@ -84,7 +83,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: tools/create_release.py
--version "${{ steps.create-identity.outputs.prev-version }}"
--version latest
--upstream origin
--dryrun

Expand Down
11 changes: 10 additions & 1 deletion tools/create_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def parse_args() -> Config:
)
parser.add_argument(
"--version",
help="Version to release. Default: next milestone",
help="Version to release. The special value 'latest' means the "
"current latest release on GitHub. Default: next milestone",
default="",
)
parser.add_argument(
Expand Down Expand Up @@ -116,6 +117,11 @@ def stage_version(config: Config) -> str:
s.ok(git.branch_sha(f"{config.upstream}/{config.main_branch}")[:7])
with stage.Stage("Version", "Determine the upcoming version") as s:
if config.version:
if config.version == "latest":
version = github.latest_release()
s.ok(f"Using latest release {version}")
return version

require(
re.match(git.VERSION_REGEX, config.version) is not None,
f"Invalid version: {config.version} "
Expand Down Expand Up @@ -285,6 +291,9 @@ def stage_pull_request(


def stage_restyled(config: Config, version: str, parent: stage.Stage) -> None:
if config.verify:
# Can't do this on CI.
return
with stage.Stage("Restyled", "Applying restyled fixes",
parent=parent) as s:
subprocess.run(["hub-restyled"], check=True) # nosec
Expand Down
8 changes: 8 additions & 0 deletions tools/lib/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ def open_milestone_issues(milestone: int) -> list[Issue]:
]


def latest_release() -> str:
"""Get the name of the current release in the repository.
Includes prereleases.
"""
return api(f"/repos/{repository()}/releases/latest")["tag_name"]


def prereleases(version: str) -> list[str]:
"""Get the names of all prereleases for a given version in the repository."""
return [
Expand Down

0 comments on commit 3e85d4b

Please sign in to comment.