Skip to content

Commit f745256

Browse files
committed
feat: Make check_release fail on released versions.
Hackage refuses to upload a version it already has, so we should catch this before merging. Also use `.value` instead of `.s`, since Python 3.14 removed `.s`.
1 parent 86306f8 commit f745256

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎.restyled.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ restylers:
1515
image: ghcr.io/toktok/restyler-autopep8:v2.3.2
1616
- black:
1717
image: ghcr.io/toktok/restyler-black:v26.10.1
18+
- isort:
19+
image: ghcr.io/toktok/restyler-isort:v9.0.2
1820
- prettier-markdown:
1921
image: ghcr.io/toktok/restyler-prettier:v3.9.10-6
2022
- prettier-yaml:

‎bin/check_release‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os
44
import re
55
import subprocess # nosec
66
import sys
7-
from typing import List, Optional, cast
7+
from typing import Any, List, Optional, cast
88

99
import requests
1010

@@ -23,9 +23,10 @@ def github_repo() -> str:
2323
)
2424

2525

26-
def release_github() -> Optional[str]:
26+
def github_releases() -> list[dict[str, Any]]:
2727
resp = requests.get(
2828
f"{os.environ['GITHUB_API_URL']}/repos/{github_repo()}/releases",
29+
params={"per_page": "100"},
2930
auth=("", os.environ["GITHUB_TOKEN"]),
3031
)
3132

@@ -34,7 +35,10 @@ def release_github() -> Optional[str]:
3435
print(f"WARNING: GitHub API failed to list releases: {releases}")
3536
print("WARNING: Aborting.")
3637
sys.exit(1)
38+
return releases
3739

40+
41+
def release_github(releases: list[dict[str, Any]]) -> Optional[str]:
3842
# Drafts are hidden from tokens that can't push, as in PRs from forks.
3943
if not releases:
4044
print("WARNING: Could not find any releases.")
@@ -119,9 +123,9 @@ def release_local(path: str) -> tuple[Optional[str], str, bool]:
119123
if (
120124
arg.arg == "version"
121125
and isinstance(arg.value, ast.Constant)
122-
and isinstance(arg.value.s, str)
126+
and isinstance(arg.value.value, str)
123127
):
124-
return arg.value.s, "BUILD.bazel", True
128+
return arg.value.value, "BUILD.bazel", True
125129

126130
if os.path.exists(os.path.join(path, "configure.ac")):
127131
with open(os.path.join(path, "configure.ac"), "r") as fh:
@@ -151,7 +155,8 @@ def release_local(path: str) -> tuple[Optional[str], str, bool]:
151155
def main(prog: str, args: List[str]) -> None:
152156
path = args[0] if args else "."
153157

154-
gh_release = release_github()
158+
releases = github_releases()
159+
gh_release = release_github(releases)
155160
pr_release = release_pr_milestone()
156161
ms_release = release_milestone()
157162
local_release, local_origin, local_required = release_local(path)
@@ -161,6 +166,14 @@ def main(prog: str, args: List[str]) -> None:
161166
print(f"PR Milestone release: {pr_release}")
162167
print(f"Local release: {local_release} ({local_origin})")
163168

169+
if local_required and f"v{local_release}" in (
170+
r["tag_name"] for r in releases if not r["draft"]
171+
):
172+
print(
173+
f"\nFAIL: {local_release} in {local_origin} is already released. "
174+
"Bump it for the next release."
175+
)
176+
sys.exit(1)
164177
if local_required and gh_release and gh_release != local_release:
165178
print(
166179
f"\nFAIL: GitHub draft release {gh_release} does not match "

0 commit comments

Comments
 (0)