File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import subprocess
77from pathlib import Path
88from typing import Optional
9+ import xml .etree .ElementTree as ET
910
1011
1112DEFAULT_MICROMETER_DIR = Path (
1920DEFAULT_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
2526def 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+
4762def 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 {{
You can’t perform that action at this time.
0 commit comments