Changeset View
Changeset View
Standalone View
Standalone View
contrib/teamcity/build-configurations.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2020 The Bitcoin developers | # Copyright (c) 2020 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
import argparse | import argparse | ||||
import asyncio | import asyncio | ||||
from deepmerge import always_merger | from deepmerge import always_merger | ||||
import json | |||||
import os | import os | ||||
from pathlib import Path, PurePath | from pathlib import Path, PurePath | ||||
import shutil | import shutil | ||||
import subprocess | import subprocess | ||||
import sys | import sys | ||||
from teamcity import is_running_under_teamcity | from teamcity import is_running_under_teamcity | ||||
from teamcity.messages import TeamcityServiceMessages | from teamcity.messages import TeamcityServiceMessages | ||||
import yaml | |||||
# Default timeout value in seconds. Should be overridden by the | # Default timeout value in seconds. Should be overridden by the | ||||
# configuration file. | # configuration file. | ||||
DEFAULT_TIMEOUT = 1 * 60 * 60 | DEFAULT_TIMEOUT = 1 * 60 * 60 | ||||
if sys.version_info < (3, 6): | if sys.version_info < (3, 6): | ||||
raise SystemError("This script requires python >= 3.6") | raise SystemError("This script requires python >= 3.6") | ||||
Show All 30 Lines | def __init__(self, script_root, config_file, build_name=None): | ||||
if build_name is not None: | if build_name is not None: | ||||
self.load(build_name) | self.load(build_name) | ||||
def load(self, build_name): | def load(self, build_name): | ||||
self.name = build_name | self.name = build_name | ||||
# Read the configuration | # Read the configuration | ||||
with open(self.config_file, encoding="utf-8") as f: | with open(self.config_file, encoding="utf-8") as f: | ||||
config = json.load(f) | config = yaml.safe_load(f) | ||||
# The configuration root should contain a mandatory element "builds", and | # The configuration root should contain a mandatory element "builds", and | ||||
# it should not be empty. | # it should not be empty. | ||||
if not config.get("builds", None): | if not config.get("builds", None): | ||||
raise AssertionError( | raise AssertionError( | ||||
"Invalid configuration file {}: the \"builds\" element is missing or empty".format( | "Invalid configuration file {}: the \"builds\" element is missing or empty".format( | ||||
str(self.config_file) | str(self.config_file) | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 362 Lines • ▼ Show 20 Lines | |||||
def main(): | def main(): | ||||
script_dir = PurePath(os.path.realpath(__file__)).parent | script_dir = PurePath(os.path.realpath(__file__)).parent | ||||
# By default search for a configuration file in the same directory as this | # By default search for a configuration file in the same directory as this | ||||
# script. | # script. | ||||
default_config_path = Path( | default_config_path = Path( | ||||
script_dir.joinpath("build-configurations.json") | script_dir.joinpath("build-configurations.yml") | ||||
) | ) | ||||
parser = argparse.ArgumentParser(description="Run a CI build") | parser = argparse.ArgumentParser(description="Run a CI build") | ||||
parser.add_argument( | parser.add_argument( | ||||
"build", | "build", | ||||
help="The name of the build to run" | help="The name of the build to run" | ||||
) | ) | ||||
parser.add_argument( | parser.add_argument( | ||||
Show All 24 Lines |