[FIX] runbot: use parent global_state for gitthub status

The main motivation of this commit is to be able to notify github status only
when all children are done.

Until today, children where only used for dev branches and nightly. The needs to
use this system for staging need to enforce github_status behaviour.
Before this commit, a parent won't send github status since he will only
create childrens. And childrens are not awared of other children state,
so sending a succes may be wrong if another one failed.

Asking the parent to make the github_status looks the easiest solution:
-If top parent config will have update_github_state False, we also want to take that into account.
-If a child wants to contact github for failfast, parent will be in global_state error too and will send
message immediatly.
-If a child want to contact github for succsess, we actually want to wait for last child, parent will
be in waiting global_state and notify nothing (or pending).
Only last child will be able to notiffy success since global_state will be running or done at this step.
Orphan builds wont have any impact on result in with this scenario.
This commit is contained in:
Xavier-Do 2019-07-24 16:54:21 +02:00
parent 2e5b1cb240
commit fb637194f5

View File

@ -293,7 +293,7 @@ class runbot_build(models.Model):
docker_source_folders.add(docker_source_folder)
build_id.write(extra_info)
if build_id.local_state == 'duplicate' and build_id.duplicate_id.global_state in ('running', 'done'): # and not build_id.parent_id:
if build_id.local_state == 'duplicate' and build_id.duplicate_id.global_state in ('running', 'done'):
build_id._github_status()
return build_id
@ -933,20 +933,25 @@ class runbot_build(models.Model):
def _github_status(self):
"""Notify github of failed/successful builds"""
for build in self:
if build.config_id.update_github_state:
if build.parent_id:
build.parent_id._github_status()
elif build.config_id.update_github_state:
runbot_domain = self.env['runbot.repo']._domain()
desc = "runbot build %s" % (build.dest,)
if build.local_state == 'testing':
if build.global_result in ('ko', 'warn'):
state = 'failure'
elif build.global_state == 'testing':
state = 'pending'
elif build.local_state in ('running', 'done'):
elif build.global_state in ('running', 'done'):
state = 'error'
if build.global_result == 'ok':
state = 'success'
else:
_logger.debug("skipping github status for build %s ", build.id)
continue
desc += " (runtime %ss)" % (build.job_time,)
if build.local_result == 'ok':
state = 'success'
if build.local_result in ('ko', 'warn'):
state = 'failure'
status = {
"state": state,
"target_url": "http://%s/runbot/build/%s" % (runbot_domain, build.id),