diff options
author | Moustafa Maher Khalil <m.maher@mongodb.com> | 2021-11-05 21:12:54 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-17 15:44:07 +0000 |
commit | c0da0ce5c6d0bd464d842ad0598537aac8b599a5 (patch) | |
tree | 666e184b853dbd9cea615e6cb8b8f250cc022eff | |
parent | 2f41591c75b5ef09e804291f9be9e7fe1c75d4b0 (diff) | |
download | mongo-c0da0ce5c6d0bd464d842ad0598537aac8b599a5.tar.gz |
SERVER-61291 Fix forward compatibility with checkout_idl_files_from_past_releases.py
(cherry picked from commit 110f7f2d791c99851849d0e16beae8acebb721fd)
-rwxr-xr-x | buildscripts/idl/checkout_idl_files_from_past_releases.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/buildscripts/idl/checkout_idl_files_from_past_releases.py b/buildscripts/idl/checkout_idl_files_from_past_releases.py index 91c43c3531d..4d928b0cc0e 100755 --- a/buildscripts/idl/checkout_idl_files_from_past_releases.py +++ b/buildscripts/idl/checkout_idl_files_from_past_releases.py @@ -29,6 +29,7 @@ import argparse import logging import os +import re import shutil from subprocess import check_output from typing import List @@ -40,10 +41,26 @@ LOGGER_NAME = 'checkout-idl' LOGGER = logging.getLogger(LOGGER_NAME) +def get_current_git_version() -> Version: + """Return current git version'. + + If the version is a release like "2.3.4" or "2.3.4-rc0", or a pre-release like + "2.3.4-325-githash" or "2.3.4-pre-" these will return "2.3.4". If the version begins with the + letter 'r', it will also match, e.g. r2.3.4, r2.3.4-rc0, r2.3.4-git234, r2.3.4-rc0-234-githash + If the version is invalid (i.e. doesn't start with "2.3.4" or "2.3.4-rc0", this will return + False. + """ + git_describe = check_output(['git', 'describe']).decode() + git_version = re.match(r'^r?(\d+\.\d+\.\d+)(?:-rc\d+|-alpha\d+)?(?:-.*)?', git_describe) + assert git_version, f"git describe output '{git_describe}' does not match pattern." + return Version(git_version.groups()[0]) + + def get_release_tags() -> List[str]: """Get a list of release git tags since API Version 1 was introduced.""" # Use packaging.version.Version's parsing and comparison logic. min_version = Version(FIRST_API_V1_RELEASE) + max_version = get_current_git_version() def gen_versions_and_tags(): for tag in check_output(['git', 'tag']).decode().split(): @@ -61,7 +78,7 @@ def get_release_tags() -> List[str]: # gen_versions_and_tags yields pairs (version, tag). Sort them by version using # packaging.version.Version's comparison rules. for version, tag in sorted(gen_versions_and_tags()): - if version < min_version: + if version < min_version or version > max_version: continue # Skip alphas, betas, etc. |