diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
| commit | 294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch) | |
| tree | 279b1e0bab53901a1647ac63c1c724f0f789a663 /buildscripts/generate_version_expansions.py | |
| parent | 70be7c27a251621187a1de533462ae2bb1e3bd39 (diff) | |
| parent | 1e917fd798aa25b7066d4b414b51184f13d5a092 (diff) | |
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10'
with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'buildscripts/generate_version_expansions.py')
| -rwxr-xr-x | buildscripts/generate_version_expansions.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/buildscripts/generate_version_expansions.py b/buildscripts/generate_version_expansions.py new file mode 100755 index 00000000000..4b0f9ccc0a8 --- /dev/null +++ b/buildscripts/generate_version_expansions.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 +""" +Generate the version expansions file used by Evergreen as part of the push/release process. + +Invoke by specifying an output file. +$ python generate_build_expansions.py --out version_expansions.yml +""" + +import argparse +import json +import os +import re +import sys +import yaml + +VERSION_JSON = "version.json" + + +def generate_expansions(): + """Entry point for the script. + + This calls functions to generate version and scons cache expansions and + writes them to a file. + """ + args = parse_args() + expansions = {} + expansions.update(generate_version_expansions()) + + with open(args.out, "w") as out: + print("saving compile expansions to {0}: ({1})".format(args.out, expansions)) + yaml.safe_dump(expansions, out, default_flow_style=False) + + +def parse_args(): + """Parse program arguments.""" + parser = argparse.ArgumentParser() + parser.add_argument("--out", required=True) + return parser.parse_args() + + +def generate_version_expansions(): + """Generate expansions from a version.json file if given, or $MONGO_VERSION.""" + expansions = {} + + if os.path.exists(VERSION_JSON): + with open(VERSION_JSON, "r") as fh: + data = fh.read() + version_data = json.loads(data) + version_line = version_data['version'] + version_parts = match_verstr(version_line) + if not version_parts: + raise ValueError("Unable to parse version.json") + else: + version_line = os.getenv("MONGO_VERSION") + if not version_line: + raise Exception("$MONGO_VERSION not set and no version.json provided") + + version_line = version_line.lstrip("r") + version_parts = match_verstr(version_line) + if not version_parts: + raise ValueError("Unable to parse version from stdin and no version.json provided") + + if version_parts[0]: + expansions["suffix"] = "v6.0-latest" + expansions["src_suffix"] = "v6.0-latest" + expansions["is_release"] = "false" + else: + expansions["suffix"] = version_line + expansions["src_suffix"] = "r{0}".format(version_line) + expansions["is_release"] = "true" + expansions["version"] = version_line + + return expansions + + +def match_verstr(verstr): + """Match a version string and capture the "extra" part. + + If the version is a release like "2.3.4" or "2.3.4-rc0", this will return + None. If the version is a pre-release like "2.3.4-325-githash" or + "2.3.4-pre-", this will return "-pre-" or "-325-githash" 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. + """ + res = re.match(r'^r?(?:\d+\.\d+\.\d+(?:-rc\d+|-alpha\d+)?)(-.*)?', verstr) + if not res: + return False + return res.groups() + + +if __name__ == "__main__": + generate_expansions() |
