-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_release.py
More file actions
executable file
·72 lines (57 loc) · 1.98 KB
/
create_release.py
File metadata and controls
executable file
·72 lines (57 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""Bump version in package.xml and conda.recipe/recipe.yaml, then commit."""
import argparse
import re
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parent
VERSION_FILES = {
REPO / "package.xml": (
re.compile(r"(<version>)([\d.]+)(</version>)"),
r"\g<1>{version}\g<3>",
),
REPO / "conda.recipe/recipe.yaml": (
re.compile(r'(version:\s*")[\d.]+(")'),
r'\g<1>{version}\2',
),
}
def current_version() -> str:
text = (REPO / "package.xml").read_text()
m = re.search(r"<version>([\d.]+)</version>", text)
if not m:
sys.exit("Cannot read current version from package.xml")
return m.group(1)
def update_file(path: Path, pattern: re.Pattern, replacement: str, version: str):
text = path.read_text()
new_text, n = pattern.subn(replacement.format(version=version), text)
if n == 0:
sys.exit(f"Version pattern not found in {path.relative_to(REPO)}")
path.write_text(new_text)
print(f" {path.relative_to(REPO)}: updated to {version}")
def main():
cur = current_version()
parser = argparse.ArgumentParser(description="Bump project version and commit.")
parser.add_argument("version", help=f"New version (current: {cur})")
parser.add_argument(
"--no-commit", action="store_true", help="Update files without committing"
)
args = parser.parse_args()
new = args.version
if new == cur:
sys.exit(f"Version is already {cur}")
print(f"Bumping {cur} → {new}")
for path, (pattern, repl) in VERSION_FILES.items():
update_file(path, pattern, repl, new)
if args.no_commit:
return
files = [str(p) for p in VERSION_FILES]
subprocess.run(["git", "add", *files], check=True, cwd=REPO)
subprocess.run(
["git", "commit", "-m", new],
check=True,
cwd=REPO,
)
print(f"\nCommitted as '{new}'. Review with: git log --oneline -1")
if __name__ == "__main__":
main()