2 # Copyright 2013 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following
11 # disclaimer in the documentation and/or other materials provided
12 # with the distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived
15 # from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
36 from common_includes import *
39 SETTINGS_LOCATION = "SETTINGS_LOCATION"
42 PERSISTFILE_BASENAME: "/tmp/v8-auto-push-tempfile",
43 DOT_GIT_LOCATION: ".git",
44 SETTINGS_LOCATION: "~/.auto-roll",
47 PUSH_MESSAGE_RE = re.compile(r".* \(based on bleeding_edge revision r(\d+)\)$")
50 class Preparation(Step):
51 MESSAGE = "Preparation."
54 self.InitialEnvironmentChecks()
58 class CheckAutoPushSettings(Step):
59 MESSAGE = "Checking settings file."
62 settings_file = os.path.realpath(self.Config(SETTINGS_LOCATION))
63 if os.path.exists(settings_file):
64 settings_dict = json.loads(FileToText(settings_file))
65 if settings_dict.get("enable_auto_roll") is False:
66 self.Die("Push to trunk disabled by auto-roll settings file: %s"
70 class CheckTreeStatus(Step):
71 MESSAGE = "Checking v8 tree status message."
74 status_url = "https://v8-status.appspot.com/current?format=json"
75 status_json = self.ReadURL(status_url, wait_plan=[5, 20, 300, 300])
76 self["tree_message"] = json.loads(status_json)["message"]
77 if re.search(r"nopush|no push", self["tree_message"], flags=re.I):
78 self.Die("Push to trunk disabled by tree state: %s"
79 % self["tree_message"])
82 class FetchLKGR(Step):
83 MESSAGE = "Fetching V8 LKGR."
86 lkgr_url = "https://v8-status.appspot.com/lkgr"
87 # Retry several times since app engine might have issues.
88 self["lkgr"] = self.ReadURL(lkgr_url, wait_plan=[5, 20, 300, 300])
91 class CheckLastPush(Step):
92 MESSAGE = "Checking last V8 push to trunk."
95 last_push = self.FindLastTrunkPush()
97 # Retrieve the bleeding edge revision of the last push from the text in
98 # the push commit message.
99 last_push_title = self.GitLog(n=1, format="%s", git_hash=last_push)
100 last_push_be = PUSH_MESSAGE_RE.match(last_push_title).group(1)
102 if not last_push_be: # pragma: no cover
103 self.Die("Could not retrieve bleeding edge revision for trunk push %s"
106 # TODO(machenbach): This metric counts all revisions. It could be
107 # improved by counting only the revisions on bleeding_edge.
108 if int(self["lkgr"]) - int(last_push_be) < 10: # pragma: no cover
109 # This makes sure the script doesn't push twice in a row when the cron
110 # job retries several times.
111 self.Die("Last push too recently: %s" % last_push_be)
114 class PushToTrunk(Step):
115 MESSAGE = "Pushing to trunk if specified."
118 print "Pushing lkgr %s to trunk." % self["lkgr"]
120 # TODO(machenbach): Update the script before calling it.
121 if self._options.push:
122 P = push_to_trunk.PushToTrunk
123 self._side_effect_handler.Call(
124 P(push_to_trunk.CONFIG, self._side_effect_handler).Run,
125 ["--author", self._options.author,
126 "--reviewer", self._options.reviewer,
127 "--revision", self["lkgr"],
131 class AutoPush(ScriptsBase):
132 def _PrepareOptions(self, parser):
133 parser.add_argument("-p", "--push",
134 help="Push to trunk. Dry run if unspecified.",
135 default=False, action="store_true")
137 def _ProcessOptions(self, options):
138 if not options.author or not options.reviewer: # pragma: no cover
139 print "You need to specify author and reviewer."
141 options.requires_editor = False
147 CheckAutoPushSettings,
155 if __name__ == "__main__": # pragma: no cover
156 sys.exit(AutoPush(CONFIG).Run())