-
-
Notifications
You must be signed in to change notification settings - Fork 10
chore: Add basic script to upgrade most helm-charts #250
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0350f3e
chore: Add basic script to upgrade most helm-charts
sbernauer b2ef4e5
Mention in issue template
sbernauer 3a478c9
typo
sbernauer e6e5dad
fix: Update repos
sbernauer 058012c
Update shell.nix
sbernauer add657f
revert bump
sbernauer 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import os | ||
| import subprocess | ||
| import yaml | ||
| from typing import Tuple, Set | ||
|
|
||
|
|
||
| def run_helm_repo_add(repo_name: str, repo_url: str) -> None: | ||
| try: | ||
| subprocess.run(["helm", "repo", "add", repo_name, repo_url], check=True) | ||
| except subprocess.CalledProcessError as e: | ||
| if "already exists" in e.stderr.decode() if e.stderr else str(e): | ||
| pass # Ignore "already exists" error | ||
| else: | ||
| raise | ||
|
|
||
|
|
||
| def run_helm_repo_update() -> None: | ||
| subprocess.run(["helm", "repo", "update"], check=True) | ||
|
|
||
|
|
||
| def get_chart_and_app_version(repo_name: str, chart_name: str) -> Tuple[str, str]: | ||
| full_chart = f"{repo_name}/{chart_name}" | ||
| result = subprocess.run( | ||
| ["helm", "show", "chart", full_chart], | ||
| capture_output=True, | ||
| text=True, | ||
| check=True | ||
| ) | ||
| chart_yaml = yaml.safe_load(result.stdout) | ||
| return chart_yaml["version"], chart_yaml["appVersion"] | ||
|
|
||
|
|
||
| def process_yaml_files(top_dir: str) -> None: | ||
| seen_repos: Set[str] = set() | ||
|
|
||
| for root, _, files in os.walk(top_dir): | ||
| for file in files: | ||
| if not file.endswith(".yaml"): | ||
| continue | ||
|
|
||
| filepath = os.path.join(root, file) | ||
|
|
||
| try: | ||
| with open(filepath, "r") as f: | ||
| raw_lines = f.readlines() | ||
|
|
||
| try: | ||
| first_doc = yaml.safe_load("".join(raw_lines)) | ||
| except yaml.YAMLError as e: | ||
| if "expected a single document" in str(e): | ||
| continue # silently skip multi-doc YAMLs | ||
| print(f"⚠️ Skipping invalid YAML: {filepath}") | ||
| continue | ||
|
|
||
| if not isinstance(first_doc, dict): | ||
| continue | ||
|
|
||
| if not ( | ||
| "releaseName" in first_doc | ||
| and "version" in first_doc | ||
| and "repo" in first_doc | ||
| and "name" in first_doc | ||
| ): | ||
| continue | ||
|
|
||
| repo_info = first_doc["repo"] | ||
| chart_name = first_doc["name"] | ||
| repo_name = repo_info.get("name") | ||
| repo_url = repo_info.get("url") | ||
|
|
||
| if not repo_name or not repo_url: | ||
| continue | ||
|
|
||
| if repo_name not in seen_repos: | ||
| run_helm_repo_add(repo_name, repo_url) | ||
| seen_repos.add(repo_name) | ||
|
|
||
| # print(f"📦 Updating {filepath} -> {repo_name}/{chart_name}") | ||
| new_chart_version, new_app_version = get_chart_and_app_version(repo_name, chart_name) | ||
|
|
||
| updated_lines = [] | ||
| for line in raw_lines: | ||
| if line.strip().startswith("version:"): | ||
| new_line = f'version: {new_chart_version} # {new_app_version}\n' | ||
| updated_lines.append(new_line) | ||
| else: | ||
| updated_lines.append(line) | ||
|
|
||
| with open(filepath, "w") as f: | ||
| f.writelines(updated_lines) | ||
|
|
||
| print(f"✅ Updated {filepath}") | ||
|
|
||
| except Exception as e: | ||
| print(f"⚠️ Error processing {filepath}: {e}") | ||
|
|
||
| if __name__ == "__main__": | ||
| print('⚠️⚠️⚠️ This script is best-effort! Always check the result using "git diff"! ⚠️⚠️⚠️') | ||
| print('Notably, it skips invalid YAMLs, which can be the case because we sometimes use templating syntax, even for helm-chart definitions') | ||
| print('Please judge on the skipped files if they contain a helm-chart and should be manually bumped') | ||
| print('The script can be improved to handle such files in the future') | ||
| print() | ||
|
|
||
| process_yaml_files(".") | ||
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.