|
| 1 | +import json |
| 2 | +import re |
| 3 | +from collections import defaultdict |
| 4 | +from packaging.version import Version |
| 5 | +from xml.etree import ElementTree as ET |
| 6 | +import urllib.request |
| 7 | + |
| 8 | +# Configuration |
| 9 | +managed_minors = {"3.0", "3.1", "3.2", "3.3", "3.4"} |
| 10 | +boot_java_compatibility = { |
| 11 | + "3.0": ["17"], # Java 21 not supported |
| 12 | + "3.1": ["17", "21"], |
| 13 | + "3.2": ["17", "21"], |
| 14 | + "3.3": ["17", "21"], |
| 15 | + "3.4": ["17", "21"] |
| 16 | +} |
| 17 | +output_path = ".github/spring-versions.json" |
| 18 | + |
| 19 | +# Step 1: Fetch Spring Boot versions |
| 20 | +metadata_url = "https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter/maven-metadata.xml" |
| 21 | +with urllib.request.urlopen(metadata_url) as response: |
| 22 | + xml_data = response.read() |
| 23 | + |
| 24 | +root = ET.fromstring(xml_data) |
| 25 | +versions = [v.text for v in root.findall(".//version")] |
| 26 | + |
| 27 | +boot_versions = defaultdict(list) |
| 28 | +for v in versions: |
| 29 | + if not re.match(r"^\d+\.\d+\.\d+$", v): |
| 30 | + continue |
| 31 | + minor = ".".join(v.split(".")[:2]) |
| 32 | + if minor in managed_minors: |
| 33 | + boot_versions[minor].append(Version(v)) |
| 34 | + |
| 35 | +latest_boot_versions = {minor: str(max(vlist)) for minor, vlist in boot_versions.items()} |
| 36 | + |
| 37 | +# Step 2: Resolve Spring Framework version |
| 38 | +def get_spring_framework_version(boot_version: str) -> str: |
| 39 | + pom_url = f"https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter/{boot_version}/spring-boot-starter-{boot_version}.pom" |
| 40 | + try: |
| 41 | + with urllib.request.urlopen(pom_url) as response: |
| 42 | + pom_data = response.read() |
| 43 | + pom_root = ET.fromstring(pom_data) |
| 44 | + ns = {'m': 'http://maven.apache.org/POM/4.0.0'} |
| 45 | + for dep in pom_root.findall(".//m:dependency", ns): |
| 46 | + gid = dep.find("m:groupId", ns) |
| 47 | + aid = dep.find("m:artifactId", ns) |
| 48 | + ver = dep.find("m:version", ns) |
| 49 | + if gid is not None and aid is not None and ver is not None: |
| 50 | + if gid.text == "org.springframework" and aid.text == "spring-core": |
| 51 | + return ver.text |
| 52 | + except Exception as e: |
| 53 | + print(f"Warning: Failed to fetch framework version for {boot_version}: {e}") |
| 54 | + return "unknown" |
| 55 | + |
| 56 | +# Step 3: Build matrix |
| 57 | +matrix_entries = [] |
| 58 | +for minor, boot_version in sorted(latest_boot_versions.items()): |
| 59 | + framework_version = get_spring_framework_version(boot_version) |
| 60 | + for java_version in boot_java_compatibility.get(minor, []): |
| 61 | + matrix_entries.append({ |
| 62 | + "boot": boot_version, |
| 63 | + "framework": framework_version, |
| 64 | + "java": str(java_version) |
| 65 | + }) |
| 66 | + |
| 67 | +# Step 4: Save result |
| 68 | +with open(output_path, "w") as f: |
| 69 | + json.dump({"matrix": matrix_entries}, f, indent=2) |
| 70 | + |
| 71 | +print(f"Updated {output_path} with {len(matrix_entries)} matrix entries.") |
0 commit comments