Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(929)

Side by Side Diff: tools/push-to-trunk/auto_roll.py

Issue 185653004: Experimental parser: merge to r19637 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/merge-to-branch.sh ('k') | tools/push-to-trunk/common_includes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 the V8 project authors. All rights reserved. 2 # Copyright 2013 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following 10 # copyright notice, this list of conditions and the following
11 # disclaimer in the documentation and/or other materials provided 11 # disclaimer in the documentation and/or other materials provided
12 # with the distribution. 12 # with the distribution.
13 # * Neither the name of Google Inc. nor the names of its 13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived 14 # contributors may be used to endorse or promote products derived
15 # from this software without specific prior written permission. 15 # from this software without specific prior written permission.
16 # 16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 import argparse
29 import json 30 import json
30 import optparse
31 import os 31 import os
32 import re 32 import re
33 import sys 33 import sys
34 import urllib 34 import urllib
35 35
36 from common_includes import * 36 from common_includes import *
37 import push_to_trunk 37 import push_to_trunk
38 from push_to_trunk import PushToTrunkOptions 38 from push_to_trunk import PushToTrunkOptions
39 from push_to_trunk import RunPushToTrunk 39 from push_to_trunk import RunPushToTrunk
40 40
41 SETTINGS_LOCATION = "SETTINGS_LOCATION" 41 SETTINGS_LOCATION = "SETTINGS_LOCATION"
42 42
43 CONFIG = { 43 CONFIG = {
44 PERSISTFILE_BASENAME: "/tmp/v8-auto-roll-tempfile", 44 PERSISTFILE_BASENAME: "/tmp/v8-auto-roll-tempfile",
45 DOT_GIT_LOCATION: ".git", 45 DOT_GIT_LOCATION: ".git",
46 SETTINGS_LOCATION: "~/.auto-roll", 46 SETTINGS_LOCATION: "~/.auto-roll",
47 } 47 }
48 48
49 49
50 class AutoRollOptions(CommonOptions): 50 class AutoRollOptions(CommonOptions):
51 def __init__(self, options): 51 def __init__(self, options):
52 super(AutoRollOptions, self).__init__(options) 52 super(AutoRollOptions, self).__init__(options)
53 self.requires_editor = False 53 self.requires_editor = False
54 self.status_password = options.status_password 54 self.status_password = options.status_password
55 self.r = options.r 55 self.chromium = options.chromium
56 self.c = options.c
57 self.push = getattr(options, 'push', False) 56 self.push = getattr(options, 'push', False)
57 self.author = getattr(options, 'author', None)
58 58
59 59
60 class Preparation(Step): 60 class Preparation(Step):
61 MESSAGE = "Preparation." 61 MESSAGE = "Preparation."
62 62
63 def RunStep(self): 63 def RunStep(self):
64 self.InitialEnvironmentChecks() 64 self.InitialEnvironmentChecks()
65 self.CommonPrepare() 65 self.CommonPrepare()
66 66
67 67
68 class CheckAutoRollSettings(Step): 68 class CheckAutoRollSettings(Step):
69 MESSAGE = "Checking settings file." 69 MESSAGE = "Checking settings file."
70 70
71 def RunStep(self): 71 def RunStep(self):
72 settings_file = os.path.realpath(self.Config(SETTINGS_LOCATION)) 72 settings_file = os.path.realpath(self.Config(SETTINGS_LOCATION))
73 if os.path.exists(settings_file): 73 if os.path.exists(settings_file):
74 settings_dict = json.loads(FileToText(settings_file)) 74 settings_dict = json.loads(FileToText(settings_file))
75 if settings_dict.get("enable_auto_roll") is False: 75 if settings_dict.get("enable_auto_roll") is False:
76 self.Die("Push to trunk disabled by auto-roll settings file: %s" 76 self.Die("Push to trunk disabled by auto-roll settings file: %s"
77 % settings_file) 77 % settings_file)
78 78
79 79
80 class CheckTreeStatus(Step): 80 class CheckTreeStatus(Step):
81 MESSAGE = "Checking v8 tree status message." 81 MESSAGE = "Checking v8 tree status message."
82 82
83 def RunStep(self): 83 def RunStep(self):
84 status_url = "https://v8-status.appspot.com/current?format=json" 84 status_url = "https://v8-status.appspot.com/current?format=json"
85 status_json = self.ReadURL(status_url, wait_plan=[5, 20, 300, 300]) 85 status_json = self.ReadURL(status_url, wait_plan=[5, 20, 300, 300])
86 message = json.loads(status_json)["message"] 86 self["tree_message"] = json.loads(status_json)["message"]
87 if re.search(r"nopush|no push", message, flags=re.I): 87 if re.search(r"nopush|no push", self["tree_message"], flags=re.I):
88 self.Die("Push to trunk disabled by tree state: %s" % message) 88 self.Die("Push to trunk disabled by tree state: %s"
89 self.Persist("tree_message", message) 89 % self["tree_message"])
90 90
91 91
92 class FetchLatestRevision(Step): 92 class FetchLatestRevision(Step):
93 MESSAGE = "Fetching latest V8 revision." 93 MESSAGE = "Fetching latest V8 revision."
94 94
95 def RunStep(self): 95 def RunStep(self):
96 log = self.Git("svn log -1 --oneline").strip() 96 match = re.match(r"^r(\d+) ", self.GitSVNLog())
97 match = re.match(r"^r(\d+) ", log)
98 if not match: 97 if not match:
99 self.Die("Could not extract current svn revision from log.") 98 self.Die("Could not extract current svn revision from log.")
100 self.Persist("latest", match.group(1)) 99 self["latest"] = match.group(1)
101 100
102 101
103 class CheckLastPush(Step): 102 class CheckLastPush(Step):
104 MESSAGE = "Checking last V8 push to trunk." 103 MESSAGE = "Checking last V8 push to trunk."
105 104
106 def RunStep(self): 105 def RunStep(self):
107 self.RestoreIfUnset("latest") 106 last_push_hash = self.FindLastTrunkPush()
108 log = self.Git("svn log -1 --oneline ChangeLog").strip() 107 last_push = int(self.GitSVNFindSVNRev(last_push_hash))
109 match = re.match(r"^r(\d+) \| Prepare push to trunk", log) 108
110 if match: 109 # TODO(machenbach): This metric counts all revisions. It could be
111 latest = int(self._state["latest"]) 110 # improved by counting only the revisions on bleeding_edge.
112 last_push = int(match.group(1)) 111 if int(self["latest"]) - last_push < 10:
113 # TODO(machebach): This metric counts all revisions. It could be 112 # This makes sure the script doesn't push twice in a row when the cron
114 # improved by counting only the revisions on bleeding_edge. 113 # job retries several times.
115 if latest - last_push < 10: 114 self.Die("Last push too recently: %d" % last_push)
116 # This makes sure the script doesn't push twice in a row when the cron
117 # job retries several times.
118 self.Die("Last push too recently: %d" % last_push)
119 115
120 116
121 class FetchLKGR(Step): 117 class FetchLKGR(Step):
122 MESSAGE = "Fetching V8 LKGR." 118 MESSAGE = "Fetching V8 LKGR."
123 119
124 def RunStep(self): 120 def RunStep(self):
125 lkgr_url = "https://v8-status.appspot.com/lkgr" 121 lkgr_url = "https://v8-status.appspot.com/lkgr"
126 # Retry several times since app engine might have issues. 122 # Retry several times since app engine might have issues.
127 self.Persist("lkgr", self.ReadURL(lkgr_url, wait_plan=[5, 20, 300, 300])) 123 self["lkgr"] = self.ReadURL(lkgr_url, wait_plan=[5, 20, 300, 300])
128 124
129 125
130 class PushToTrunk(Step): 126 class PushToTrunk(Step):
131 MESSAGE = "Pushing to trunk if possible." 127 MESSAGE = "Pushing to trunk if possible."
132 128
133 def PushTreeStatus(self, message): 129 def PushTreeStatus(self, message):
134 if not self._options.status_password: 130 if not self._options.status_password:
135 print "Skipping tree status update without password file." 131 print "Skipping tree status update without password file."
136 return 132 return
137 params = { 133 params = {
138 "message": message, 134 "message": message,
139 "username": "v8-auto-roll@chromium.org", 135 "username": "v8-auto-roll@chromium.org",
140 "password": FileToText(self._options.status_password).strip(), 136 "password": FileToText(self._options.status_password).strip(),
141 } 137 }
142 params = urllib.urlencode(params) 138 params = urllib.urlencode(params)
143 print "Pushing tree status: '%s'" % message 139 print "Pushing tree status: '%s'" % message
144 self.ReadURL("https://v8-status.appspot.com/status", params, 140 self.ReadURL("https://v8-status.appspot.com/status", params,
145 wait_plan=[5, 20]) 141 wait_plan=[5, 20])
146 142
147 def RunStep(self): 143 def RunStep(self):
148 self.RestoreIfUnset("latest") 144 latest = int(self["latest"])
149 self.RestoreIfUnset("lkgr") 145 lkgr = int(self["lkgr"])
150 self.RestoreIfUnset("tree_message")
151 latest = int(self._state["latest"])
152 lkgr = int(self._state["lkgr"])
153 if latest == lkgr: 146 if latest == lkgr:
154 print "ToT (r%d) is clean. Pushing to trunk." % latest 147 print "ToT (r%d) is clean. Pushing to trunk." % latest
155 self.PushTreeStatus("Tree is closed (preparing to push)") 148 self.PushTreeStatus("Tree is closed (preparing to push)")
156 149
157 # TODO(machenbach): Call push to trunk script.
158 # TODO(machenbach): Update the script before calling it. 150 # TODO(machenbach): Update the script before calling it.
159 try: 151 try:
160 if self._options.push: 152 if self._options.push:
161 self._side_effect_handler.Call( 153 self._side_effect_handler.Call(
162 RunPushToTrunk, 154 RunPushToTrunk,
163 push_to_trunk.CONFIG, 155 push_to_trunk.CONFIG,
164 PushToTrunkOptions.MakeForcedOptions(self._options.r, 156 PushToTrunkOptions.MakeForcedOptions(self._options.author,
165 self._options.c), 157 self._options.reviewer,
158 self._options.chromium),
166 self._side_effect_handler) 159 self._side_effect_handler)
167 finally: 160 finally:
168 self.PushTreeStatus(self._state["tree_message"]) 161 self.PushTreeStatus(self["tree_message"])
169 else: 162 else:
170 print("ToT (r%d) is ahead of the LKGR (r%d). Skipping push to trunk." 163 print("ToT (r%d) is ahead of the LKGR (r%d). Skipping push to trunk."
171 % (latest, lkgr)) 164 % (latest, lkgr))
172 165
173 166
174 def RunAutoRoll(config, 167 def RunAutoRoll(config,
175 options, 168 options,
176 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER): 169 side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER):
177 step_classes = [ 170 step_classes = [
178 Preparation, 171 Preparation,
179 CheckAutoRollSettings, 172 CheckAutoRollSettings,
180 CheckTreeStatus, 173 CheckTreeStatus,
181 FetchLatestRevision, 174 FetchLatestRevision,
182 CheckLastPush, 175 CheckLastPush,
183 FetchLKGR, 176 FetchLKGR,
184 PushToTrunk, 177 PushToTrunk,
185 ] 178 ]
186 RunScript(step_classes, config, options, side_effect_handler) 179 RunScript(step_classes, config, options, side_effect_handler)
187 180
188 181
189 def BuildOptions(): 182 def BuildOptions():
190 result = optparse.OptionParser() 183 parser = argparse.ArgumentParser()
191 result.add_option("-c", "--chromium", dest="c", 184 parser.add_argument("-a", "--author",
192 help=("Specify the path to your Chromium src/ " 185 help="The author email used for rietveld.")
193 "directory to automate the V8 roll.")) 186 parser.add_argument("-c", "--chromium",
194 result.add_option("-p", "--push", 187 help=("The path to your Chromium src/ directory to "
195 help="Push to trunk if possible. Dry run if unspecified.", 188 "automate the V8 roll."))
196 default=False, action="store_true") 189 parser.add_argument("-p", "--push",
197 result.add_option("-r", "--reviewer", dest="r", 190 help="Push to trunk if possible. Dry run if unspecified.",
198 help=("Specify the account name to be used for reviews.")) 191 default=False, action="store_true")
199 result.add_option("-s", "--step", dest="s", 192 parser.add_argument("-r", "--reviewer",
200 help="Specify the step where to start work. Default: 0.", 193 help="The account name to be used for reviews.")
201 default=0, type="int") 194 parser.add_argument("-s", "--step",
202 result.add_option("--status-password", 195 help="Specify the step where to start work. Default: 0.",
203 help="A file with the password to the status app.") 196 default=0, type=int)
204 return result 197 parser.add_argument("--status-password",
198 help="A file with the password to the status app.")
199 return parser
205 200
206 201
207 def Main(): 202 def Main():
208 parser = BuildOptions() 203 parser = BuildOptions()
209 (options, args) = parser.parse_args() 204 options = parser.parse_args()
210 if not options.c or not options.r: 205 if not options.author or not options.chromium or not options.reviewer:
211 print "You need to specify the chromium src location and a reviewer." 206 print "You need to specify author, chromium src location and reviewer."
212 parser.print_help() 207 parser.print_help()
213 return 1 208 return 1
214 RunAutoRoll(CONFIG, AutoRollOptions(options)) 209 RunAutoRoll(CONFIG, AutoRollOptions(options))
215 210
216 if __name__ == "__main__": 211 if __name__ == "__main__":
217 sys.exit(Main()) 212 sys.exit(Main())
OLDNEW
« no previous file with comments | « tools/merge-to-branch.sh ('k') | tools/push-to-trunk/common_includes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698