Skip to content

Commit 5bbab90

Browse files
committed
fix: derive micrometer test version from pom
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 7fbed80 commit 5bbab90

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

.mise/lib/micrometer_compat.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
from pathlib import Path
88
from typing import Optional
9+
import xml.etree.ElementTree as ET
910

1011

1112
DEFAULT_MICROMETER_DIR = Path(
@@ -19,7 +20,7 @@
1920
DEFAULT_INIT_SCRIPT = Path(
2021
os.environ.get("MICROMETER_INIT_SCRIPT", "/tmp/micrometer-prom-local.init.gradle")
2122
)
22-
DEFAULT_PROM_VERSION = os.environ.get("PROM_VERSION", "1.6.1")
23+
DEFAULT_PROM_VERSION = os.environ.get("PROM_VERSION")
2324

2425

2526
def run_cmd(cmd: list[str], cwd: Optional[Path] = None) -> None:
@@ -44,9 +45,25 @@ def check_clean_worktree(micrometer_dir: Path) -> None:
4445
)
4546

4647

48+
def get_prom_version(root_dir: Path = Path.cwd()) -> str:
49+
configured_version = DEFAULT_PROM_VERSION
50+
if configured_version:
51+
return configured_version
52+
pom = ET.parse(root_dir / "pom.xml")
53+
root = pom.getroot()
54+
version = root.findtext("./{*}version")
55+
if not version:
56+
version = root.findtext("./{*}parent/{*}version")
57+
if not version:
58+
raise RuntimeError("could not determine Prometheus version from pom.xml")
59+
return version
60+
61+
4762
def write_init_script(
48-
init_script: Path = DEFAULT_INIT_SCRIPT, prom_version: str = DEFAULT_PROM_VERSION
63+
init_script: Path = DEFAULT_INIT_SCRIPT, prom_version: Optional[str] = None
4964
) -> None:
65+
if prom_version is None:
66+
prom_version = get_prom_version()
5067
init_script.write_text(
5168
f"""allprojects {{
5269
repositories {{

0 commit comments

Comments
 (0)