diff --git a/runbot/models/build.py b/runbot/models/build.py index 93bb0cf79..e0821e0a0 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -164,6 +164,8 @@ class BuildResult(models.Model): trigger_id = fields.Many2one('runbot.trigger', related='params_id.trigger_id', store=True, index=True) create_batch_id = fields.Many2one('runbot.batch', related='params_id.create_batch_id', store=True, index=True) create_bundle_id = fields.Many2one('runbot.bundle', related='params_id.create_batch_id.bundle_id', index=True) + base_attached = fields.Boolean('Base attached', compute='_compute_base_attached') + can_rebuild = fields.Boolean('Can rebuild', compute='_compute_can_rebuild') # state machine global_state = fields.Selection(make_selection(state_order), string='Status', compute='_compute_global_state', store=True, recursive=True) @@ -494,6 +496,18 @@ def _compute_build_age(self): else: build.build_age = 0 + def _compute_can_rebuild(self): + # note, not recursive, only checks one level of depth to avoid checking to much builds, mainly for nightlies + # this is a relaxed condition to help and easier rebuild before waiting for all child to be killed + for build in self: + build.can_rebuild = False + if build.global_state in ['done', 'running']: + build.can_rebuild = True + elif build.requested_action == 'deathrow': + build.can_rebuild = True + elif build.local_state in ['done', 'running'] and all(child.can_rebuild for child in build.children_ids): + build.can_rebuild = True + def _rebuild(self, message=None): """Force a rebuild and return a recordset of builds""" self.ensure_one() @@ -1015,6 +1029,24 @@ def truncate(message, maxlenght=300000): 'line': '0', }) + def _compute_base_attached(self): + slots = self.env['runbot.batch.slot'].search([('build_id', 'in', self.ids)], order='build_id') + slots.batch_id.bundle_id.mapped('is_base') # prefetch + bundle_per_build = defaultdict(list) + for slot in slots: + bundle_per_build[slot.build_id].append(slot.batch_id.bundle_id) + for build in self: + build.base_attached = any(bundle.is_base for bundle in bundle_per_build[build]) + + def _cannnot_kill_reason(self, from_batch=None): + if self.requested_action == 'deathrow': + return "Killing" + if not self.base_attached: + return None + if from_batch and from_batch.bundle_id.is_base and self.env.user.has_groups('runbot.group_runbot_admin'): + return None + return "Cannot be killed, attached to a base bundle" + def _kill(self, result=None): host_name = self.env['runbot.host']._get_current_name() self.ensure_one() diff --git a/runbot/models/runbot.py b/runbot/models/runbot.py index 2e038108d..823f42d1d 100644 --- a/runbot/models/runbot.py +++ b/runbot/models/runbot.py @@ -115,7 +115,6 @@ def _gc_running(self, host): for build in Build.browse(build_ids)[running_max:]: build._kill() - def _gc_testing(self, host): """garbage collect builds that could be killed""" # decide if we need room diff --git a/runbot/models/upgrade.py b/runbot/models/upgrade.py index 35b1aced7..48d0f6b1f 100644 --- a/runbot/models/upgrade.py +++ b/runbot/models/upgrade.py @@ -22,7 +22,7 @@ def action_post_message(self): raise UserError('You are not allowed to send messages') for pr in self.pr_ids: pr.remote_id._github('/repos/:owner/:repo/issues/%s/comments' % pr.name, {'body': self.message}) - + def action_auto_rebuild(self): builds = self.create_build_id.parent_id.children_ids if self.create_build_id.parent_id else self.create_build_id for build in builds: @@ -40,7 +40,7 @@ def _generate(self): if exceptions: return 'suppress_upgrade_warnings=%s' % (','.join(exceptions.mapped('elements'))).replace(' ', '').replace('\n', ',') return False - + def default_pr_ids(self): bundle_id = self.env.context.get('default_bundle_id') if bundle_id: diff --git a/runbot/templates/build.xml b/runbot/templates/build.xml index 3f9ecf326..c32faa2d4 100644 --- a/runbot/templates/build.xml +++ b/runbot/templates/build.xml @@ -92,7 +92,7 @@ - + Commit: diff --git a/runbot/templates/utils.xml b/runbot/templates/utils.xml index a7aaf59f5..7560622d1 100644 --- a/runbot/templates/utils.xml +++ b/runbot/templates/utils.xml @@ -243,7 +243,9 @@ @@ -266,7 +268,10 @@ - + + + + @@ -315,16 +320,24 @@ Database selector - - - Rebuild - + + + + Rebuild + + + + Advanced Rebuild + + - + + Kill +