Files
static-musl-builds/scripts/sync_iperf3_version.py
T
Hermes Agent 257889f1e2
iperf3 static musl build / build-and-release (push) Failing after 16s
feat: bootstrap static musl build pipeline for iperf3
2026-05-07 22:12:23 +00:00

55 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import json
import re
import sys
import urllib.request
from pathlib import Path
VERSION_FILE = Path("versions/iperf3.version")
LATEST_RELEASE_URL = "https://api.github.com/repos/esnet/iperf/releases/latest"
def fetch_latest_version() -> str:
req = urllib.request.Request(
LATEST_RELEASE_URL,
headers={
"Accept": "application/vnd.github+json",
"User-Agent": "static-musl-builds-updater",
},
)
with urllib.request.urlopen(req, timeout=30) as resp:
data = json.load(resp)
tag = data["tag_name"].strip()
version = re.sub(r"^v", "", tag)
if not re.fullmatch(r"[0-9]+(?:\.[0-9]+)*", version):
raise ValueError(f"Unexpected iperf3 version format: {version!r}")
return version
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--update-file", action="store_true", help="Write latest version into versions/iperf3.version if changed")
args = parser.parse_args()
latest = fetch_latest_version()
current = VERSION_FILE.read_text(encoding="utf-8").strip() if VERSION_FILE.exists() else ""
print(f"current={current or '<missing>'}")
print(f"latest={latest}")
if current == latest:
print("status=up-to-date")
return 0
print("status=update-available")
if args.update_file:
VERSION_FILE.parent.mkdir(parents=True, exist_ok=True)
VERSION_FILE.write_text(latest + "\n", encoding="utf-8")
print(f"updated_file={VERSION_FILE}")
return 0
if __name__ == "__main__":
sys.exit(main())