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 | ||||
from deepmerge import always_merger | |||||
import json | import json | ||||
import os | import os | ||||
from pathlib import Path, PurePath | from pathlib import Path, PurePath | ||||
import signal | import signal | ||||
import subprocess | import subprocess | ||||
import sys | import sys | ||||
from teamcity.messages import TeamcityServiceMessages | from teamcity.messages import TeamcityServiceMessages | ||||
Show All 37 Lines | if not config_path.is_file(): | ||||
str(config_path) | str(config_path) | ||||
) | ) | ||||
) | ) | ||||
# Read the configuration | # Read the configuration | ||||
with open(config_path, encoding="utf-8") as f: | with open(config_path, encoding="utf-8") as f: | ||||
config = json.load(f) | config = json.load(f) | ||||
# The configuration root should contain a mandatory element "builds", and it | |||||
# should not be empty. | |||||
if not config.get("builds", None): | |||||
raise AssertionError( | |||||
"Invalid configuration file {}: the \"builds\" element is missing or empty".format( | |||||
str(config_path) | |||||
) | |||||
) | |||||
# Check the target build has an entry in the configuration file | # Check the target build has an entry in the configuration file | ||||
build = config.get(args.build, None) | build = config["builds"].get(args.build, None) | ||||
if not build: | if not build: | ||||
raise AssertionError( | raise AssertionError( | ||||
"{} is not a valid build identifier. Valid identifiers are {}".format( | "{} is not a valid build identifier. Valid identifiers are {}".format( | ||||
args.build, list(config.keys()) | args.build, list(config.keys()) | ||||
) | ) | ||||
) | ) | ||||
# Get a list of the templates, if any | |||||
templates = config.get("templates", {}) | |||||
# If the build references a template, merge the configurations | |||||
template_name = build.get("template", None) | |||||
if template_name: | |||||
# Raise an error if the template does not exist | |||||
if template_name not in templates: | |||||
raise AssertionError( | |||||
"Build {} configuration inherits from template {}, but the template does not exist.".format( | |||||
args.build, | |||||
template_name | |||||
) | |||||
) | |||||
# The template exists, apply the build configuration on top of the | |||||
# template | |||||
build = always_merger.merge(templates.get(template_name, {}), build) | |||||
# Make sure there is a script file associated with the build... | # Make sure there is a script file associated with the build... | ||||
script = build.get("script", None) | script = build.get("script", None) | ||||
if script is None: | if script is None: | ||||
raise AssertionError( | raise AssertionError( | ||||
"No script provided for the build {}".format( | "No script provided for the build {}".format( | ||||
args.build | args.build | ||||
) | ) | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |