Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>/` 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/<name>/` 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

Expand Down
18 changes: 17 additions & 1 deletion scripts/generate_helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_generate_helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading