diff --git a/.openshift-ci/get_latest_release_versions.py b/.openshift-ci/get_latest_release_versions.py new file mode 100755 index 0000000000000..91c74b1ab504e --- /dev/null +++ b/.openshift-ci/get_latest_release_versions.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +""" +Returns the latest patches of the last n major versions +""" + +import sys +import re +import subprocess +from collections import defaultdict + +def is_release_tag(version): + return re.search(r"^\d+\.\d+\.\d+$", version) is not None + +def filter_tags(rawtags): + return set([t for t in rawtags if is_release_tag(t)]) + +def reduce_tags_to_latest_patch(tags): + top_patch_version = defaultdict(int) + for t in tags: + [major, minor, patch] = t.split('.') + k = '.'.join([major, minor]) + top_patch_version[k] = max(top_patch_version[k], int(patch)) + top_major_versions = sorted(list(top_patch_version.keys()), reverse=True) + return [t + '.' + str(top_patch_version[t]) for t in top_major_versions] + +def make_image_tag(): + return subprocess.check_output(["make", "--quiet", "--no-print-directory", "tag"]).decode(encoding="utf-8") + +def extract_x_y_from_main_image_tag(tag): + x_y = re.search(r"^(\d+)\.(\d+)", tag) + return int(x_y.group(1)), int(x_y.group(2)) + +def get_latest_n_tags(tags, num_versions): + central_major, central_minor = extract_x_y_from_main_image_tag(make_image_tag()) + tags_older_than_central = [t for t in tags if (int(t.split('.')[0]) < central_major or (int(t.split('.')[0]) == central_major and int(t.split('.')[1]) <= central_minor))] + return tags_older_than_central[:num_versions] + +# get_latest_release_versions gets the latest patches of the last num_versions major versions via Git CLI +def get_latest_release_versions(num_versions): + rawtags = subprocess.check_output(["git", "tag", "--list"]).decode(encoding="utf-8").splitlines() + tags = filter_tags(rawtags) + latest_patch_tags = reduce_tags_to_latest_patch(tags) + return get_latest_n_tags(latest_patch_tags, num_versions) + +def main(argv): + n = int(argv[1]) if len(argv)>1 else 4 + latestversions = get_latest_release_versions(n) + print(f"Last {n} versions:") + print("\n".join(latestversions)) + +if (__name__ == "__main__"): + main(sys.argv) diff --git a/scripts/ci/jobs/gke_version_compatibility_tests.py b/scripts/ci/jobs/gke_version_compatibility_tests.py index 523b739496406..5fd110e350f07 100755 --- a/scripts/ci/jobs/gke_version_compatibility_tests.py +++ b/scripts/ci/jobs/gke_version_compatibility_tests.py @@ -4,6 +4,7 @@ Run version compatibility tests """ import os +from get_latest_release_versions import get_latest_release_versions from compatibility_test import make_compatibility_test_runner from clusters import GKECluster @@ -13,12 +14,10 @@ # don't use postgres os.environ["ROX_POSTGRES_DATASTORE"] = "false" -versions=["3.71.0", "3.70.0", "3.69.0"] +versions=get_latest_release_versions(4) gkecluster=GKECluster("qa-e2e-test") for version in versions: os.environ["SENSOR_IMAGE_TAG"] = version make_compatibility_test_runner(cluster=gkecluster).run() - -print("stub for version compatibility tests")