[IMP] runbot: automatic base master bundle

When adding a new project, if no branch matches a base name,
the created bundles won't have a version and it will fail.

A simple fix will be to add a master bundle for all projects.
This commit is contained in:
Xavier-Do 2023-01-10 18:48:55 +01:00 committed by Christophe Monniez
parent 9e0f0e6a75
commit 27ac733df6
9 changed files with 69 additions and 20 deletions

View File

@ -6,7 +6,7 @@
'author': "Odoo SA",
'website': "http://runbot.odoo.com",
'category': 'Website',
'version': '5.2',
'version': '5.3',
'application': True,
'depends': ['base', 'base_automation', 'website'],
'data': [

View File

@ -17,17 +17,6 @@
</record>
<data noupdate="1">
<record model="runbot.bundle" id="runbot.bundle_master" >
<field name="name">master</field>
<field name="is_base">True</field>
<field name="project_id" ref="runbot.main_project"/>
</record>
<record model="runbot.bundle" id="runbot.bundle_dummy">
<field name="name">Dummy</field>
<field name="no_build">True</field>
<field name="project_id" ref="runbot.main_project"/>
</record>
<record model="ir.config_parameter" id="runbot.runbot_upgrade_exception_message">
<field name="key">runbot.runbot_upgrade_exception_message</field>
<field name="value">Upgrade exception [#{exception.id}]({base_url}/web/#id={exception.id}&amp;view_type=form&amp;model=runbot.upgrade.exception) added\

View File

@ -0,0 +1,28 @@
from odoo import api, SUPERUSER_ID
def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
projects = env['runbot.project'].search([])
for project in projects:
if not project.master_bundle_id:
master = env['runbot.bundle'].search([('name', '=', 'master'), ('project_id', '=', project.id)], limit=1)
if not master:
master = env['runbot.bundle'].create({
'name': 'master',
'project_id': project.id,
'is_base': True,
})
project.master_bundle_id = master
if not project.dummy_bundle_id:
dummy = env['runbot.bundle'].search([('name', '=', 'Dummy'), ('project_id', '=', project.id)], limit=1)
if not dummy:
dummy = env['runbot.bundle'].create({
'name': 'Dummy',
'project_id': project.id,
'no_build': True,
})
else:
dummy.no_build = True
project.dummy_bundle_id = dummy

View File

@ -0,0 +1,2 @@
def migrate(cr, version):
cr.execute("DELETE FROM ir_model_data WHERE module = 'runbot' AND model = 'runbot.bundle' and name in ('bundle_master', 'bundle_dummy')")

View File

@ -145,8 +145,8 @@ class Branch(models.Model):
@api.depends('reference_name', 'remote_id.repo_id.project_id')
def _compute_bundle_id(self):
dummy = self.env.ref('runbot.bundle_dummy')
for branch in self:
dummy = branch.remote_id.repo_id.project_id.dummy_bundle_id
if branch.bundle_id == dummy:
continue
name = branch.reference_name

View File

@ -37,7 +37,7 @@ class Codeowner(models.Model):
def _validate_version_domain(self):
for rec in self:
try:
self._match_version(self.env.ref('runbot.bundle_master').version_id)
self._match_version(self.env['runbot.version'].search([], limit=1)[0])
except Exception as e:
raise ValidationError("Unable to validate version_domain: %s" % e)

View File

@ -1,4 +1,4 @@
from odoo import models, fields
from odoo import models, fields, api
class Project(models.Model):
@ -15,6 +15,32 @@ class Project(models.Model):
sequence = fields.Integer('Sequence')
organisation = fields.Char('organisation', default=lambda self: self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_organisation'))
token = fields.Char("Github token", groups="runbot.group_runbot_admin")
master_bundle_id = fields.Many2one('runbot.bundle', string='Master bundle')
dummy_bundle_id = fields.Many2one('runbot.bundle', string='Dummy bundle')
@api.model_create_multi
def create(self, create_values):
projects = super().create(create_values)
base_bundle_values = []
dummy_bundle_values = []
for project in projects:
base_bundle_values.append({
'project_id': project.id,
'name': 'master',
'is_base': True,
})
dummy_bundle_values.append({
'project_id': project.id,
'name': 'Dummy',
'no_build': True,
})
master_bundles = self.env['runbot.bundle'].create(base_bundle_values)
dummy_bundles = self.env['runbot.bundle'].create(dummy_bundle_values)
for project, bundle in zip(projects, master_bundles):
project.master_bundle_id = bundle
for project, bundle in zip(projects, dummy_bundles):
project.dummy_bundle_id = bundle
return projects
class Category(models.Model):

View File

@ -146,7 +146,7 @@ class TestBranchForbidden(RunbotCase):
"""Test that a branch matching the repo forbidden regex, goes to dummy bundle"""
def test_forbidden(self):
dummy_bundle = self.env.ref('runbot.bundle_dummy')
dummy_bundle = self.remote_server_dev.repo_id.project_id.dummy_bundle_id
self.remote_server_dev.repo_id.forbidden_regex = '^bad_name.+'
with mute_logger("odoo.addons.runbot.models.branch"):
branch = self.Branch.create({
@ -199,7 +199,7 @@ class TestBranchIsBase(RunbotCaseMinimalSetup):
@mute_logger("odoo.addons.runbot.models.branch")
def test_is_base_regex_on_dev_remote(self):
"""Test that a branch matching the is_base regex on a secondary remote goes to the dummy bundles."""
dummy_bundle = self.env.ref('runbot.bundle_dummy')
dummy_bundle = self.repo_addons.project_id.dummy_bundle_id
# master branch on dev remote
initial_addons_dev_commit = self.Commit.create({

View File

@ -14,15 +14,19 @@ class Runbot(models.AbstractModel):
@patch('odoo.addons.runbot.models.repo.Repo._git')
def _create_demo_data(self, mock_git, mock_github):
mock_github.return_value = False
project = self.env.ref('runbot.main_project')
bundles = self.env['runbot.bundle'].browse(
self.env['ir.model.data'].search([
('module', '=', 'runbot_populate'), ('model', '=', 'runbot.bundle')
]).mapped('res_id')
)
bundles |= self.env.ref('runbot.bundle_master')
).filtered(lambda bundle: bundle.project_id == project)
bundles |= project.master_bundle_id
bundles = bundles.sorted('is_base', reverse=True)
assert bundles|self.env.ref('runbot.bundle_dummy') == bundles.search([])
existing_bundle = bundles.search([('project_id', '=', project.id)])
expected_bundle = bundles | project.dummy_bundle_id
assert expected_bundle == existing_bundle
if bundles.branch_ids:
# only populate data if no branch are found