Skip to content

Commit

Permalink
Merge PR #199 into 11.0
Browse files Browse the repository at this point in the history
Signed-off-by moylop260
  • Loading branch information
OCA-git-bot committed May 14, 2020
2 parents 8845595 + b3b4513 commit 49d175f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion runbot_buildout/README.rst
Expand Up @@ -16,7 +16,7 @@ To configure this module, you need to:
#. turn on `Use buildouts` on a repository
#. fill in a regex that allows to differentiate a normal branch name: For runbot, branches should be named ``$version-$sometext`` anyways, so this module's suggestion is to call buildout branches ``buildout-$version-$sometext``
#. check the value of the field `Buildout section`, this must be the name you use in your buildouts
#. if you use multiple buildouts for the same version to implement some kind of DTAP scenario (you should), you can mark some buildout branch as the one to be used for tests by navigating to the branch and checking `Default for this version`
#. if you use multiple buildouts for the same version to implement some kind of DTAP scenario (you should), you can mark some buildout branch as the one to be used for tests by navigating to the repository and selecting a default buildout branch. In case you deal with multiple versions, set the default to a buildout from your current version, and set the buildout branch for branches of the new version manually
#. when converting a repository to use buildouts, be sure to remove all dependency branches first. Otherwise, runbot will copy all of them unnecessarily. Then, rebuild some buildout branch, and when it is green, rebuild another branch that is supposed to use the buildout

Background
Expand Down
2 changes: 1 addition & 1 deletion runbot_buildout/__manifest__.py
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Buildout for runbot",
"version": "11.0.1.0.0",
"version": "11.0.1.1.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Runbot",
Expand Down
2 changes: 1 addition & 1 deletion runbot_buildout/examples/buildout.cfg
Expand Up @@ -10,4 +10,4 @@ anybox.recipe.odoo = 1.9.3.dev0
[odoo]
recipe = anybox.recipe.odoo:server

version = git http://github.com/oca/ocb.git odoo 9.0 depth=1
version = git http://github.com/oca/ocb.git odoo 11.0 depth=1
11 changes: 11 additions & 0 deletions runbot_buildout/migrations/11.0.1.1.0/post-migration.py
@@ -0,0 +1,11 @@
# Copyright 2020 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).


def migrate(cr, version=None):
cr.execute(
"""update runbot_repo set buildout_branch_id=runbot_branch.id
from runbot_branch where
runbot_branch.repo_id=runbot_repo.id and runbot_branch.buildout_default
"""
)
3 changes: 1 addition & 2 deletions runbot_buildout/models/runbot_branch.py
Expand Up @@ -11,7 +11,6 @@
class RunbotBranch(models.Model):
_inherit = 'runbot.branch'

buildout_default = fields.Boolean('Default buildout')
buildout_version = fields.Char(
compute='_compute_buildout_version', store=True,
)
Expand All @@ -22,7 +21,7 @@ class RunbotBranch(models.Model):
)
buildout_branch_id = fields.Many2one(
'runbot.branch', help='Default buildout branch',
domain='[("repo_id", "=", repo_id)]',
domain="[('repo_id', '=', repo_id), ('buildout_version', '!=', False)]"
)

@api.multi
Expand Down
20 changes: 13 additions & 7 deletions runbot_buildout/models/runbot_build.py
Expand Up @@ -181,7 +181,7 @@ def _job_30_run(self, build, lock_path, log_path):
if self._check_buildout_success(build):
build.write({'result': 'ok'})
return self._spawn(
'for part in %s/*; do git -C $part repack -a --threads=1; '
'for part in %s/*; do git -C $part repack -A --threads=1; '
'done' % (
build._path('parts')
), lock_path, log_path, shell=True,
Expand Down Expand Up @@ -221,7 +221,7 @@ def preexec():
return subprocess.Popen(
cmd, stdout=out, stderr=out, cwd=self._path(),
preexec_fn=preexec, close_fds=False,
env=self._get_buildout_environment(),
env=self._get_buildout_environment(log_build=True),
).pid

@api.multi
Expand Down Expand Up @@ -259,7 +259,7 @@ def _bootstrap_buildout(self, lock_path, log_path, delete_server=True):
)

@api.multi
def _get_buildout_environment(self):
def _get_buildout_environment(self, log_build=False):
self.ensure_one()
build_environment = dict(os.environ)
previous_build = self.search([
Expand All @@ -269,6 +269,12 @@ def _get_buildout_environment(self):
('id', '!=', self.id),
], order='create_date desc', limit=1)
if previous_build:
if log_build:
self._log(
'buildout',
'Using alternate objects from build #%(id)s' %
previous_build,
)
build_environment['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = ':'.join([
':'.join(glob.glob(
previous_build._path('parts', '*', '.git', 'objects')
Expand All @@ -280,7 +286,8 @@ def _get_buildout_environment(self):
@api.multi
def _get_buildout_build(self):
self.ensure_one()
buildout_branch = self.branch_id.buildout_branch_id
buildout_branch = self.branch_id.buildout_branch_id or\
self.branch_id.repo_id.buildout_branch_id
version = None
if not buildout_branch:
pi = self.branch_id._get_pull_info()
Expand All @@ -290,9 +297,7 @@ def _get_buildout_build(self):
buildout_branch = self.env['runbot.branch'].search([
('repo_id', '=', self.repo_id.id),
('buildout_version', '=', version),
], order='buildout_default desc, name asc')
if buildout_branch.filtered('buildout_default'):
buildout_branch = buildout_branch.filtered('buildout_default')
], order='name asc', limit=1)
buildout_build = self.search([
('repo_id', '=', self.repo_id.id),
('state', '=', 'done'),
Expand Down Expand Up @@ -408,6 +413,7 @@ def _adapt_buildout(self):
'merges =\n'
' git %(target_repo)s %(path)s %(target_commit)s\n'
'options.logfile = False\n'
'options.sentry_enabled = False\n'
'options.log_level = info\n'
'options.log_handler = :INFO\n'
'options.workers = 0\n'
Expand Down
8 changes: 8 additions & 0 deletions runbot_buildout/models/runbot_repo.py
Expand Up @@ -20,3 +20,11 @@ class RunbotRepo(models.Model):
default='odoo',
help='The buildout section you use to create your odoo instance'
)
buildout_branch_id = fields.Many2one(
'runbot.branch', 'Default buildout branch',
domain="[('repo_id', '=', id), ('buildout_version', '!=', False)]",
help='Set this to use the latest green build of this branch for '
'buildouts. Note you can set a specific buildout branch on branch '
'level too, so you should configure your testing buildout branch here,'
' and configure the production buildout for your production branch.',
)
6 changes: 3 additions & 3 deletions runbot_buildout/tests/test_runbot_buildout.py
Expand Up @@ -29,11 +29,11 @@ def _git(*args):
os.path.join(git_dir, 'buildout.cfg'), 'a'
) as buildout_cfg:
buildout_cfg.write(
'\naddons = git %s parts/test 9.0\n' % git_dir,
'\naddons = git %s parts/test 11.0\n' % git_dir,
)

_git('init')
_git('checkout', '-b', 'buildout-9.0-testing')
_git('checkout', '-b', 'buildout-11.0-testing')
_git('add', '.')
_git('commit', '-m', 'initial commit')

Expand All @@ -45,7 +45,7 @@ def _git(*args):
cls.repo._update(cls.repo)
cls.repo._scheduler(cls.repo.ids)

_git('checkout', '--orphan', '9.0')
_git('checkout', '--orphan', '11.0')
_git('commit', '-m', 'initial commit')

def test_00_buildout(self):
Expand Down
1 change: 0 additions & 1 deletion runbot_buildout/views/runbot_branch.xml
Expand Up @@ -5,7 +5,6 @@
<field name="inherit_id" ref="runbot.branch_form" />
<field name="arch" type="xml">
<field name="sticky" position="after">
<field name="buildout_default" attrs="{'invisible': [('buildout_version', '=', False)]}" />
<field name="buildout_branch_id" attrs="{'invisible': [('buildout_version', '=', True)]}" />
<field name="buildout_section" />
</field>
Expand Down
1 change: 1 addition & 0 deletions runbot_buildout/views/runbot_repo.xml
Expand Up @@ -8,6 +8,7 @@
<field name="uses_buildout" />
<field name="buildout_branch_pattern" attrs="{'invisible': [('uses_buildout', '=', False)]}" />
<field name="buildout_section" attrs="{'invisible': [('uses_buildout', '=', False)]}" />
<field name="buildout_branch_id" attrs="{'invisible': [('uses_buildout', '=', False)]}" />
</field>
<field name="dependency_ids" position="attributes">
<attribute name="attrs">{'invisible': [('uses_buildout', '=', True)]}</attribute>
Expand Down

0 comments on commit 49d175f

Please sign in to comment.