runbot fixes

- rebuild create a new build
- test pull head instead of merge
- move commit status to a function, to add support for pending
This commit is contained in:
Antony Lesuisse 2014-05-27 01:59:22 +02:00
parent 5423ea2394
commit c2ca8aeed9
2 changed files with 46 additions and 26 deletions

View File

@ -207,7 +207,7 @@ class runbot_repo(osv.osv):
run(['git', 'clone', '--bare', repo.name, repo.path])
else:
repo.git(['fetch', '-p', 'origin', '+refs/heads/*:refs/heads/*'])
repo.git(['fetch', '-p', 'origin', '+refs/pull/*/merge:refs/pull/*'])
repo.git(['fetch', '-p', 'origin', '+refs/pull/*/head:refs/pull/*'])
out = repo.git(['for-each-ref', '--format', '["%(refname)","%(objectname)","%(authordate:iso8601)"]', '--sort=-committerdate', 'refs/heads'])
refs = [simplejson.loads(i) for i in out.split('\n') if i]
out = repo.git(['for-each-ref', '--format', '["%(refname)","%(objectname)","%(authordate:iso8601)"]', '--sort=-committerdate', 'refs/pull'])
@ -458,6 +458,8 @@ class runbot_build(osv.osv):
# checkout branch
build.branch_id.repo_id.git_export(build.name, build.path())
# TODO use git log to get commit message date and author
# v6 rename bin -> openerp
if os.path.isdir(build.path('bin/addons')):
shutil.move(build.path('bin'), build.path('openerp'))
@ -533,6 +535,7 @@ class runbot_build(osv.osv):
def spawn(self, cmd, lock_path, log_path, cpu_limit=None, shell=False):
def preexec_fn():
os.setsid()
if cpu_limit:
# set soft cpulimit
soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
@ -547,6 +550,22 @@ class runbot_build(osv.osv):
p=subprocess.Popen(cmd, stdout=out, stderr=out, preexec_fn=preexec_fn, shell=shell)
return p.pid
def github_status(self, cr, uid, ids, context=None):
for build in self.browse(cr, uid, ids, context=context):
# try to update github
try:
state = "success" if build.result == 'ok' else "failure"
status = {
"state": state,
"target_url": "http://runbot.odoo.com/runbot/build/%s" % build.id,
"description": "runbot build %s (runtime %ss)" % (build.dest, build.job_time),
"context": "continuous-integration/runbot"
}
build.repo_id.github('/repos/:owner/:repo/statuses/%s' % build.name, status)
_logger.debug("github status %s update to %s", build.name, state)
except Exception, e:
_logger.exception("github status error")
def job_10_test_base(self, cr, uid, build, lock_path, log_path):
# checkout source
build.checkout()
@ -576,25 +595,12 @@ class runbot_build(osv.osv):
'job_end': time.strftime(openerp.tools.DEFAULT_SERVER_DATETIME_FORMAT, log_time),
'result': 'ko',
}
# TODO mark as failed too long post_install (after Modules loaded.)
if grep(log_all, "openerp.modules.loading: Modules loaded."):
if not grep(log_all, "FAIL"):
if not grep(build.path("openerp/test/common.py"), "post_install") or grep(log_all, "Initiating shutdown."):
v['result'] = "ok"
build.write(v)
# try to update github
try:
state = "success" if v['result'] == 'ok' else "failure"
status = {
"state": state,
"target_url": "http://runbot.odoo.com/runbot/build/%s" % build.name,
"description": "runbot build %s (runtime %ss)" % (build.dest, build.job_time),
"context": "continuous-integration/runbot"
}
build.repo_id.github('/repos/:owner/:repo/statuses/%s' % build.name, status)
_logger.debug("github status %s update to %s", build.name, state)
except Exception, e:
_logger.exception("github status error")
build.github_status()
# run server
cmd, mods = build.cmd()
@ -631,14 +637,18 @@ class runbot_build(osv.osv):
def force(self, cr, uid, ids, context=None):
for build in self.browse(cr, uid, ids, context=context):
if build.state in ['running']:
build.kill()
max_ids = self.search(cr, uid, [('repo_id','=',build.repo_id.id)], order='id desc', limit=1)
build.write({
'sequence':max_ids[0],
'state':'pending',
'result':'',
})
max_id = self.search(cr, uid, [('repo_id','=',build.repo_id.id)], order='id desc', limit=1)[0]
# Force it now
if build.state in ['pending']:
build.write({ 'sequence':max_id })
# or duplicate it
elif build.state in ['running']:
d = {
'branch_id': build.branch_id.id,
'name': build.name,
'sequence': max_id,
}
self.create(cr, 1, d)
return build.repo_id.id
def schedule(self, cr, uid, ids, context=None):
@ -828,8 +838,17 @@ class RunbotController(http.Controller):
return werkzeug.utils.redirect('/runbot/repo/%s' % repo_id)
# kill ` ps faux | grep ./static | awk '{print $2}' `
# ps faux| grep Cron | grep -v '_' | awk '{print $2}' | xargs kill
# ps faux| grep Cron | grep -- '-all' | awk '{print $2}' | xargs kill
# psql -l | grep " 000" | awk '{print $1}' | xargs -n1 dropdb
# TODO
# - cannibal branch
# - commit/pull more info
# - v6 support
# - host field in build
# - unlink build to remove ir_logging entires # ondelete=cascade
# - gc either build or only old ir_logging
# - if nginx server logfiles via each virtual server or map /runbot/static to root
# vim:

View File

@ -215,6 +215,7 @@
<div t-attf-class="btn-group {{klass}} pull-right">
<div t-attf-class="btn-group {{klass}}">
<a t-if="bu.state=='running'" t-attf-href="http://{{bu.domain}}/?db={{bu.dest}}-all" class="btn btn-primary"><i class="fa fa-sign-in"/></a>
<a t-attf-href="/runbot/build/{{bu.name}}" class="btn btn-default"><i class="fa fa-file-text-o"/></a>
<a t-attf-href="https://#{bu.repo_id.base}/commit/#{bu.name}" class="btn btn-default"><i class="fa fa-github"/></a>
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"/><span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">