Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncing from upstream odoo/runbot (18.0-upgrade-refactoring-xdo) #820

Open
wants to merge 12 commits into
base: 18.0-upgrade-refactoring-xdo
Choose a base branch
from
1 change: 1 addition & 0 deletions runbot/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'views/res_config_settings_views.xml',
'views/stat_views.xml',
'views/upgrade.xml',
'views/upgrade_matrix_views.xml',
'views/warning_views.xml',
'views/custom_trigger_wizard_views.xml',
'wizards/stat_regex_wizard_views.xml',
Expand Down
12 changes: 8 additions & 4 deletions runbot/controllers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ def bundle(self, bundle=None, page=1, limit=50, **kwargs):
'/runbot/bundle/<model("runbot.bundle"):bundle>/force',
'/runbot/bundle/<model("runbot.bundle"):bundle>/force/<int:auto_rebase>',
], type='http', auth="user", methods=['GET', 'POST'], csrf=False)
def force_bundle(self, bundle, auto_rebase=False, **_post):
def force_bundle(self, bundle, auto_rebase=False, use_base_commits=False,**_post):
if not request.env.user.has_group('runbot.group_runbot_advanced_user') and ':' not in bundle.name:
raise Forbidden("Only users with a specific group can do that. Please contact runbot administrators")
_logger.info('user %s forcing bundle %s', request.env.user.name, bundle.name) # user must be able to read bundle
batch = bundle.sudo()._force()
batch._log('Batch forced by %s', request.env.user.name)
batch._prepare(auto_rebase)
batch._prepare(auto_rebase=bool(auto_rebase), use_base_commits=bool(use_base_commits))
batch._process()
return werkzeug.utils.redirect('/runbot/batch/%s' % batch.id)

Expand Down Expand Up @@ -629,10 +629,14 @@ def list_config_categories(config):
return request.render("runbot.modules_stats", context)

@route(['/runbot/load_info'], type='http', auth="user", website=True, sitemap=False)
def load_infos(self, **post):
def load_infos(self, host: str | None = None, **post):
build_by_bundle = {}

for build in request.env['runbot.build'].search([('local_state', 'in', ('pending', 'testing'))], order='id'):
domain = [('local_state', 'in', ('pending', 'testing'))]
if host:
domain.append(('host', '=', host))

for build in request.env['runbot.build'].search(domain, order='id'):
build_by_bundle.setdefault(build.params_id.create_batch_id.bundle_id, []).append(build)

build_by_bundle = list(build_by_bundle.items())
Expand Down
13 changes: 11 additions & 2 deletions runbot/data/error_link.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<odoo>
<record model="ir.actions.server" id="action_link_build_errors">
<field name="name">Link build errors</field>
<field name="name">Merge build errors</field>
<field name="model_id" ref="runbot.model_runbot_build_error" />
<field name="binding_model_id" ref="runbot.model_runbot_build_error" />
<field name="type">ir.actions.server</field>
Expand Down Expand Up @@ -39,7 +39,7 @@
records.action_assign()
</field>
</record>
<record model="ir.actions.server" id="action_deduplicate">
<record model="ir.actions.server" id="action_deduplicate">
<field name="name">Deduplicate Error Contents</field>
<field name="model_id" ref="runbot.model_runbot_build_error_content" />
<field name="binding_model_id" ref="runbot.model_runbot_build_error_content" />
Expand All @@ -49,4 +49,13 @@
records.action_deduplicate()
</field>
</record>
<record model="ir.actions.server" id="action_view_build_errors">
<field name="name">View build errors</field>
<field name="model_id" ref="runbot.model_runbot_build"/>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
action = records.action_view_build_errors()
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions runbot/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from . import upgrade
from . import user
from . import version
from . import website

# those imports have to be at the end otherwise the sql view cannot be initialised
from . import build_stat
Expand Down
14 changes: 12 additions & 2 deletions runbot/models/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ def _create_build(self, params):
build._github_status()
return link_type, build

def _prepare(self, auto_rebase=False):
def _prepare(self, auto_rebase=False, use_base_commits=False):
_logger.info('Preparing batch %s', self.id)
if use_base_commits:
self._warning('This batch will use base commits instead of bundle commits')
if not self.bundle_id.base_id:
# in some case the base can be detected lately. If a bundle has no base, recompute the base before preparing
self.bundle_id._compute_base_id()
Expand Down Expand Up @@ -358,6 +360,9 @@ def _fill_missing(branch_commits, match_type):
for commit_link in self.commit_link_ids:
commit_link.commit_id = commit_link.commit_id._rebase_on(commit_link.base_commit_id)
commit_link_by_repos = {commit_link.commit_id.repo_id.id: commit_link for commit_link in self.commit_link_ids}
base_commit_link_by_repos = {commit_link.commit_id.repo_id.id: commit_link for commit_link in self.base_reference_batch_id.commit_link_ids}
if use_base_commits:
commit_link_by_repos = base_commit_link_by_repos
version_id = self.bundle_id.version_id.id
project_id = self.bundle_id.project_id.id
trigger_customs = {}
Expand All @@ -373,14 +378,19 @@ def _fill_missing(branch_commits, match_type):
config = trigger_custom.config_id or trigger.config_id
extra_params = trigger_custom.extra_params or ''
config_data = dict(trigger.config_data or {}) | dict(trigger_custom.config_data or {})
trigger_commit_link_by_repos = commit_link_by_repos
if trigger_custom.use_base_commits and self.base_reference_batch_id:
self._warning(f'This batch will use base commits instead of bundle commits for trigger {trigger.name}')
trigger_commit_link_by_repos = base_commit_link_by_repos
commits_links = [trigger_commit_link_by_repos[repo.id].id for repo in trigger_repos]
params_value = {
'version_id': version_id,
'extra_params': extra_params,
'config_id': config.id,
'project_id': project_id,
'trigger_id': trigger.id, # for future reference and access rights
'config_data': config_data,
'commit_link_ids': [(6, 0, [commit_link_by_repos[repo.id].id for repo in trigger_repos])],
'commit_link_ids': [(6, 0, commits_links)],
'modules': bundle.modules,
'dockerfile_id': dockerfile_id,
'create_batch_id': self.id,
Expand Down
14 changes: 13 additions & 1 deletion runbot/models/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,8 +1263,20 @@ def _github_status(self):
target_url = trigger.ci_url or "%s/runbot/build/%s" % (self.get_base_url(), build.id)
for build_commit in self.params_id.commit_link_ids:
commit = build_commit.commit_id
if 'base_' not in build_commit.match_type and commit.repo_id in trigger.repo_ids:
if 'base_' not in build_commit.match_type and (trigger.ci_send_all or (commit.repo_id in trigger.repo_ids)):
commit._github_status(build, trigger.ci_context, state, target_url, desc)

def _parse_config(self):
return set(findall(self._server("tools/config.py"), r'--[\w-]+', ))

def action_view_build_errors(self):
errors = self.env['runbot.build.error'].browse()
for record in self:
errors |= record.error_log_ids.error_content_id.error_id
return {
"type": "ir.actions.act_window",
"res_model": "runbot.build.error",
"domain": [('id', 'in', errors.ids)],
"name": "Build errors",
"view_mode": "list,form"
}
48 changes: 36 additions & 12 deletions runbot/models/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ class ConfigStep(models.Model):
upgrade_from_all_intermediate_version = fields.Boolean() # 13.2 # 13.1
upgrade_from_version_ids = fields.Many2many('runbot.version', relation='runbot_upgrade_from_version_ids', string='Forced version to use as source (cartesian with target)')

# wip replace previous field by matrix
upgrade_matrix_id = fields.Many2one('runbot.upgrade.matrix', 'Upgrade matrix', tracking=True)
upgrade_current_source = fields.Boolean('Upgrade Curent source', help='Use current build as Source if version match', default=True, tracking=True)
upgrade_current_target = fields.Boolean('Upgrade Curent target', help='Use current build as target if version match', default=True, tracking=True)
# TODO maybe remove this field in the future, should all work in the same build
upgrade_from_bellow = fields.boolean('Upgrade from bellow', help="Standard upgrade behaviour", default=True, tracking=True)
upgrade_to_above = fields.boolean('Upgrade to above', help="Will behave as a complement", default=True, tracking=True)

upgrade_flat = fields.Boolean("Flat", help="Take all decisions in on build")

upgrade_config_id = fields.Many2one('runbot.build.config',string='Upgrade Config', tracking=True, index=True)
Expand Down Expand Up @@ -708,7 +716,7 @@ def _run_configure_upgrade(self, build):
dbs = dump_builds.database_ids.sorted('db_suffix')
valid_databases += list(self._filter_upgrade_database(dbs, upgrade_db.db_pattern))
if not valid_databases:
build._log('_run_configure_upgrade', 'No datase found for pattern %s' % (upgrade_db.db_pattern), level='ERROR')
build._log('_run_configure_upgrade', 'No database found for pattern %s' % (upgrade_db.db_pattern), level='ERROR')
for db in valid_databases:
#commit_ids = build.params_id.commit_ids
#if commit_ids != target.params_id.commit_ids:
Expand All @@ -722,7 +730,7 @@ def _run_configure_upgrade(self, build):
'upgrade_to_build_id': target.id,
'upgrade_from_build_id': source,
'dump_db': db.id,
'config_id': self.upgrade_config_id
'config_id': self.upgrade_config_id,
})

child.description = 'Testing migration from %s to %s using db %s (%s)' % (
Expand Down Expand Up @@ -861,16 +869,32 @@ def _reference_builds(self, batch, trigger):
refs_builds = refs_batches.mapped('slot_ids').filtered(
lambda slot: slot.trigger_id == upgrade_dumps_trigger_id
).mapped('build_id')
# should we filter on active? implicit. On match type? on skipped ?
# is last_"done"_batch enough?
# TODO active test false and take last done/running build limit 1 -> in case of rebuild
return refs_builds

def _is_upgrade_step(self):
return self.job_type in ('configure_upgrade', 'configure_upgrade_complement')

def _reference_batches(self, batch, trigger):
if self.job_type == 'configure_upgrade_complement':
# upgrade_matrix_id
# upgrade_current_source
# upgrade_current_target
# upgrade_from_bellow
# upgrade_to_above

if self.upgrade_matrix_id:
batches = self.env['runbot.batch']
base_batch = batch if batch.reference_batch_ids else batch.base_reference_batch_id
reference_batch_ids = base_batch.reference_batch_ids
if self.upgrade_from_bellow:
from_versions = self.upgrade_matrix_id._get_versions_to(batch.version_id)
batches |= reference_batch_ids.filtered(lambda batch: batch.bundle_id.version_id in from_versions)

if self.upgrade_to_above:
to_versions = self.upgrade_matrix_id._get_versions_from(batch.version_id)
batches |= reference_batch_ids.filtered(lambda batch: batch.bundle_id.version_id in to_versions)
return batches

elif self.job_type == 'configure_upgrade_complement':
return self._reference_batches_complement(batch, trigger)
else:
return self._reference_batches_upgrade(batch, trigger.upgrade_dumps_trigger_id.category_id.id)
Expand All @@ -890,9 +914,9 @@ def _reference_batches_complement(self, batch, trigger):
for next_version in next_versions:
if bundle.version_id in upgrade_complement_step._get_upgrade_source_versions(next_version):
target_versions |= next_version
return target_versions.with_context(
category_id=category_id, project_id=bundle.project_id.id,
).mapped('base_bundle_id').filtered('to_upgrade').mapped('last_done_batch')

base_batch = batch if batch.reference_batch_ids else batch.base_reference_batch_id
return base_batch.reference_batch_ids.filtered(lambda batch: batch.bundle_id.version_id in target_versions and batch.category_id.id == category_id)

def _reference_batches_upgrade(self, batch, category_id):
if not batch.bundle_id.base_id.to_upgrade:
Expand Down Expand Up @@ -932,9 +956,9 @@ def from_versions(f_bundle):
from_versions(f_bundle)
source_refs_bundles = source_refs_bundles.filtered('to_upgrade_from')

return (target_refs_bundles | source_refs_bundles).with_context(
category_id=category_id
).mapped('last_done_batch')
ref_bundles = target_refs_bundles | source_refs_bundles
base_batch = batch if batch.reference_batch_ids else batch.base_reference_batch_id
return base_batch.reference_batch_ids.filtered(lambda batch: batch.bundle_id in ref_bundles and batch.category_id.id == category_id)

def _log_end(self, build):
if self.job_type == 'create_build':
Expand Down
Loading