Skip to content
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

ci: Make version bumping script more robust #2689

Merged
merged 4 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 23 additions & 43 deletions infra/scripts/release/bump_file_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,22 @@ def main() -> None:
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, but we should also make sure to support the
# occasional patch release on the master branch like 0.18.1 or 0.18.2
versions_in_files = 0
if current_version[-2:] != ".0":
print(current_version[-2:])
versions_in_files = count_version(current_version, files_to_bump, repo_root)
if versions_in_files != VERSIONS_TO_BUMP:
raise SystemExit(f"Found {versions_in_files} occurrences of {current_version} in files to bump, but "
f"expected {VERSIONS_TO_BUMP}")
else:
found = False

# Lets make sure the files don't contain a patch version (e.g, 0.x.0 -> 0.x.20)
for patch_version in range(0, 20):
current_version_patch = current_version[:-1] + str(patch_version)
versions_in_files = count_version(current_version_patch, files_to_bump, repo_root)

# We are using a patch version, let's change our version number
if versions_in_files == VERSIONS_TO_BUMP:
print(f"Found {versions_in_files} occurrences of {current_version_patch}, changing current version to "
f"{current_version_patch}")
current_version = current_version_patch
found = True
break
else:
print(f"Found {versions_in_files} occurrences of {current_version_patch}, instead of {VERSIONS_TO_BUMP}")
if not found:
raise SystemExit(f"Could not find {VERSIONS_TO_BUMP} versions of {current_version} in {path_to_file_list}")

print(f"Found {versions_in_files} occurrences of {current_version} in files to bump {path_to_file_list}")
# The current version should be 0.18.0 or 0.19.0 or 0.20.0 etc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need 0.18.0 or 0.19.0 right? Also after version bump we're at 0.21?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as an example, but I'll update.

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:
with open(repo_root.joinpath(file), "r") as f:
file_contents = f.read()
file_contents = file_contents.replace(current_version, new_version)

with open(repo_root.joinpath(file), "w") as f:
f.write(file_contents)
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:
file_contents[int(line) - 1] = file_contents[int(line) - 1].replace(current_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}")
Expand All @@ -88,14 +64,18 @@ def is_semantic_version(version: str) -> bool:
return True


def count_version(current_version, files_to_bump, repo_root):
# Count how many of the existing versions we find
total = 0
def validate_files_to_bump(current_version, files_to_bump, repo_root):
for file in files_to_bump:
with open(repo_root.joinpath(file), "r") as f:
file_contents = f.read()
total += file_contents.count(current_version)
return total
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:
assert current_version in file_contents[int(line) - 1], f"File {file_path} line {line} didn't containe " \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "contain"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops fixed

f"version {current_version}. " \
f"Contents: {file_contents[int(line) - 1]}"


if __name__ == "__main__":
Expand Down
25 changes: 12 additions & 13 deletions infra/scripts/release/files_to_bump.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
infra/charts/feast/requirements.yaml
infra/charts/feast/Chart.yaml
infra/charts/feast/charts/transformation-service/Chart.yaml
infra/charts/feast/charts/transformation-service/README.md
infra/charts/feast/charts/transformation-service/values.yaml
infra/charts/feast/charts/feature-server/Chart.yaml
infra/charts/feast/charts/feature-server/README.md
infra/charts/feast/charts/feature-server/values.yaml
infra/charts/feast/README.md
infra/charts/feast-python-server/Chart.yaml
infra/charts/feast-python-server/README.md
java/pom.xml
ui/package.json
infra/charts/feast/requirements.yaml 4 9
infra/charts/feast/Chart.yaml 4
infra/charts/feast/charts/transformation-service/Chart.yaml 4 5
infra/charts/feast/charts/transformation-service/README.md 3 16
infra/charts/feast/charts/transformation-service/values.yaml 8
infra/charts/feast/charts/feature-server/Chart.yaml 4 5
infra/charts/feast/charts/feature-server/README.md 3 20
infra/charts/feast/charts/feature-server/values.yaml 8
infra/charts/feast/README.md 11 58 59
infra/charts/feast-python-server/Chart.yaml 5
infra/charts/feast-python-server/README.md 3
java/pom.xml 41