-
Notifications
You must be signed in to change notification settings - Fork 83
build(python): give RC artifacts unique versions #557
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
Merged
XiaoHongbo-Hope
merged 4 commits into
apache:main
from
XiaoHongbo-Hope:fix/python-rc-artifact-version
Jul 21, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0ceaa4d
build(python): derive RC artifact version from tag
XiaoHongbo-Hope af82b8f
build(python): harden release workflow
XiaoHongbo-Hope 16c2d1a
fix(python): honor dispatched release tag
XiaoHongbo-Hope 2b0ebdb
fix(python): align manual RC releases
XiaoHongbo-Hope File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Set a unique Python version for release-candidate artifacts.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import re | ||
| import sys | ||
| import tomllib | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| TAG_PATTERN = re.compile(r"^v(?P<base>\d+\.\d+\.\d+)(?:-rc(?P<rc>[1-9]\d*))?$") | ||
|
XiaoHongbo-Hope marked this conversation as resolved.
|
||
| DYNAMIC_VERSION = 'dynamic = ["version"]' | ||
|
|
||
|
|
||
| def workspace_version(root: Path) -> str: | ||
| with (root / "Cargo.toml").open("rb") as source: | ||
| return str(tomllib.load(source)["workspace"]["package"]["version"]) | ||
|
|
||
|
|
||
| def python_version(tag: str, expected_base: str) -> str: | ||
| match = TAG_PATTERN.fullmatch(tag) | ||
| if match is None: | ||
| raise ValueError(f"invalid release tag: {tag}") | ||
| base = match.group("base") | ||
| if base != expected_base: | ||
| raise ValueError(f"tag {base} does not match workspace {expected_base}") | ||
| rc = match.group("rc") | ||
| return base if rc is None else f"{base}rc{rc}" | ||
|
|
||
|
|
||
| def update_pyproject(path: Path, version: str, expected_base: str) -> None: | ||
| if version == expected_base: | ||
| return | ||
| content = path.read_text(encoding="utf-8") | ||
| if content.count(DYNAMIC_VERSION) != 1: | ||
| raise ValueError(f"unexpected dynamic version setting in {path}") | ||
| path.write_text( | ||
| content.replace(DYNAMIC_VERSION, f'version = "{version}"', 1), | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--tag", required=True) | ||
| parser.add_argument("--pyproject", type=Path) | ||
| args = parser.parse_args() | ||
|
|
||
| root = Path(__file__).resolve().parents[1] | ||
| try: | ||
| base = workspace_version(root) | ||
| version = python_version(args.tag, base) | ||
| if args.pyproject is not None: | ||
| update_pyproject(root / args.pyproject, version, base) | ||
| except (KeyError, OSError, ValueError, tomllib.TOMLDecodeError) as error: | ||
| print(f"Python release version failed: {error}", file=sys.stderr) | ||
| return 1 | ||
|
|
||
| print(version) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.