Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support toxic's version location. #82

Merged
merged 1 commit into from
Nov 11, 2024
Merged
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
24 changes: 17 additions & 7 deletions bin/check_release
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def release_pr_milestone() -> str:
return version[1:] # Remove the 'v' prefix.


def release_local(path: str) -> tuple[Optional[str], str]:
def release_local(path: str) -> tuple[Optional[str], str, bool]:
with open(os.path.join(path, "BUILD.bazel"), "r") as fh:
bzl = ast.parse(fh.read(), filename=path)
for stmt in bzl.body:
Expand All @@ -104,19 +104,29 @@ def release_local(path: str) -> tuple[Optional[str], str]:
if (arg.arg == "version"
and isinstance(arg.value, ast.Constant)
and isinstance(arg.value.s, str)):
return arg.value.s, "BUILD.bazel"
return arg.value.s, "BUILD.bazel", True

# Check if configure.ac exists.
if os.path.exists(os.path.join(path, "configure.ac")):
return None, "configure.ac"
with open(os.path.join(path, "configure.ac"), "r") as fh:
for line in fh:
res = re.match(r"AC_INIT\(\[.*\], \[(.*)\][,)]", line)
if res:
return res.group(1), "configure.ac", False

if os.path.exists(os.path.join(path, "cfg/global_vars.mk")):
with open(os.path.join(path, "cfg/global_vars.mk"), "r") as fh:
for line in fh:
res = re.match(r"TOXIC_VERSION = (.*)", line)
if res:
return res.group(1), "cfg/global_vars.mk", False

# Check if README.md contains "Version: x.y.z".
if os.path.exists(os.path.join(path, "README.md")):
with open(os.path.join(path, "README.md"), "r") as fh:
for line in fh:
res = re.match(r"Version: (.*)", line)
if res:
return res.group(1), "README.md"
return res.group(1), "README.md", False

raise Exception(f"Could not find a version in {path}")

Expand All @@ -127,7 +137,7 @@ def main(prog: str, args: List[str]) -> None:
gh_release = release_github()
pr_release = release_pr_milestone()
ms_release = release_milestone()
local_release, local_origin = release_local(path)
local_release, local_origin, local_required = release_local(path)

print(f"GitHub release: {gh_release}")
print(f"Next GitHub Milestone release: {ms_release}")
Expand All @@ -140,7 +150,7 @@ def main(prog: str, args: List[str]) -> None:
# event as opposed to a pull_request_target event.
gh_release = pr_release

if local_release and gh_release != local_release:
if local_required and gh_release != local_release:
print(f"\nFAIL: GitHub draft release {gh_release} does not match "
f"{local_origin} {local_release}")
sys.exit(1)
Expand Down
Loading