|
39 | 39 |
|
40 | 40 | NAMESPACE = Namespace.DEV |
41 | 41 |
|
| 42 | +VERSION_PATTERN_DOCKER = ( |
| 43 | + r"\$\{INFRAHUB_DOCKER_IMAGE:-registry\.opsmill\.io/opsmill/infrahub\}:\$\{VERSION:-[\d\.\-a-zA-Z]+\}" |
| 44 | +) |
| 45 | +VERSION_PATTERN_HELM = r'^appVersion:\s*("?)([\d\.\-a-zA-Z]+)\1$' |
| 46 | + |
42 | 47 |
|
43 | 48 | @task(optional=["database"]) |
44 | 49 | def build( |
@@ -194,34 +199,39 @@ def get_version_from_pyproject() -> str: |
194 | 199 | def update_helm_chart(context: Context, chart_file: str | None = "helm/Chart.yaml") -> None: |
195 | 200 | """Update helm/Chart.yaml with the current version from pyproject.toml.""" |
196 | 201 | version = get_version_from_pyproject() |
197 | | - version_pattern = r"^appVersion:\s*[\d\.\-a-zA-Z]+" |
| 202 | + version_pattern = VERSION_PATTERN_HELM |
198 | 203 |
|
199 | | - def replace_version(match: str) -> str: |
200 | | - return f"appVersion: {version}" |
| 204 | + def replace_version(match: re.Match) -> str: |
| 205 | + return f'appVersion: "{version}"' |
201 | 206 |
|
202 | 207 | chart_path = Path(chart_file) |
203 | 208 | chart_yaml = chart_path.read_text(encoding="utf-8") |
| 209 | + updated_chart_yaml, count = re.subn(version_pattern, replace_version, chart_yaml, flags=re.MULTILINE) |
204 | 210 |
|
205 | | - updated_chart_yaml = re.sub(version_pattern, replace_version, chart_yaml, flags=re.MULTILINE) |
206 | | - chart_path.write_text(updated_chart_yaml, encoding="utf-8") |
| 211 | + if count == 0: |
| 212 | + raise ValueError(f"Pattern not found in {chart_file}; no updates made.") |
207 | 213 |
|
| 214 | + chart_path.write_text(updated_chart_yaml, encoding="utf-8") |
208 | 215 | print(f"{chart_file} updated with appVersion {version}") |
209 | 216 |
|
210 | 217 |
|
211 | 218 | @task |
212 | 219 | def update_docker_compose(context: Context, docker_file: str | None = "docker-compose.yml") -> None: |
213 | 220 | """Update docker-compose.yml with the current version from pyproject.toml.""" |
214 | 221 | version = get_version_from_pyproject() |
215 | | - version_pattern = r"registry.opsmill.io/opsmill/infrahub:\$\{VERSION:-[\d\.\-a-zA-Z]+\}" |
| 222 | + version_pattern = VERSION_PATTERN_DOCKER |
216 | 223 |
|
217 | 224 | def replace_version(match: str) -> str: |
218 | | - return f"registry.opsmill.io/opsmill/infrahub:${{VERSION:-{version}}}" |
| 225 | + return f"${{INFRAHUB_DOCKER_IMAGE:-registry.opsmill.io/opsmill/infrahub}}:${{VERSION:-{version}}}" |
219 | 226 |
|
220 | 227 | docker_path = Path(docker_file) |
221 | 228 | docker_compose = docker_path.read_text(encoding="utf-8") |
222 | | - updated_docker_compose = re.sub(version_pattern, replace_version, docker_compose) |
223 | | - docker_path.write_text(updated_docker_compose, encoding="utf-8") |
| 229 | + updated_docker_compose, count = re.subn(version_pattern, replace_version, docker_compose) |
224 | 230 |
|
| 231 | + if count == 0: |
| 232 | + raise ValueError(f"Pattern not found in {docker_file}; no updates made.") |
| 233 | + |
| 234 | + docker_path.write_text(updated_docker_compose, encoding="utf-8") |
225 | 235 | print(f"{docker_file} updated with version {version}") |
226 | 236 |
|
227 | 237 |
|
|
0 commit comments