-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathbump_file_versions.py
More file actions
94 lines (72 loc) · 3.5 KB
/
bump_file_versions.py
File metadata and controls
94 lines (72 loc) · 3.5 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
86
87
88
89
90
91
92
93
94
# This script will bump the versions found in files (charts, pom.xml) during the Feast release process.
import re
import pathlib
import sys
USAGE = f"Usage: python {sys.argv[0]} [--help] | current_semver_version new_semver_version]"
VERSIONS_TO_BUMP = 27
def main() -> None:
args = sys.argv[1:]
if not args or len(args) != 2:
raise SystemExit(USAGE)
current_version = args[0].strip()
new_version = args[1].strip()
if current_version == new_version:
raise SystemExit(f"Current and new versions are the same: {current_version} == {new_version}")
# Validate that the input arguments are semver versions
if not is_semantic_version(current_version):
raise SystemExit(f"Current version is not a valid semantic version: {current_version}")
if not is_semantic_version(new_version):
raise SystemExit(f"New version is not a valid semantic version: {new_version}")
# Get git repo root directory
repo_root = pathlib.Path(__file__).resolve().parent.parent.parent.parent
path_to_file_list = repo_root.joinpath("infra", "scripts", "release", "files_to_bump.txt")
# Get files to bump versions within
with open(path_to_file_list, "r") as f:
files_to_bump = f.read().splitlines()
# The current version should be 0.18.0 or 0.19.0 or 0.20.0 etc
validate_files_to_bump(current_version, files_to_bump, repo_root)
# Bump the version in the files
updated_count = 0
for file in files_to_bump:
components = file.split(" ")
file_path = components[0]
lines = components[1:]
with open(repo_root.joinpath(file_path), "r") as f:
file_contents = f.readlines()
for line in lines:
# note we validate the version above already
current_parsed_version = _get_semantic_version(file_contents[int(line) - 1])
file_contents[int(line) - 1] = file_contents[int(line) - 1].replace(current_parsed_version, new_version)
with open(repo_root.joinpath(file_path), "w") as f:
f.write(''.join(file_contents))
updated_count += 1
print(f"Updated {updated_count} files with new version {new_version}")
def is_semantic_version(version: str) -> bool:
components = version.split(".")
if len(components) != 3:
return False
for component in components:
if not component.isdigit():
return False
return True
def validate_files_to_bump(current_version, files_to_bump, repo_root):
for file in files_to_bump:
components = file.split(" ")
assert len(components) > 1, f"Entry {file} should have a file name, and a list of line numbers with versions"
file_path = components[0]
lines = components[1:]
with open(repo_root.joinpath(file_path), "r") as f:
file_contents = f.readlines()
for line in lines:
new_version = _get_semantic_version(file_contents[int(line) - 1])
current_major_minor_version = '.'.join(current_version.split(".")[0:1])
assert current_version in new_version or current_major_minor_version in new_version, (
f"File `{file_path}` line `{line}` didn't contain version {current_version}. "
f"Contents: {file_contents[int(line) - 1]}"
)
def _get_semantic_version(input_string: str) -> str:
semver_pattern = r'\bv?(\d+\.\d+\.\d+)\b'
match = re.search(semver_pattern, input_string)
return match.group(1)
if __name__ == "__main__":
main()