Changeset View
Changeset View
Standalone View
Standalone View
lilybuild/lilybuild/ci_steps.py
| Show First 20 Lines • Show All 370 Lines • ▼ Show 20 Lines | def getSchedulersAndProperties(self): | ||||
| ret.append({ | ret.append({ | ||||
| 'sched_name': self.lbc.triggerable_scheduler_name, | 'sched_name': self.lbc.triggerable_scheduler_name, | ||||
| 'props_to_set': properties, | 'props_to_set': properties, | ||||
| 'unimportant': False, | 'unimportant': False, | ||||
| }) | }) | ||||
| return ret | return ret | ||||
| class LatestMixin: | |||||
| latest_build_dir_pattern = '%(kw:st)s/repos/%(prop:lilybuild_repo_id)s/latest' | |||||
| latest_good_build_dir_pattern = '%(kw:st)s/repos/%(prop:lilybuild_repo_id)s/latest-good' | |||||
| latest_name_pattern = '%(kw:st)s/repos/%(prop:lilybuild_repo_id)s/latest/%(kw:name)s' | |||||
| latest_good_name_pattern = '%(kw:st)s/repos/%(prop:lilybuild_repo_id)s/latest-good/%(kw:name)s' | |||||
| class EnsureLatestDirs(steps.MasterShellCommand, LatestMixin): | |||||
| def __init__(self, lbc, storage_dir, **kwargs): | |||||
| self.lbc = lbc | |||||
| self.storage_dir = storage_dir | |||||
| command = util.Transform( | |||||
| fill_list, | |||||
| 'mkdir', | |||||
| '-pv', | |||||
| util.Interpolate(self.latest_build_dir_pattern, st=self.storage_dir), | |||||
| util.Interpolate(self.latest_good_build_dir_pattern, st=self.storage_dir)) | |||||
| super().__init__( | |||||
| name='Ensure latest dirs', | |||||
| command=command, | |||||
| logEnviron=False, | |||||
| doStepIf=on_always, | |||||
| **kwargs | |||||
| ) | |||||
| class MarkLatest(steps.MasterShellCommand, LatestMixin): | |||||
| def __init__(self, lbc, storage_dir, buildid, ref_name, is_good, **kwargs): | |||||
| self.lbc = lbc | |||||
| self.storage_dir = storage_dir | |||||
| name_pattern = self.latest_good_name_pattern if is_good else self.latest_name_pattern | |||||
| command = util.Transform( | |||||
| fill_list, | |||||
| 'ln', | |||||
| '-sfvn', | |||||
| util.Interpolate('../builds/%(kw:buildid)s', buildid=buildid), | |||||
| util.Interpolate(name_pattern, st=self.storage_dir, name=ref_name), | |||||
| ) | |||||
| super().__init__( | |||||
| name='Mark build as latest-good' if is_good else 'Mark build as latest', | |||||
| command=command, | |||||
| logEnviron=False, | |||||
| doStepIf=on_success if is_good else on_always, | |||||
| **kwargs | |||||
| ) | |||||
| class AnalyzeCIFileCommand(buildstep.ShellMixin, steps.BuildStep): | class AnalyzeCIFileCommand(buildstep.ShellMixin, steps.BuildStep): | ||||
| ci_def_file = '.gitlab-ci.yml' | ci_def_file = '.gitlab-ci.yml' | ||||
| build_target_prop_name = 'harbormaster_build_target_phid' | build_target_prop_name = 'harbormaster_build_target_phid' | ||||
| def __init__( | def __init__( | ||||
| self, | self, | ||||
| lbc, | lbc, | ||||
| src_relative=None, | src_relative=None, | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | def get_ref_and_type(self): | ||||
| if ref is not None: | if ref is not None: | ||||
| m = re.match(r'^refs/(heads|tags)/(.+)$', ref) | m = re.match(r'^refs/(heads|tags)/(.+)$', ref) | ||||
| if m: | if m: | ||||
| ref = m.group(2) | ref = m.group(2) | ||||
| return (ref, ref_type) | return (ref, ref_type) | ||||
| def get_cur_repo_config(self): | |||||
| return self.lbc.repos[self.getProperty('lilybuild_repo_id')] | |||||
| @defer.inlineCallbacks | @defer.inlineCallbacks | ||||
| def get_pipeline_ci_vars(self): | def get_pipeline_ci_vars(self): | ||||
| url = yield self.build.getUrl() | url = yield self.build.getUrl() | ||||
| res = { | res = { | ||||
| 'CI_PIPELINE_ID': self.build.buildid, | 'CI_PIPELINE_ID': self.build.buildid, | ||||
| 'CI_PIPELINE_IID': self.build.buildid, | 'CI_PIPELINE_IID': self.build.buildid, | ||||
| 'CI_PIPELINE_URL': url, | 'CI_PIPELINE_URL': url, | ||||
| 'CI_PROJECT_ID': self.getProperty('lilybuild_repo_id'), | 'CI_PROJECT_ID': self.getProperty('lilybuild_repo_id'), | ||||
| Show All 20 Lines | def run(self): | ||||
| # if the command passes extract the list of stages | # if the command passes extract the list of stages | ||||
| result = cmd.results() | result = cmd.results() | ||||
| if result == util.SUCCESS: | if result == util.SUCCESS: | ||||
| pipeline_vars = yield self.get_pipeline_ci_vars() | pipeline_vars = yield self.get_pipeline_ci_vars() | ||||
| self.setProperty('lilybuild_pipeline_vars', pipeline_vars, self.__class__.__name__) | self.setProperty('lilybuild_pipeline_vars', pipeline_vars, self.__class__.__name__) | ||||
| # create a ShellCommand for each stage and add them to the build | # create a ShellCommand for each stage and add them to the build | ||||
| self.build.addStepsAfterCurrentStep(self.get_steps(self.observer.getStdout())) | self.build.addStepsAfterCurrentStep(self.get_steps(self.observer.getStdout())) | ||||
| latest_branch_map = self.get_cur_repo_config()['artifact_latest_branch_map'] | |||||
| ref, _ref_type = self.get_ref_and_type() | |||||
| if ref in latest_branch_map: | |||||
| latest_name = latest_branch_map[ref] | |||||
| self.build.addStepsAfterLastStep([ | |||||
| EnsureLatestDirs(lbc=self.lbc, storage_dir=self.storage_dir), | |||||
| MarkLatest( | |||||
| lbc=self.lbc, | |||||
| storage_dir=self.storage_dir, | |||||
| buildid=self.build.buildid, | |||||
| ref_name=latest_name, | |||||
| is_good=True, | |||||
| ), | |||||
| MarkLatest( | |||||
| lbc=self.lbc, | |||||
| storage_dir=self.storage_dir, | |||||
| buildid=self.build.buildid, | |||||
| ref_name=latest_name, | |||||
| is_good=False, | |||||
| ), | |||||
| ]) | |||||
| return result | return result | ||||