From ab9ab61587447a5ef906406c2789d8f157aec2ea Mon Sep 17 00:00:00 2001 From: Christian Geller Date: Wed, 25 Nov 2026 13:47:33 +0100 Subject: [PATCH] accept newer openadservice dependency in helm check --- README.md | 2 +- scripts/generate_helm.py | 18 +++++++++++++++++- tests/test_generate_helm.py | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fda2559..667696b 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ Use [`generate_helm.py`](scripts/generate_helm.py) to generate `helm/Chart.yaml` .openads-dev-environment/scripts/generate_helm.py --check ``` -A single launch deployment keeps the existing `deployment/helm/Chart.yaml` and `deployment/helm/values.yaml` paths, chart name, and version. Multiple directly launching files generate one chart below `deployment/helm//` per launch file. All charts use the same package-derived chart name and therefore share one OCI repository. Multi-launch chart versions append the launch name with underscores converted to hyphens, for example `1.0.0-first-node`; branch builds append the Git ref afterwards. The Helm OCI workflows discover, package, publish, and clean up all generated charts. +A single launch deployment keeps the existing `deployment/helm/Chart.yaml` and `deployment/helm/values.yaml` paths, chart name, and version. Multiple directly launching files generate one chart below `deployment/helm//` per launch file. All charts use the same package-derived chart name and therefore share one OCI repository. Multi-launch chart versions append the launch name with underscores converted to hyphens, for example `1.0.0-first-node`; branch builds append the Git ref afterwards. The Helm OCI workflows discover, package, publish, and clean up all generated charts. Generation pins the `openadservice` dependency to the template version, while `--check` also accepts a newer version in the repository. ### Consistency Checker diff --git a/scripts/generate_helm.py b/scripts/generate_helm.py index 88af6dd..5ee5882 100755 --- a/scripts/generate_helm.py +++ b/scripts/generate_helm.py @@ -44,6 +44,22 @@ HELM_DIR = Path("deployment/helm") CHART_PATH = HELM_DIR / "Chart.yaml" VALUES_PATH = HELM_DIR / "values.yaml" +DEPENDENCY_VERSION_PATTERN = re.compile(r"^(\s+name: openadservice\n\s+version:[ \t]*)(\d+(?:\.\d+)*)[ \t]*$", re.MULTILINE) + + +def accept_newer_dependency_version(current: str, expected: str) -> str: + """Treat a newer openadservice dependency version in the repository as up to date.""" + current_match = DEPENDENCY_VERSION_PATTERN.search(current) + expected_match = DEPENDENCY_VERSION_PATTERN.search(expected) + if current_match is None or expected_match is None: + return current + + def version_key(version: str) -> tuple[int, ...]: + return tuple(int(part) for part in version.split(".")) + + if version_key(current_match.group(2)) < version_key(expected_match.group(2)): + return current + return DEPENDENCY_VERSION_PATTERN.sub(rf"\g<1>{expected_match.group(2)}", current, count=1) def extract_readme_tagline(readme_path: Path) -> str | None: @@ -230,7 +246,7 @@ def main() -> int: for relative_path, expected in sorted(expected_files.items()): output_path = repo_root / relative_path current = output_path.read_text(encoding="utf-8") if output_path.exists() else "" - if current == expected: + if accept_newer_dependency_version(current, expected) == expected: continue stale = True diff = build_diff(expected, current, output_path, repo_root) diff --git a/tests/test_generate_helm.py b/tests/test_generate_helm.py index bfa804b..c328a66 100644 --- a/tests/test_generate_helm.py +++ b/tests/test_generate_helm.py @@ -175,6 +175,28 @@ def test_generate_helm_check_reports_stale_file_without_rewriting(tmp_path: Path assert values_path.read_text(encoding="utf-8") == "stale\n" +def test_generate_helm_check_accepts_newer_dependency_version(tmp_path: Path) -> None: + repo_root = prepare_repository(FIXTURES_DIR / "sample_pkg", tmp_path) + result = run_generator(repo_root) + assert result.returncode == 0, result.stderr + + chart_path = repo_root / CHART_PATH + generated_chart = chart_path.read_text(encoding="utf-8") + assert " version: 1.2.0\n" in generated_chart + + chart_path.write_text(generated_chart.replace(" version: 1.2.0\n", " version: 1.3.0\n"), encoding="utf-8") + assert run_generator(repo_root, "--check").returncode == 0 + + chart_path.write_text(generated_chart.replace(" version: 1.2.0\n", " version: 1.1.0\n"), encoding="utf-8") + check_result = run_generator(repo_root, "--check") + assert check_result.returncode == 1 + assert "helm/Chart.yaml" in check_result.stdout + + chart_path.write_text(generated_chart.replace(" version: 1.2.0\n", " version: 1.3.0\n"), encoding="utf-8") + assert run_generator(repo_root).returncode == 0 + assert chart_path.read_text(encoding="utf-8") == generated_chart + + def test_generate_helm_reports_and_removes_obsolete_managed_chart(tmp_path: Path) -> None: repo_root = prepare_repository(MULTI_LAUNCH_FIXTURE, tmp_path) result = run_generator(repo_root)