-
Notifications
You must be signed in to change notification settings - Fork 1k
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
achals
merged 4 commits into
feast-dev:master
from
achals:achal/update-version-bump-script
May 16, 2022
+52
−63
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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}") | ||
|
@@ -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 " \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "contain" There was a problem hiding this comment. Choose a reason for hiding this commentThe 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__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.