2021-03-10 16:08:04 +00:00
|
|
|
"""
|
|
|
|
script to build the peach-config debian module and add it to the freight repository
|
|
|
|
"""
|
|
|
|
import argparse
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2021-03-16 12:04:55 +00:00
|
|
|
import re
|
2021-03-10 16:08:04 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from peach_package_builder.constants import *
|
|
|
|
from peach_package_builder.utils import add_deb_to_freight, update_freight_cache
|
|
|
|
|
|
|
|
|
2021-03-16 12:04:55 +00:00
|
|
|
def get_version_from_setup_file(file_path):
|
|
|
|
with open(file_path, 'r') as f:
|
|
|
|
lines = f.read().splitlines()
|
|
|
|
for line in lines:
|
|
|
|
match = re.match('.*version = "(\S+)",', line)
|
|
|
|
if match:
|
|
|
|
version = match.group(1)
|
|
|
|
return version
|
|
|
|
# if a version wasn't found then raise an exception
|
|
|
|
raise Exception("version not found")
|
|
|
|
|
|
|
|
|
2021-03-10 16:08:04 +00:00
|
|
|
def build_peach_config(default_branch=True):
|
|
|
|
service_path = os.path.join(MICROSERVICES_SRC_DIR, "peach-config")
|
|
|
|
if default_branch:
|
|
|
|
# because some repo have main as default and some as master, we get the default
|
|
|
|
default_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'origin/HEAD'],
|
2021-04-13 09:19:09 +00:00
|
|
|
cwd=service_path).decode(sys.stdout.encoding).strip()
|
|
|
|
branch = default_branch.replace('origin/', '')
|
2021-03-10 16:08:04 +00:00
|
|
|
subprocess.check_call(["git", "checkout", branch], cwd=service_path)
|
2021-03-22 10:39:15 +00:00
|
|
|
subprocess.check_call(["git", "fetch", "--all"], cwd=service_path)
|
|
|
|
subprocess.check_call(["git", "reset", "--hard", default_branch], cwd=service_path)
|
2021-03-11 09:41:20 +00:00
|
|
|
# remove old build dir
|
|
|
|
subprocess.check_call([
|
|
|
|
"rm",
|
|
|
|
"-rf",
|
|
|
|
os.path.join(service_path, 'deb_dist')
|
|
|
|
])
|
2021-03-10 16:08:04 +00:00
|
|
|
# build .deb
|
|
|
|
subprocess.check_call([
|
|
|
|
"python3",
|
|
|
|
"setup.py",
|
|
|
|
"--command-packages=stdeb.command",
|
|
|
|
"bdist_deb"
|
|
|
|
],
|
|
|
|
cwd=service_path)
|
2021-03-16 12:04:55 +00:00
|
|
|
# get version number of peach-config from setup.py file
|
|
|
|
setup_file = os.path.join(service_path, 'setup.py')
|
|
|
|
version = get_version_from_setup_file(setup_file)
|
|
|
|
# build the deb
|
2021-03-10 16:08:04 +00:00
|
|
|
deb_name = "python3-peach-config_{version}-1_all.deb".format(version=version)
|
|
|
|
debian_package_path = os.path.join(
|
|
|
|
service_path,
|
|
|
|
"deb_dist/{}".format(deb_name)
|
|
|
|
)
|
|
|
|
subprocess.check_call(["cp", debian_package_path, MICROSERVICES_DEB_DIR])
|
|
|
|
add_deb_to_freight(package_name=debian_package_path, package_path=debian_package_path)
|
|
|
|
update_freight_cache()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"-d",
|
|
|
|
"--default",
|
|
|
|
help="Ensure default branch for all repos for build",
|
|
|
|
action="store_true"
|
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
build_peach_config(default_branch=args.default)
|