diff --git a/.github/scripts/gradle_to_chart.py b/.github/scripts/gradle_to_chart.py index 4d7a667fe97..c8944f6d620 100644 --- a/.github/scripts/gradle_to_chart.py +++ b/.github/scripts/gradle_to_chart.py @@ -8,17 +8,20 @@ def get_chart_version(path): """ - Reads the appVersion from Chart.yaml. + Reads the version and the appVersion from Chart.yaml. Args: path (str): The file path to the Chart.yaml. Returns: - str: The appVersion if found, otherwise an empty string. + dict: The version under "chart" key and the appVersion under "app" key. """ with open(path, encoding="utf-8") as file: chart_yaml = yaml.safe_load(file) - return chart_yaml.get("appVersion", "") + return { + "chart": chart_yaml["version"], + "app": chart_yaml["appVersion"] + } def get_gradle_version(path): @@ -39,17 +42,46 @@ def get_gradle_version(path): return "" -def update_chart_version(path, new_version): +def get_new_chart_version(chart_version, old_app_version, new_app_version): + """ + Get the new chart version from + + Args: + str: The current chart version. + str: The current app version. + str: The new app version. + + Returns: + str: The new chart version to update to. + """ + chart_major, chart_minor, chart_patch = chart_version.split(".") + + old_major, old_minor, old_patch = old_app_version.split(".") + new_major, new_minor, new_patch = new_app_version.split(".") + + if old_major != new_major: + new_chart_version = f"{int(chart_major)+1}.0.0" + elif old_minor != new_minor: + new_chart_version = f"{chart_major}.{int(chart_minor)+1}.0" + elif old_patch != new_patch: + new_chart_version = f"{chart_major}.{chart_minor}.{int(chart_patch)+1}" + + return new_chart_version + + +def update_chart_version(path, new_chart_version, new_app_version): """ - Updates the appVersion in Chart.yaml with a new version. + Updates the version and the appVersion in Chart.yaml with a new version. Args: path (str): The file path to the Chart.yaml. - new_version (str): The new version to update to. + new_chart_version (str): The new chart version to update to. + new_app_version (str): The new app version to update to. """ with open(path, encoding="utf-8") as file: chart_yaml = yaml.safe_load(file) - chart_yaml["appVersion"] = new_version + chart_yaml["version"] = new_chart_version + chart_yaml["appVersion"] = new_app_version with open(path, "w", encoding="utf-8") as file: yaml.safe_dump(chart_yaml, file) @@ -58,10 +90,11 @@ def update_chart_version(path, new_version): chart_version = get_chart_version(chart_yaml_path) gradle_version = get_gradle_version(gradle_path) -if chart_version != gradle_version: +if chart_version["app"] != gradle_version: + new_chart_version = get_new_chart_version(chart_version["chart"], chart_version["app"], gradle_version, ) print( - f"Versions do not match. Updating Chart.yaml from {chart_version} to {gradle_version}." + f"Versions do not match. Updating Chart.yaml from {chart_version['chart']} to {new_chart_version}." ) - update_chart_version(chart_yaml_path, gradle_version) + update_chart_version(chart_yaml_path, new_chart_version, gradle_version) else: print("Versions match. No update required.") diff --git a/chart/stirling-pdf/Chart.yaml b/chart/stirling-pdf/Chart.yaml index 01ad871a1f6..2f916695b31 100644 --- a/chart/stirling-pdf/Chart.yaml +++ b/chart/stirling-pdf/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 -appVersion: 0.30.1 +appVersion: 0.1.1 description: locally hosted web application that allows you to perform various operations on PDF files home: https://github.com/Stirling-Tools/Stirling-PDF @@ -13,4 +13,4 @@ maintainers: name: stirling-pdf-chart sources: - https://github.com/Stirling-Tools/Stirling-PDF -version: 1.0.0 +version: 3.0.0