Skip to content

Commit f6129b0

Browse files
committed
ci: Add version bump script
Signed-off-by: Willem Pienaar <git@willem.co>
1 parent 8e5a2f5 commit f6129b0

File tree

4 files changed

+115
-3
lines changed

4 files changed

+115
-3
lines changed

.releaserc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ module.exports = {
4141
}
4242
],
4343
["@semantic-release/exec", {
44-
"verifyReleaseCmd": "./infra/scripts/validate-release.sh ${nextRelease.type} " + current_branch
44+
"verifyReleaseCmd": "./infra/scripts/validate-release.sh ${nextRelease.type} " + current_branch,
45+
"prepareCmd": "./infra/version_bump/bump_file_versions.py ${lastRelease.version} ${nextRelease.type}"
4546
}]
4647
]
4748
}
4849

49-

infra/scripts/helm/validate-helm-chart-versions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ echo "Found ${CHANGED_VERSIONS_COUNT} versions that have been changed"
2121
echo "This repository should contain ${UNIQUE_VERSIONS_COUNT} changed versions"
2222

2323
if [ $UNIQUE_VERSIONS_COUNT -ne "${CHANGED_VERSIONS_COUNT}" ]; then
24-
echo "We expected $UNIQUE_VERSIONS_COUNT to have been updated to the latest version, but online ${CHANGED_VERSIONS_COUNT} have. This number is statically defined based on a simple grep"
24+
echo "We expected $UNIQUE_VERSIONS_COUNT to have been updated to the latest version, but only ${CHANGED_VERSIONS_COUNT} have. This number is statically defined based on a simple grep"
2525
echo "Please confirm that all versions in all charts and requirements files have been bumped to the tagged release version. If you have successfully bumped all versions and there is still a mismatch in the expected and actual counts, then rerun the following command"
2626
echo "grep -R 'insert_your_semver_version_here' . | wc -l"
2727
echo "and update the script scripts/validate-helm-chart-versions.sh"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# This script will bump the versions found in files (charts, pom.xml) during the Feast release process.
2+
3+
import pathlib
4+
import sys
5+
6+
USAGE = f"Usage: python {sys.argv[0]} [--help] | current_semver_version new_semver_version]"
7+
VERSIONS_TO_BUMP = 26
8+
9+
10+
def main() -> None:
11+
args = sys.argv[1:]
12+
if not args or len(args) != 2:
13+
raise SystemExit(USAGE)
14+
15+
current_version = args[0].strip()
16+
new_version = args[1].strip()
17+
18+
if current_version == new_version:
19+
raise SystemExit(f"Current and new versions are the same: {current_version} == {new_version}")
20+
21+
# Validate that the input arguments are semver versions
22+
if not is_semantic_version(current_version):
23+
raise SystemExit(f"Current version is not a valid semantic version: {current_version}")
24+
25+
if not is_semantic_version(new_version):
26+
raise SystemExit(f"New version is not a valid semantic version: {new_version}")
27+
28+
# Get git repo root directory
29+
repo_root = pathlib.Path(__file__).resolve().parent.parent.parent.parent
30+
path_to_file_list = repo_root.joinpath("infra", "scripts", "version_bump", "files_to_bump.txt")
31+
32+
# Get files to bump versions within
33+
with open(path_to_file_list, "r") as f:
34+
files_to_bump = f.read().splitlines()
35+
36+
# The current version should be 0.18.0 or 0.19.0 or 0.20.0 etc, but we should also make sure to support the
37+
# occasional patch release on the master branch like 0.18.1 or 0.18.2
38+
versions_in_files = 0
39+
if current_version[-2:] != ".0":
40+
print(current_version[-2:])
41+
versions_in_files = count_version(current_version, files_to_bump, repo_root)
42+
if versions_in_files != VERSIONS_TO_BUMP:
43+
raise SystemExit(f"Found {versions_in_files} occurrences of {current_version} in files to bump, but "
44+
f"expected {VERSIONS_TO_BUMP}")
45+
else:
46+
found = False
47+
48+
# Lets make sure the files don't contain a patch version (e.g, 0.x.0 -> 0.x.20)
49+
for patch_version in range(0, 20):
50+
current_version_patch = current_version[:-1] + str(patch_version)
51+
versions_in_files = count_version(current_version_patch, files_to_bump, repo_root)
52+
53+
# We are using a patch version, let's change our version number
54+
if versions_in_files == VERSIONS_TO_BUMP:
55+
print(f"Found {versions_in_files} occurrences of {current_version_patch}, changing current version to "
56+
f"{current_version_patch}")
57+
current_version = current_version_patch
58+
found = True
59+
break
60+
if not found:
61+
raise SystemExit(f"Could not find {VERSIONS_TO_BUMP} versions of {current_version} in {path_to_file_list}")
62+
63+
print(f"Found {versions_in_files} occurrences of {current_version} in files to bump {path_to_file_list}")
64+
65+
# Bump the version in the files
66+
updated_count = 0
67+
for file in files_to_bump:
68+
with open(repo_root.joinpath(file), "r") as f:
69+
file_contents = f.read()
70+
file_contents = file_contents.replace(current_version, new_version)
71+
72+
with open(repo_root.joinpath(file), "w") as f:
73+
f.write(file_contents)
74+
updated_count += 1
75+
76+
print(f"Updated {updated_count} files with new version {new_version}")
77+
78+
79+
def is_semantic_version(version: str) -> bool:
80+
components = version.split(".")
81+
if len(components) != 3:
82+
return False
83+
for component in components:
84+
if not component.isdigit():
85+
return False
86+
return True
87+
88+
89+
def count_version(current_version, files_to_bump, repo_root):
90+
# Count how many of the existing versions we find
91+
total = 0
92+
for file in files_to_bump:
93+
with open(repo_root.joinpath(file), "r") as f:
94+
file_contents = f.read()
95+
total += file_contents.count(current_version)
96+
return total
97+
98+
99+
if __name__ == "__main__":
100+
main()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
infra/charts/feast/requirements.yaml
2+
infra/charts/feast/Chart.yaml
3+
infra/charts/feast/charts/transformation-service/Chart.yaml
4+
infra/charts/feast/charts/transformation-service/README.md
5+
infra/charts/feast/charts/transformation-service/values.yaml
6+
infra/charts/feast/charts/feature-server/Chart.yaml
7+
infra/charts/feast/charts/feature-server/README.md
8+
infra/charts/feast/charts/feature-server/values.yaml
9+
infra/charts/feast/README.md
10+
infra/charts/feast-python-server/Chart.yaml
11+
infra/charts/feast-python-server/README.md
12+
java/pom.xml

0 commit comments

Comments
 (0)