-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathupdate_git_versions.py
More file actions
85 lines (65 loc) · 2.2 KB
/
Copy pathupdate_git_versions.py
File metadata and controls
85 lines (65 loc) · 2.2 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
73
74
75
76
77
78
79
80
81
82
83
84
85
import contextlib
import re
import subprocess
import sys
from pathlib import Path
from typing import Any
if __name__ == "__main__" and not __package__:
file = Path(__file__).resolve()
parent, top = file.parent, file.parents[1]
if str(top) not in sys.path:
sys.path.append(str(top))
with contextlib.suppress(ValueError):
sys.path.remove(str(parent))
__package__ = "scripts"
from scripts.tools import get_version
def replace_in_file(filename: Path, pattern: "re.Pattern[str]", to: str) -> None:
text = filename.read_text()
new = pattern.sub(to, text)
filename.write_text(new)
def run(title: str, *args: Any, **kwargs: Any) -> None:
try:
print(f"running {title}")
subprocess.run(*args, **kwargs)
except (SystemExit, KeyboardInterrupt):
raise
except BaseException as e:
print(f"{title} failed: {e}", file=sys.stderr)
def main() -> None:
version = get_version()
version_files = list(Path("packages").rglob("__version__.py"))
for f in [Path("src/robotcode/cli/__version__.py"), *version_files]:
replace_in_file(
f,
re.compile(r"""(^_*version_*\s*=\s*['"])([^'"]*)(['"])""", re.MULTILINE),
rf"\g<1>{version or ''}\g<3>",
)
# replace_in_file(
# Path("package.json"),
# re.compile(
# r"""(\"version\"\s*:\s*['"])([0-9]+\.[0-9]+\.[0-9]+.*)(['"])""",
# re.MULTILINE,
# ),
# rf"\g<1>{version or ''}\g<3>",
# )
run(
"npm version",
f"npm --no-git-tag-version version {version}",
shell=True,
timeout=600,
)
pyproject_files = list(Path("packages").rglob("pyproject.toml"))
for f in [Path("pyproject.toml"), *pyproject_files]:
replace_in_file(
f,
re.compile(r"""("robotcode\S*==)([0-9]+\.[0-9]+\.[0-9]+[^'"]*)(")""", re.MULTILINE),
rf"\g<1>{version or ''}\g<3>",
)
for f in [Path("intellij-client/gradle.properties")]:
replace_in_file(
f,
re.compile(r"""(^pluginVersion\s*=\s*)([0-9]+\S*)""", re.MULTILINE),
rf"\g<1>{version or ''}",
)
if __name__ == "__main__":
main()