|
| 1 | +import argparse |
| 2 | +import json |
| 3 | +import os |
| 4 | +import configparser |
| 5 | + |
| 6 | +# Name of the remote |
| 7 | +ORIGIN = 'origin' |
| 8 | + |
| 9 | +script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 10 | +grandparent_dir = os.path.dirname(os.path.dirname(script_dir)) |
| 11 | + |
| 12 | +config = configparser.ConfigParser() |
| 13 | +with open(os.path.join(grandparent_dir, 'releases.ini')) as stream: |
| 14 | + config.read_string('[default]\n' + stream.read()) |
| 15 | + |
| 16 | +OLDEST_SUPPORTED_MAJOR_VERSION = int(config['default']['OLDEST_SUPPORTED_MAJOR_VERSION']) |
| 17 | + |
| 18 | +def main(): |
| 19 | + |
| 20 | + parser = argparse.ArgumentParser() |
| 21 | + parser.add_argument("--major-version", required=True, type=str, help="The major version of the release") |
| 22 | + parser.add_argument("--latest-tag", required=True, type=str, help="The most recent tag published to the repository") |
| 23 | + args = parser.parse_args() |
| 24 | + |
| 25 | + major_version = args.major_version |
| 26 | + latest_tag = args.latest_tag |
| 27 | + |
| 28 | + print("major_version: " + major_version) |
| 29 | + print("latest_tag: " + latest_tag) |
| 30 | + |
| 31 | + # If this is a primary release, we backport to all supported branches, |
| 32 | + # so we check whether the major_version taken from the package.json |
| 33 | + # is greater than or equal to the latest tag pulled from the repo. |
| 34 | + # For example... |
| 35 | + # 'v1' >= 'v2' is False # we're operating from an older release branch and should not backport |
| 36 | + # 'v2' >= 'v2' is True # the normal case where we're updating the current version |
| 37 | + # 'v3' >= 'v2' is True # in this case we are making the first release of a new major version |
| 38 | + consider_backports = ( major_version >= latest_tag.split(".")[0] ) |
| 39 | + |
| 40 | + with open(os.environ["GITHUB_OUTPUT"], "a") as f: |
| 41 | + |
| 42 | + f.write(f"backport_source_branch=releases/{major_version}\n") |
| 43 | + |
| 44 | + backport_target_branches = [] |
| 45 | + |
| 46 | + if consider_backports: |
| 47 | + for i in range(int(major_version.strip("v"))-1, 0, -1): |
| 48 | + branch_name = f"releases/v{i}" |
| 49 | + if i >= OLDEST_SUPPORTED_MAJOR_VERSION: |
| 50 | + backport_target_branches.append(branch_name) |
| 51 | + |
| 52 | + f.write("backport_target_branches="+json.dumps(backport_target_branches)+"\n") |
| 53 | + |
| 54 | +if __name__ == "__main__": |
| 55 | + main() |
0 commit comments