2020-03-03 09:20:18 +00:00
|
|
|
from subprocess import run
|
2020-03-03 17:30:17 +00:00
|
|
|
from .python_util import filter_none
|
2020-03-03 09:20:18 +00:00
|
|
|
|
2020-03-03 15:34:12 +00:00
|
|
|
|
2020-03-31 17:25:31 +00:00
|
|
|
def create_devops_build_config(stage, project_root_path, module,
|
2020-03-06 15:10:18 +00:00
|
|
|
build_dir_name='target'):
|
2020-03-03 15:34:12 +00:00
|
|
|
return {'stage': stage,
|
|
|
|
'project_root_path': project_root_path,
|
|
|
|
'module': module,
|
2020-03-04 07:51:12 +00:00
|
|
|
'build_dir_name': build_dir_name}
|
2020-03-03 15:34:12 +00:00
|
|
|
|
2020-03-07 14:07:14 +00:00
|
|
|
def get_devops_build(project):
|
|
|
|
return project.get_property('devops_build')
|
2020-03-06 15:10:18 +00:00
|
|
|
|
2021-06-25 08:12:43 +00:00
|
|
|
def get_tag_from_latest_commit():
|
|
|
|
return run('git describe --abbrev=0 --tags', shell=True, capture_output=True).stdout.decode('UTF-8').rstrip()
|
|
|
|
|
2020-03-03 09:20:18 +00:00
|
|
|
class DevopsBuild:
|
|
|
|
|
2020-03-03 15:34:12 +00:00
|
|
|
def __init__(self, project, config):
|
2020-05-01 15:38:17 +00:00
|
|
|
#deprecate stage
|
2020-03-03 15:34:12 +00:00
|
|
|
self.stage = config['stage']
|
|
|
|
self.project_root_path = config['project_root_path']
|
|
|
|
self.module = config['module']
|
|
|
|
self.build_dir_name = config['build_dir_name']
|
2020-04-17 15:59:19 +00:00
|
|
|
self.stack = {}
|
2020-03-03 09:20:18 +00:00
|
|
|
self.project = project
|
2020-03-07 14:07:14 +00:00
|
|
|
project.set_property('devops_build', self)
|
2020-03-03 15:34:12 +00:00
|
|
|
|
2020-03-03 09:20:18 +00:00
|
|
|
def name(self):
|
2020-03-04 08:07:03 +00:00
|
|
|
return self.project.name
|
2020-03-03 09:20:18 +00:00
|
|
|
|
|
|
|
def build_path(self):
|
2020-03-03 17:30:17 +00:00
|
|
|
mylist = [self.project_root_path,
|
|
|
|
self.build_dir_name,
|
2020-03-04 08:07:03 +00:00
|
|
|
self.name(),
|
2020-03-03 17:30:17 +00:00
|
|
|
self.module]
|
|
|
|
return '/'.join(filter_none(mylist))
|
2020-03-03 09:20:18 +00:00
|
|
|
|
|
|
|
def initialize_build_dir(self):
|
|
|
|
run('rm -rf ' + self.build_path(), shell=True)
|
2020-03-03 15:34:12 +00:00
|
|
|
run('mkdir -p ' + self.build_path(), shell=True)
|
2020-04-17 15:59:19 +00:00
|
|
|
|
|
|
|
def put(self, key, value):
|
|
|
|
self.stack[key] = value
|
|
|
|
|
|
|
|
def get(self, key):
|
|
|
|
return self.stack[key]
|