-
Notifications
You must be signed in to change notification settings - Fork 3
Add a release helper to x.py #11
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
Open
moucha19-st
wants to merge
2
commits into
main
Choose a base branch
from
x-release
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,15 +43,16 @@ | |
|
|
||
| def target(msg: str = None, dependencies: set[str] = frozenset()): | ||
| def decorator(func): | ||
| def wrapper(): | ||
| def wrapper(*args, **kwargs): | ||
| if func.__name__ in already_run: | ||
| return | ||
| for dep in dependencies: | ||
| dep() | ||
| if msg: | ||
| print(f"\n>\t{msg}\n") | ||
| func() | ||
| result = func(*args, **kwargs) | ||
| already_run.add(func.__name__) | ||
| return result | ||
|
|
||
| targets[func.__name__] = wrapper | ||
| return wrapper | ||
|
|
@@ -71,21 +72,45 @@ def run(args: list[str], **kwargs): | |
| print(f"Command {e.filename} does not exist!") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def replace_line(path: str, pattern: str, replacement: str): | ||
| with open(path, "r", encoding="utf-8") as file: | ||
| content = file.read() | ||
|
|
||
| new_content, replaced = re.subn(pattern, replacement, content, flags=re.MULTILINE) | ||
| if replaced != 1: | ||
| print(f"Expected to replace exactly one line in {path}, replaced {replaced} lines instead.") | ||
| sys.exit(1) | ||
|
|
||
| with open(path, "w", encoding="utf-8") as file: | ||
| file.write(new_content) | ||
|
|
||
| @target("Generating version from Git") | ||
| def version(): | ||
| ver = json.loads(run(["dotnet-gitversion"], capture_output=True, text=True).stdout) | ||
| ver = json.loads(run(["dotnet", "tool", "exec", "GitVersion.Tool"], capture_output=True, text=True).stdout) | ||
| if ver['PreReleaseLabel']: | ||
| prerelease = f".{ver['PreReleaseLabel']}{ver['PreReleaseNumber']}" | ||
| else: | ||
| prerelease = "" | ||
| python_ver = f"{ver['MajorMinorPatch']}{prerelease}" | ||
| with open("../compost_rpc/compost_rpc.py", "r") as file: | ||
| content = file.read() | ||
| content = re.sub(r'^__version__\s*=.*$', f"__version__ = \"{python_ver}\"", content, flags=re.MULTILINE) | ||
| with open("../compost_rpc/compost_rpc.py", "w") as file: | ||
| file.write(content) | ||
| replace_line("../compost_rpc/compost_rpc.py", r'^__version__\s*=.*$', f'__version__ = "{python_ver}"') | ||
| run(["uv", "version", python_ver]) | ||
| print(f"Detected version {python_ver} from Git repository.") | ||
| return python_ver | ||
|
|
||
|
|
||
| @target("Creating release commit") | ||
| def release(release_type: str): | ||
| run(["uv", "version", "--bump", release_type]) | ||
| new_version = run(["uv", "version", "--short"], capture_output=True, text=True).stdout.strip() | ||
|
|
||
| replace_line("../compost_rpc/compost_rpc.py", r'^__version__\s*=.*$', f'__version__ = "{new_version}"') | ||
|
|
||
| run(["git", "-C", "..", "add", "compost_rpc/compost_rpc.py", "pyproject.toml"]) | ||
| run(["git", "-C", "..", "commit", "-m", f"chore: Release version {new_version}"]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like the "chore: " prefix
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be removed. |
||
| run(["git", "-C", "..", "tag", f"v{new_version}"]) | ||
|
|
||
| print(f"Created release commit for version {new_version}.") | ||
|
|
||
| @target("Generating code") | ||
| def codegen(): | ||
|
|
@@ -181,13 +206,24 @@ def test_powerpc(): | |
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(prog="test.py", description="Compost test runner") | ||
| parser.add_argument("target", nargs="?", default="test", choices=targets.keys(), help="Target to run") | ||
| parser = argparse.ArgumentParser(prog="x.py", description="Compost development script") | ||
| subparsers = parser.add_subparsers(dest="target") | ||
| parser.set_defaults(target="test") | ||
|
|
||
| for target_name in targets: | ||
| target_parser = subparsers.add_parser(target_name, help=f"Run '{target_name}' target") | ||
| if target_name == "release": | ||
| target_parser.add_argument("release_type", choices=("major", "minor", "patch"), help="Release bump type") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| target_kwargs = {} | ||
| if args.target == "release": | ||
| target_kwargs["release_type"] = args.release_type | ||
|
|
||
| # Change current working directory to the script directory | ||
| os.chdir(sys.path[0] + "/test") | ||
|
|
||
| targets[args.target]() | ||
| targets[args.target](**target_kwargs) | ||
|
|
||
| print("Finished successfully") | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird on multiple levels - you use
-Cand give a relative path and then the path is... Why?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is weird because the script sets the
testfolder globally as a root. If we extend this script to do more than just tests, it should be changed. Didn't do it yet though, hence this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should change it then, but even if we didn't I don't see the reason to do this.