Skip to content

Commit

Permalink
[REF] runbot_travis2docker: Skip builds if commit message has [ci ski…
Browse files Browse the repository at this point in the history
…p] (#117)
  • Loading branch information
hugho-ad authored and moylop260 committed Dec 26, 2016
1 parent 46e3998 commit 34a7bee
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
32 changes: 19 additions & 13 deletions runbot_travis2docker/models/runbot_build.py
Expand Up @@ -48,6 +48,8 @@ def custom_func(self, cr, uid, ids, context=None):
class RunbotBuild(models.Model):
_inherit = 'runbot.build'

SKIP_WORDS = ['[ci skip]', '[skip ci]']

dockerfile_path = fields.Char()
docker_image = fields.Char()
docker_container = fields.Char()
Expand All @@ -66,10 +68,9 @@ def job_10_test_base(self, cr, uid, build, lock_path, log_path):
if not build.branch_id.repo_id.is_travis2docker_build:
return super(RunbotBuild, self).job_10_test_base(
cr, uid, build, lock_path, log_path)
if not build.docker_image or not build.dockerfile_path \
or build.result == 'skipped':
_logger.info('docker build skipping job_10_test_base')
return MAGIC_PID_RUN_NEXT_JOB
skip = build.skip_check(cr, uid, build, context={})
if skip:
return skip
cmd = [
'docker', 'build',
"--no-cache",
Expand All @@ -83,10 +84,9 @@ def job_20_test_all(self, cr, uid, build, lock_path, log_path):
if not build.branch_id.repo_id.is_travis2docker_build:
return super(RunbotBuild, self).job_20_test_all(
cr, uid, build, lock_path, log_path)
if not build.docker_image or not build.dockerfile_path \
or build.result == 'skipped':
_logger.info('docker build skipping job_20_test_all')
return MAGIC_PID_RUN_NEXT_JOB
skip = build.skip_check(cr, uid, build, context={})
if skip:
return skip
run(['docker', 'rm', '-vf', build.docker_container])
pr_cmd_env = [
'-e', 'TRAVIS_PULL_REQUEST=' +
Expand Down Expand Up @@ -125,11 +125,9 @@ def job_30_run(self, cr, uid, build, lock_path, log_path):
if not build.branch_id.repo_id.is_travis2docker_build:
return super(RunbotBuild, self).job_30_run(
cr, uid, build, lock_path, log_path)
if not build.docker_image or not build.dockerfile_path \
or build.result == 'skipped':
_logger.info('docker build skipping job_30_run')
return MAGIC_PID_RUN_NEXT_JOB

skip = build.skip_check(cr, uid, build, context={})
if skip:
return skip
# Start copy and paste from original method (fix flake8)
log_all = build.path('logs', 'job_20_test_all.txt')
log_time = time.localtime(os.path.getmtime(log_all))
Expand Down Expand Up @@ -194,3 +192,11 @@ def _local_cleanup(self, cr, uid, ids, context=None):
if build.docker_container:
run(['docker', 'rm', '-f', build.docker_container])
run(['docker', 'rmi', '-f', build.docker_image])

def skip_check(self, cr, uid, build, context=None):
subject = build.subject.lower()
ci_skip = any([word in subject for word in self.SKIP_WORDS])
if (not (build.docker_image or build.dockerfile_path) or
build.result == 'skipped' or ci_skip):
_logger.info('docker build skipping job_10_test_base')
return MAGIC_PID_RUN_NEXT_JOB
34 changes: 34 additions & 0 deletions runbot_travis2docker/tests/test_runbot_build.py
Expand Up @@ -116,6 +116,40 @@ def test_jobs(self):
self.assertEqual(
self.build.result, u'ok', "Job result should be ok")

def test_jobs_ci_skip(self):
"""Test the [ci skip] feature"""
# 'Create build and run all jobs'
self.assertEqual(len(self.repo), 1, "Repo not found")
_logger.info("Repo update to get branches")
self.repo.update()

branch = self.branch_obj.create({
'repo_id': self.repo.id,
'name': 'refs/heads/fast-travis-oca',
'subject': '[CI SKIP] TEST SUBJECT'
})
self.assertEqual(len(branch), 1, "Branch not found")
self.build_obj.search([('branch_id', '=', branch.id)]).unlink()
self.build_obj.create({'branch_id': branch.id, 'name': 'HEAD'})
# runbot module has a inherit in create method
# but a "return id" is missed. Then we need to search it.
# https://github.com/odoo/odoo-extra/blob/038fd3e/runbot/runbot.py#L599
self.build = self.build_obj.search([('branch_id', '=', branch.id)],
limit=1)
self.assertEqual(len(self.build) == 0, False, "Build not found")

if self.build.state == 'done' and self.build.result == 'skipped':
# When the last commit of the repo is too old,
# runbot will skip this build then we are forcing it
self.build.force()

self.assertEqual(
self.build.state, u'skipped', "State should be skipped")

self.build.kill()
self.assertEqual(
self.build.state, u'done', "Job state should be done")

def connection_test(self, build, attempts=1, delay=0):
username = "admin"
password = "admin"
Expand Down

0 comments on commit 34a7bee

Please sign in to comment.