Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add auto_nacl_deps_bump.py for use as a cron job

This kicks off new try jobs using nacl_deps_bump.py if it sees a
sufficient number (or age) of new NaCl revisions.

Change nacl_deps_bump.py to override EDITOR so that it will run
non-interactively in most cases.
  • Loading branch information...
commit fc4be23dcb6c7e4b09285bf57cfc0b9f3afe521b 1 parent 2bcadd2
@mseaborn authored
Showing with 74 additions and 4 deletions.
  1. +66 −0 auto_nacl_deps_bump.py
  2. +8 −4 nacl_deps_bump.py
View
66 auto_nacl_deps_bump.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Native Client Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import re
+import subprocess
+import time
+
+import pysvn
+
+import nacl_deps_bump
+
+
+# When this number of new revisions accumulates, we kick off a new build.
+REVS_THRESHOLD = 10
+
+# When the last revision is this old, we kick off a new build.
+TIME_THRESHOLD = 60*60*12 # 12 hours
+
+
+def GetJobs():
+ proc = subprocess.Popen(['git', 'for-each-ref',
+ '--format', '%(refname:short)',
+ 'refs/heads/*'], stdout=subprocess.PIPE)
+ revs = []
+ for line in proc.stdout:
+ match = re.match('nacl-deps-r(\d+)$', line.strip())
+ if match is not None:
+ revs.append(int(match.group(1)))
+ assert proc.wait() == 0, proc.wait()
+ return revs
+
+
+def GetRevTime(svn_root, rev_num):
+ rev = pysvn.Revision(pysvn.opt_revision_kind.number, rev_num)
+ lst = pysvn.Client().log(svn_root, revision_start=rev, revision_end=rev)
+ assert len(lst) == 1, lst
+ return lst[0].date
+
+
+def Main():
+ last_tried_rev = max([1] + GetJobs())
+ print 'last tried NaCl revision is r%i' % last_tried_rev
+ age = time.time() - GetRevTime(nacl_deps_bump.nacl_svn_root, last_tried_rev)
+ print 'age of r%i: %.1f hours' % (last_tried_rev, age / (60 * 60))
+
+ newest_rev = nacl_deps_bump.GetNaClRev()
+ rev_diff = newest_rev - last_tried_rev
+ print '%i revisions since last try' % rev_diff
+
+ do_build = False
+ if age > TIME_THRESHOLD:
+ print 'time threshold passed: trigger new build'
+ do_build = True
+ # Note that this comparison ignores that the commits might be to
+ # branches rather the trunk.
+ if rev_diff > REVS_THRESHOLD:
+ print 'revision count threshold passed: trigger new build'
+ do_build = True
+ if do_build:
+ nacl_deps_bump.Main(['--revision', str(newest_rev)])
+
+
+if __name__ == '__main__':
+ Main()
View
12 nacl_deps_bump.py
@@ -5,6 +5,7 @@
import re
import optparse
+import os
import subprocess
import sys
import time
@@ -103,7 +104,7 @@ def GetLog(rev1, rev2):
return ''.join(got), authors
-def Main():
+def Main(args):
parser = optparse.OptionParser()
parser.add_option('-r', '--revision', default=None, type='int',
help='NaCl SVN revision to use (default is HEAD)')
@@ -115,7 +116,7 @@ def Main():
help='Do not run "git cl upload" (implies --no-try)')
parser.add_option('-T', '--no-try', action='store_true', default=False,
help='Do not start a trybot run')
- options, args = parser.parse_args()
+ options, args = parser.parse_args(args)
if len(args) != 0:
parser.error('Got unexpected arguments')
@@ -197,6 +198,9 @@ class DownloadOptions(object):
if options.no_upload:
return
+ # Override EDITOR so that "git cl upload" will run non-interactively.
+ environ = os.environ.copy()
+ environ['EDITOR'] = 'true'
# TODO: This can ask for credentials when the cached credentials
# expire, so could fail when automated. Can we fix that?
subprocess.check_call(['git', 'cl',
@@ -204,7 +208,7 @@ class DownloadOptions(object):
'-m', msg,
# This CC does not happen by default for DEPS.
'--cc', cc_list,
- ])
+ ], env=environ)
if options.no_try:
return
subprocess.check_call(['git', 'try',
@@ -213,4 +217,4 @@ class DownloadOptions(object):
if __name__ == '__main__':
- Main()
+ Main(sys.argv[1:])

0 comments on commit fc4be23

Please sign in to comment.
Something went wrong with that request. Please try again.