[IMP] runbot: add a way to add custom pre/post

Mainly usefull for custom triggers
This commit is contained in:
Xavier-Do 2024-03-21 12:10:47 +01:00
parent 70532df2d6
commit 30611c2ee8
2 changed files with 28 additions and 4 deletions

View File

@ -1062,7 +1062,7 @@ class BuildResult(models.Model):
if not self.params_id.skip_requirements and os.path.isfile(commit_id._source_path('requirements.txt')):
repo_dir = self._docker_source_folder(commit_id)
requirement_path = os.sep.join([repo_dir, 'requirements.txt'])
pres.append([f'python{py_version}', '-m', 'pip', 'install','--user', '--progress-bar', 'off', '-r', f'{requirement_path}'])
pres.append([f'python{py_version}', '-m', 'pip', 'install', '--user', '--progress-bar', 'off', '-r', f'{requirement_path}'])
addons_paths = self._get_addons_path()
(server_commit, server_file) = self._get_server_info()
@ -1073,7 +1073,7 @@ class BuildResult(models.Model):
if sub_command:
cmd += [sub_command]
if not self.params_id.extra_params or '--addons-path' not in self.params_id.extra_params :
if not self.params_id.extra_params or '--addons-path' not in self.params_id.extra_params:
cmd += ['--addons-path', ",".join(addons_paths)]
# options
@ -1083,7 +1083,12 @@ class BuildResult(models.Model):
if grep(config_path, "no-netrpc"):
cmd.append("--no-netrpc")
command = Command(pres, cmd, [], cmd_checker=build)
pres += self.params_id.config_data.get('pres', [])
posts = self.params_id.config_data.get('posts', [])
finals = self.params_id.config_data.get('finals', [])
config_tuples = self.params_id.config_data.get('config_tuples', [])
command = Command(pres, cmd, posts, finals=finals, config_tuples=config_tuples, cmd_checker=build)
# use the username of the runbot host to connect to the databases
command.add_config_tuple('db_user', '%s' % pwd.getpwuid(os.getuid()).pw_name)

View File

@ -237,7 +237,7 @@ class TestBuildResult(RunbotCase):
self.assertEqual(modules_to_test, sorted(['other_mod_2']))
def test_build_cmd_log_db(self, ):
def test_build_cmd_log_db(self):
""" test that the log_db parameter is set in the .odoorc file """
build = self.Build.create({
'params_id': self.server_params.id,
@ -245,6 +245,25 @@ class TestBuildResult(RunbotCase):
cmd = build._cmd(py_version=3)
self.assertIn('log_db = runbot_logs', cmd.get_config())
def test_build_cmd_custom_pre_post(self):
""" test that the log_db parameter is set in the .odoorc file """
custom_pre = ['pip install something:someversion'.split()]
custom_post = ["psql -l > database list".split()]
self.server_params.config_data = {
'pres': [custom_pre],
'posts': [custom_post],
}
self.env.flush_all()
build = self.Build.create({
'params_id': self.server_params.id,
})
cmd = build._cmd(py_version=3)
self.assertIn('python3 -m pip install --user --progress-bar off -r server/requirements.txt'.split(), cmd.pres)
self.assertIn(custom_pre, cmd.pres)
self.assertIn(custom_post, cmd.posts)
def test_build_cmd_server_path_no_dep(self):
""" test that the server path and addons path """
build = self.Build.create({