From d76a41537c13687d17ba43238c04c34d3aabd0d4 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 24 Nov 2020 12:30:42 +0100 Subject: [PATCH] [IMP] runbot: add batch_dependent triggers Params mechanism are a way to avoid to rebuild with the exact same params. Commit is the main identifier to know if two builds are the same, ususally commit_link are not usefull to uniquify params, exept when the mergebase is in use as in security check (based on diff). We would also like to avoid to have red diff-based build in sticky/base branches when the ci is ignored on a pr, but we want to keep the diff display on new batches (lines and files changed). We need a way to know if it is a is_base bundle. This was an initially forbidden behaviour because of duplicate detection. This commit add a batch_dependent flag. This will enable the use of the batch in the fingerprint, making it unique per batch and disabling duplicate detection/ in this case we can use the "is_base" information from the bundle + avoid false duplicate detection if trigger is based on mergebase-commit diff. (pr based on another pr now merged) --- runbot/models/batch.py | 1 + runbot/models/build.py | 3 +++ runbot/models/repo.py | 1 + runbot/views/build_views.xml | 3 +++ runbot/views/repo_views.xml | 1 + 5 files changed, 9 insertions(+) diff --git a/runbot/models/batch.py b/runbot/models/batch.py index 29717cb5..4e5f1d7e 100644 --- a/runbot/models/batch.py +++ b/runbot/models/batch.py @@ -286,6 +286,7 @@ class Batch(models.Model): 'commit_link_ids': [(6, 0, [commit_link_by_repos[repo.id].id for repo in trigger_repos])], 'modules': bundle.modules, 'dockerfile_id': dockerfile_id, + 'create_batch_id': self.id, } params_value['builds_reference_ids'] = trigger._reference_builds(bundle) diff --git a/runbot/models/build.py b/runbot/models/build.py index 429367f6..f3e2f68a 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -49,6 +49,7 @@ class BuildParameters(models.Model): version_id = fields.Many2one('runbot.version', required=True, index=True) project_id = fields.Many2one('runbot.project', required=True, index=True) # for access rights trigger_id = fields.Many2one('runbot.trigger', index=True) # for access rights + create_batch_id = fields.Many2one('runbot.batch') category = fields.Char('Category', index=True) # normal vs nightly vs weekly, ... dockerfile_id = fields.Many2one('runbot.dockerfile', index=True, default=lambda self: self.env.ref('runbot.docker_default', raise_if_not_found=False)) skip_requirements = fields.Boolean('Skip requirements.txt auto install') @@ -91,6 +92,8 @@ class BuildParameters(models.Model): 'dockerfile_id': param.dockerfile_id.id, 'skip_requirements': param.skip_requirements, } + if param.trigger_id.batch_dependent: + cleaned_vals['create_batch_id'] = param.create_batch_id.id, param.fingerprint = hashlib.sha256(str(cleaned_vals).encode('utf8')).hexdigest() @api.depends('commit_link_ids') diff --git a/runbot/models/repo.py b/runbot/models/repo.py index e0660abb..dad25628 100644 --- a/runbot/models/repo.py +++ b/runbot/models/repo.py @@ -43,6 +43,7 @@ class Trigger(models.Model): repo_ids = fields.Many2many('runbot.repo', relation='runbot_trigger_triggers', string="Triggers", domain="[('project_id', '=', project_id)]") dependency_ids = fields.Many2many('runbot.repo', relation='runbot_trigger_dependencies', string="Dependencies") config_id = fields.Many2one('runbot.build.config', string="Config", required=True) + batch_dependent = fields.Boolean('Batch Dependent', help="Force adding batch in build parameters to make it unique and give access to bundle") ci_context = fields.Char("Ci context", default='ci/runbot', tracking=True) category_id = fields.Many2one('runbot.category', default=lambda self: self.env.ref('runbot.default_category', raise_if_not_found=False)) diff --git a/runbot/views/build_views.xml b/runbot/views/build_views.xml index c2bf7528..76578c9c 100644 --- a/runbot/views/build_views.xml +++ b/runbot/views/build_views.xml @@ -16,6 +16,9 @@ + + + diff --git a/runbot/views/repo_views.xml b/runbot/views/repo_views.xml index 2a41b090..98eba586 100644 --- a/runbot/views/repo_views.xml +++ b/runbot/views/repo_views.xml @@ -17,6 +17,7 @@ +