auto_roll.py 8.21 KB
Newer Older
1 2 3 4 5
#!/usr/bin/env python
# Copyright 2014 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

6 7 8
# for py2/py3 compatibility
from __future__ import print_function

9 10 11 12 13
import argparse
import os
import sys

from common_includes import *
14 15 16 17 18 19

ROLL_SUMMARY = ("Summary of changes available at:\n"
                "https://chromium.googlesource.com/v8/v8/+log/%s..%s")

ISSUE_MSG = (
"""Please follow these instructions for assigning/CC'ing issues:
20
https://v8.dev/docs/triage-issues
21 22 23

Please close rolling in case of a roll revert:
https://v8-roll.appspot.com/
24 25
This only works with a Google account.

26 27 28 29 30
CQ_INCLUDE_TRYBOTS=luci.chromium.try:linux-blink-rel
CQ_INCLUDE_TRYBOTS=luci.chromium.try:linux_optional_gpu_tests_rel
CQ_INCLUDE_TRYBOTS=luci.chromium.try:mac_optional_gpu_tests_rel
CQ_INCLUDE_TRYBOTS=luci.chromium.try:win_optional_gpu_tests_rel
CQ_INCLUDE_TRYBOTS=luci.chromium.try:android_optional_gpu_tests_rel""")
31 32 33 34 35

class Preparation(Step):
  MESSAGE = "Preparation."

  def RunStep(self):
36
    self['json_output']['monitoring_state'] = 'preparation'
37 38 39
    # Update v8 remote tracking branches.
    self.GitFetchOrigin()
    self.Git("fetch origin +refs/tags/*:refs/tags/*")
40 41 42 43 44 45


class DetectLastRoll(Step):
  MESSAGE = "Detect commit ID of the last Chromium roll."

  def RunStep(self):
46
    self['json_output']['monitoring_state'] = 'detect_last_roll'
47 48 49
    self["last_roll"] = self._options.last_roll
    if not self["last_roll"]:
      # Interpret the DEPS file to retrieve the v8 revision.
50
      # TODO(machenbach): This should be part or the setdep api of
51 52 53 54 55 56 57 58 59 60 61 62 63 64
      # depot_tools.
      Var = lambda var: '%s'
      exec(FileToText(os.path.join(self._options.chromium, "DEPS")))

      # The revision rolled last.
      self["last_roll"] = vars['v8_revision']
    self["last_version"] = self.GetVersionTag(self["last_roll"])
    assert self["last_version"], "The last rolled v8 revision is not tagged."


class DetectRevisionToRoll(Step):
  MESSAGE = "Detect commit ID of the V8 revision to roll."

  def RunStep(self):
65
    self['json_output']['monitoring_state'] = 'detect_revision'
66 67 68 69 70 71
    self["roll"] = self._options.revision
    if self["roll"]:
      # If the revision was passed on the cmd line, continue script execution
      # in the next step.
      return False

72 73 74 75 76
    # The revision that should be rolled. Check for the latest of the most
    # recent releases based on commit timestamp.
    revisions = self.GetRecentReleases(
        max_age=self._options.max_age * DAY_IN_SECONDS)
    assert revisions, "Didn't find any recent release."
77

78 79 80 81 82 83
    # There must be some progress between the last roll and the new candidate
    # revision (i.e. we don't go backwards). The revisions are ordered newest
    # to oldest. It is possible that the newest timestamp has no progress
    # compared to the last roll, i.e. if the newest release is a cherry-pick
    # on a release branch. Then we look further.
    for revision in revisions:
84 85 86
      version = self.GetVersionTag(revision)
      assert version, "Internal error. All recent releases should have a tag"

87
      if SortingKey(self["last_version"]) < SortingKey(version):
88 89 90
        self["roll"] = revision
        break
    else:
91
      print("There is no newer v8 revision than the one in Chromium (%s)."
92
            % self["last_roll"])
93
      self['json_output']['monitoring_state'] = 'up_to_date'
94 95 96
      return True


97 98 99 100
class PrepareRollCandidate(Step):
  MESSAGE = "Robustness checks of the roll candidate."

  def RunStep(self):
101
    self['json_output']['monitoring_state'] = 'prepare_candidate'
102 103 104 105 106 107 108 109 110 111 112 113 114 115
    self["roll_title"] = self.GitLog(n=1, format="%s",
                                     git_hash=self["roll"])

    # Make sure the last roll and the roll candidate are releases.
    version = self.GetVersionTag(self["roll"])
    assert version, "The revision to roll is not tagged."
    version = self.GetVersionTag(self["last_roll"])
    assert version, "The revision used as last roll is not tagged."


class SwitchChromium(Step):
  MESSAGE = "Switch to Chromium checkout."

  def RunStep(self):
116
    self['json_output']['monitoring_state'] = 'switch_chromium'
117 118 119 120 121 122 123 124 125 126 127 128
    cwd = self._options.chromium
    self.InitialEnvironmentChecks(cwd)
    # Check for a clean workdir.
    if not self.GitIsWorkdirClean(cwd=cwd):  # pragma: no cover
      self.Die("Workspace is not clean. Please commit or undo your changes.")
    # Assert that the DEPS file is there.
    if not os.path.exists(os.path.join(cwd, "DEPS")):  # pragma: no cover
      self.Die("DEPS file not present.")


class UpdateChromiumCheckout(Step):
  MESSAGE = "Update the checkout and create a new branch."
129 130

  def RunStep(self):
131
    self['json_output']['monitoring_state'] = 'update_chromium'
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    cwd = self._options.chromium
    self.GitCheckout("master", cwd=cwd)
    self.DeleteBranch("work-branch", cwd=cwd)
    self.GitPull(cwd=cwd)

    # Update v8 remotes.
    self.GitFetchOrigin()

    self.GitCreateBranch("work-branch", cwd=cwd)


class UploadCL(Step):
  MESSAGE = "Create and upload CL."

  def RunStep(self):
147
    self['json_output']['monitoring_state'] = 'upload'
148 149
    cwd = self._options.chromium
    # Patch DEPS file.
150
    if self.Command("gclient", "setdep -r src/v8@%s" %
151 152 153 154 155 156 157 158 159 160
                    self["roll"], cwd=cwd) is None:
      self.Die("Failed to create deps for %s" % self["roll"])

    message = []
    message.append("Update V8 to %s." % self["roll_title"].lower())

    message.append(
        ROLL_SUMMARY % (self["last_roll"][:8], self["roll"][:8]))

    message.append(ISSUE_MSG)
161

162
    message.append("TBR=%s" % self._options.reviewer)
163 164
    self.GitCommit("\n\n".join(message),  author=self._options.author, cwd=cwd)
    if not self._options.dry_run:
165
      self.GitUpload(force=True,
166
                     bypass_hooks=True,
167
                     cq=self._options.use_commit_queue,
168
                     cq_dry_run=self._options.use_dry_run,
169
                     cwd=cwd)
170
      print("CL uploaded.")
171
    else:
172
      print("Dry run - don't upload.")
173 174 175 176 177 178 179 180

    self.GitCheckout("master", cwd=cwd)
    self.GitDeleteBranch("work-branch", cwd=cwd)

class CleanUp(Step):
  MESSAGE = "Done!"

  def RunStep(self):
181
    self['json_output']['monitoring_state'] = 'success'
182 183 184 185 186 187
    print("Congratulations, you have successfully rolled %s into "
          "Chromium."
          % self["roll"])

    # Clean up all temporary files.
    Command("rm", "-f %s*" % self._config["PERSISTFILE_BASENAME"])
188 189 190 191 192 193 194


class AutoRoll(ScriptsBase):
  def _PrepareOptions(self, parser):
    parser.add_argument("-c", "--chromium", required=True,
                        help=("The path to your Chromium src/ "
                              "directory to automate the V8 roll."))
195 196 197
    parser.add_argument("--last-roll",
                        help="The git commit ID of the last rolled version. "
                             "Auto-detected if not specified.")
198
    parser.add_argument("--max-age", default=7, type=int,
199
                        help="Maximum age in days of the latest release.")
200 201 202 203 204
    parser.add_argument("--revision",
                        help="Revision to roll. Auto-detected if not "
                             "specified."),
    parser.add_argument("--roll", help="Deprecated.",
                        default=True, action="store_true")
205 206 207 208 209 210 211
    group = parser.add_mutually_exclusive_group()
    group.add_argument("--use-commit-queue",
                       help="Trigger the CQ full run on upload.",
                       default=False, action="store_true")
    group.add_argument("--use-dry-run",
                       help="Trigger the CQ dry run on upload.",
                       default=True, action="store_true")
212 213

  def _ProcessOptions(self, options):  # pragma: no cover
214
    if not options.author or not options.reviewer:
215
      print("A reviewer (-r) and an author (-a) are required.")
216
      return False
217 218 219 220

    options.requires_editor = False
    options.force = True
    options.manual = False
221 222
    return True

223 224
  def _Config(self):
    return {
225
      "PERSISTFILE_BASENAME": "/tmp/v8-chromium-roll-tempfile",
226 227
    }

228 229
  def _Steps(self):
    return [
230
      Preparation,
231
      DetectLastRoll,
232 233 234 235 236 237
      DetectRevisionToRoll,
      PrepareRollCandidate,
      SwitchChromium,
      UpdateChromiumCheckout,
      UploadCL,
      CleanUp,
238 239 240 241
    ]


if __name__ == "__main__":  # pragma: no cover
242
  sys.exit(AutoRoll().Run())