2024-02-28 17:22:13 +00:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import re
|
|
|
|
from collections import defaultdict
|
|
|
|
from typing import List, Tuple, Dict
|
|
|
|
|
|
|
|
OUTPUT = "version_matrix"
|
|
|
|
|
|
|
|
|
|
|
|
def parse_version(version_str: str) -> Tuple[int, int, int]:
|
|
|
|
match = re.match(r"(\d+)\.(\d+)\.(\d+)", version_str)
|
|
|
|
if match:
|
|
|
|
return tuple(map(int, match.groups()))
|
|
|
|
else:
|
|
|
|
raise ValueError("Invalid version format: " + version_str)
|
|
|
|
|
|
|
|
|
|
|
|
def get_latest_versions(versions: List[str]) -> List[Dict[str, any]]:
|
|
|
|
latest_major = defaultdict(lambda: (0, 0, 0))
|
|
|
|
latest_minor = defaultdict(lambda: (0, 0, 0))
|
|
|
|
|
|
|
|
for version in versions:
|
|
|
|
major, minor, patch = parse_version(version)
|
|
|
|
if (major, minor, patch) > latest_major[major]:
|
|
|
|
latest_major[major] = (major, minor, patch)
|
|
|
|
if (major, minor, patch) > latest_minor[(major, minor)]:
|
|
|
|
latest_minor[(major, minor)] = (major, minor, patch)
|
|
|
|
|
|
|
|
latest_overall = max(versions)
|
|
|
|
|
|
|
|
version_objects = []
|
|
|
|
for version in versions:
|
|
|
|
major, minor, patch = parse_version(version)
|
|
|
|
is_latest = version == latest_overall
|
|
|
|
is_latest_major = (major, minor, patch) == latest_major[major]
|
|
|
|
is_latest_minor = (major, minor, patch) == latest_minor[(major, minor)]
|
|
|
|
|
|
|
|
version_obj = {
|
|
|
|
"version": version,
|
|
|
|
"is_latest": is_latest,
|
|
|
|
"is_latest_major": is_latest_major,
|
2024-02-28 19:41:47 +00:00
|
|
|
"major_version": f"{major}",
|
2024-02-28 17:22:13 +00:00
|
|
|
"is_latest_minor": is_latest_minor,
|
2024-02-28 19:41:47 +00:00
|
|
|
"minor_version": f"{major}.{minor}",
|
2024-02-28 17:22:13 +00:00
|
|
|
}
|
|
|
|
version_objects.append(version_obj)
|
|
|
|
|
|
|
|
return version_objects
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
all_versions_str = os.environ.get("VERSION_LIST", "")
|
2024-02-28 18:01:46 +00:00
|
|
|
all_versions_list = [
|
|
|
|
version.strip() for version in all_versions_str.split(",") if version.strip()
|
|
|
|
]
|
2024-02-28 17:22:13 +00:00
|
|
|
|
2024-02-28 18:01:46 +00:00
|
|
|
version_objects = get_latest_versions(all_versions_list)
|
2024-02-28 17:22:13 +00:00
|
|
|
|
2024-02-28 18:33:26 +00:00
|
|
|
value = json.dumps(version_objects, separators=(",", ":"))
|
2024-02-28 17:22:13 +00:00
|
|
|
|
2024-02-28 22:14:50 +00:00
|
|
|
print(f"Computed values: {value}")
|
|
|
|
|
2024-02-28 17:22:13 +00:00
|
|
|
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
|
2024-02-28 18:08:22 +00:00
|
|
|
print(f"{OUTPUT}={value}", file=fh)
|
2024-02-28 17:22:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|