Reviewers: ulan,

Message:
PTAL

Description:
Add last-push check to automatic push-to-trunk script.

Make sure the script is not trying a push-to-trunk twice in a row.

This also passes through some command line parameters.

TEST=python -m unittest test_scripts.ScriptTest.testCheckLastPushRecently

Please review this at https://codereview.chromium.org/103533003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+45, -3 lines):
  M tools/push-to-trunk/auto_roll.py
  M tools/push-to-trunk/test_scripts.py


Index: tools/push-to-trunk/auto_roll.py
diff --git a/tools/push-to-trunk/auto_roll.py b/tools/push-to-trunk/auto_roll.py index fa65ee2dbdb8e47a4e29a8b9fcf5256652fb8d5d..8f26a49cb3ca9dcfd99f08080aa9f02aca72e4da 100755
--- a/tools/push-to-trunk/auto_roll.py
+++ b/tools/push-to-trunk/auto_roll.py
@@ -57,6 +57,24 @@ class FetchLatestRevision(Step):
     self.Persist("latest", match.group(1))


+class CheckLastPush(Step):
+  MESSAGE = "Checking last V8 push to trunk."
+
+  def RunStep(self):
+    self.RestoreIfUnset("latest")
+    log = self.Git("svn log -1 --oneline ChangeLog").strip()
+    match = re.match(r"^r(\d+) \| Prepare push to trunk", log)
+    if match:
+      latest = int(self._state["latest"])
+      last_push = int(match.group(1))
+      # TODO(machebach): This metric counts all revisions. It could be
+      # improved by counting only the revisions on bleeding_edge.
+      if latest - last_push < 10:
+ # This makes sure the script doesn't push twice in a row when the cron
+        # job retries several times.
+        self.Die("Last push too recently: %d" % last_push)
+
+
 class FetchLKGR(Step):
   MESSAGE = "Fetching V8 LKGR."

@@ -77,6 +95,10 @@ class PushToTrunk(Step):
     if latest == lkgr:
       print "ToT (r%d) is clean. Pushing to trunk." % latest
       # TODO(machenbach): Call push to trunk script.
+      # TODO(machenbach): Update the script before calling it.
+      # self._side_effect_handler.Command(
+      #     "tools/push-to-trunk/push-to-trunk.py",
+      #     "-f -c %s -r %s" % (self._options.c, self._options.r))
     else:
       print("ToT (r%d) is ahead of the LKGR (r%d). Skipping push to trunk."
             % (latest, lkgr))
@@ -88,6 +110,7 @@ def RunAutoRoll(config,
   step_classes = [
     Preparation,
     FetchLatestRevision,
+    CheckLastPush,
     FetchLKGR,
     PushToTrunk,
   ]
@@ -96,9 +119,11 @@ def RunAutoRoll(config,

 def BuildOptions():
   result = optparse.OptionParser()
-  result.add_option("-f", "--force", dest="f",
-                    help="Don't prompt the user.",
-                    default=True, action="store_true")
+  result.add_option("-c", "--chromium", dest="c",
+                    help=("Specify the path to your Chromium src/ "
+                          "directory to automate the V8 roll."))
+  result.add_option("-r", "--reviewer", dest="r",
+ help=("Specify the account name to be used for reviews."))
   result.add_option("-s", "--step", dest="s",
help="Specify the step where to start work. Default: 0.",
                     default=0, type="int")
@@ -108,6 +133,10 @@ def BuildOptions():
 def Main():
   parser = BuildOptions()
   (options, args) = parser.parse_args()
+  if not options.c or not options.r:
+    print "You need to specify the chromium src location and a reviewer."
+    parser.print_help()
+    return 1
   RunAutoRoll(CONFIG, options)

 if __name__ == "__main__":
Index: tools/push-to-trunk/test_scripts.py
diff --git a/tools/push-to-trunk/test_scripts.py b/tools/push-to-trunk/test_scripts.py index ce90192dc19ac5fd572e6b826b9c0c4dae59f70e..8c0739770d0178fb7857ca0da4a3c36a767bf7f6 100644
--- a/tools/push-to-trunk/test_scripts.py
+++ b/tools/push-to-trunk/test_scripts.py
@@ -35,6 +35,8 @@ from common_includes import *
 import push_to_trunk
 from push_to_trunk import *
 import auto_roll
+from auto_roll import FetchLatestRevision
+from auto_roll import CheckLastPush


 TEST_CONFIG = {
@@ -709,6 +711,16 @@ class ScriptTest(unittest.TestCase):
   def testPushToTrunkForced(self):
     self._PushToTrunk(force=True)

+  def testCheckLastPushRecently(self):
+    self.ExpectGit([
+      ["svn log -1 --oneline", "r101 | Text"],
+      ["svn log -1 --oneline ChangeLog", "r99 | Prepare push to trunk..."],
+    ])
+
+    state = {}
+    self.MakeStep(FetchLatestRevision, state=state).Run()
+ self.assertRaises(Exception, self.MakeStep(CheckLastPush, state=state).Run)
+
   def testAutoRoll(self):
     TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()

@@ -722,6 +734,7 @@ class ScriptTest(unittest.TestCase):
       ["status -s -b -uno", "## some_branch\n"],
       ["svn fetch", ""],
       ["svn log -1 --oneline", "r101 | Text"],
+      ["svn log -1 --oneline ChangeLog", "r65 | Prepare push to trunk..."],
     ])

     auto_roll.RunAutoRoll(TEST_CONFIG, MakeOptions(m=False, f=True), self)


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to