Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2017 The ChromiumOS Authors |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Ben Pastene | 6a8361a | 2021-08-19 19:52:05 -0700 | [diff] [blame] | 5 | """Update the CHROMEOS_LKGM file in a chromium repository. |
| 6 | |
Jack Neus | 51d2e34 | 2022-09-14 16:40:08 +0000 | [diff] [blame] | 7 | This script will upload an LKGM CL and potentially submit it to the CQ. |
Ben Pastene | 6a8361a | 2021-08-19 19:52:05 -0700 | [diff] [blame] | 8 | """ |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 9 | |
Chris McDonald | 59650c3 | 2021-07-20 15:29:28 -0600 | [diff] [blame] | 10 | import logging |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 11 | from typing import Optional |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 12 | |
Ram Chandrasekar | 60f69f3 | 2022-06-03 22:49:30 +0000 | [diff] [blame] | 13 | from chromite.lib import chromeos_version |
Achuith Bhandarkar | f561c15 | 2018-08-27 19:05:39 -0700 | [diff] [blame] | 14 | from chromite.lib import commandline |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 15 | from chromite.lib import constants |
Ben Pastene | 5a40b10 | 2019-11-22 17:06:31 -0800 | [diff] [blame] | 16 | from chromite.lib import gerrit |
Ben Pastene | 769b121 | 2021-12-14 18:26:50 -0800 | [diff] [blame] | 17 | from chromite.lib import gob_util |
Anuj Jamwal | 258529f | 2023-09-08 17:32:55 +0000 | [diff] [blame] | 18 | from chromite.utils import hostname_util |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 19 | |
| 20 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 21 | # Gerrit hashtag for the LKGM Uprev CLs. |
| 22 | HASHTAG = "chrome-lkgm" |
| 23 | |
| 24 | |
Ben Pastene | 3ae39bd | 2022-01-04 15:20:05 -0800 | [diff] [blame] | 25 | class LKGMNotValid(Exception): |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 26 | """The LKGM version is unset or not newer than the current value.""" |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 27 | |
| 28 | |
Ben Pastene | 3ae39bd | 2022-01-04 15:20:05 -0800 | [diff] [blame] | 29 | class LKGMFileNotFound(Exception): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 30 | """Raised if the LKGM file is not found.""" |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 31 | |
| 32 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 33 | class ChromeLKGMCleaner: |
| 34 | """Responsible for cleaning up the existing LKGM CLs if necessary. |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 35 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 36 | In Particular, this class does: |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 37 | - abandoning the obsolete CLs |
| 38 | - rebasing the merge-conflicted CLs |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 39 | """ |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 40 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 41 | def __init__( |
| 42 | self, |
| 43 | branch: str, |
| 44 | current_lkgm: chromeos_version.VersionInfo, |
| 45 | user_email: str, |
| 46 | dryrun: bool = False, |
| 47 | buildbucket_id: Optional[str] = None, |
| 48 | ): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 49 | self._dryrun = dryrun |
| 50 | self._branch = branch |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 51 | self._gerrit_helper = gerrit.GetCrosExternal() |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 52 | self._buildbucket_id = buildbucket_id |
Ben Pastene | 3ae39bd | 2022-01-04 15:20:05 -0800 | [diff] [blame] | 53 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 54 | self._user_email = user_email |
Achuith Bhandarkar | ec8d7a7 | 2018-03-01 16:56:22 -0800 | [diff] [blame] | 55 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 56 | # Strip any chrome branch from the lkgm version. |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 57 | self._current_lkgm = current_lkgm |
Achuith Bhandarkar | dc3a351 | 2018-03-16 15:10:57 -0700 | [diff] [blame] | 58 | |
Yoshiki Iguchi | ab2c4c2 | 2022-09-22 18:43:21 +0900 | [diff] [blame] | 59 | def ProcessObsoleteLKGMRolls(self): |
| 60 | """Clean up all obsolete LKGM roll CLs by abandoning or rebasing. |
Ben Pastene | 5a40b10 | 2019-11-22 17:06:31 -0800 | [diff] [blame] | 61 | |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 62 | This method finds the LKGM roll CLs that were trying changing to an |
| 63 | older version than the current LKGM version, and abandons them. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 64 | """ |
| 65 | query_params = { |
| 66 | "project": constants.CHROMIUM_SRC_PROJECT, |
| 67 | "branch": self._branch, |
| 68 | "file": constants.PATH_TO_CHROME_LKGM, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 69 | "status": "open", |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 70 | "hashtag": HASHTAG, |
| 71 | # Use 'owner' rather than 'uploader' or 'author' since those last |
| 72 | # two can be overwritten when the gardener resolves a merge-conflict |
| 73 | # and uploads a new patchset. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 74 | "owner": self._user_email, |
| 75 | } |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 76 | open_changes = self._gerrit_helper.Query(**query_params) |
| 77 | if not open_changes: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 78 | logging.info("No old LKGM rolls detected.") |
| 79 | return |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 80 | |
| 81 | logging.info( |
| 82 | "Retrieved the current LKGM version: %s", |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 83 | self._current_lkgm.VersionString(), |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 84 | ) |
| 85 | |
| 86 | build_link = "" |
| 87 | if self._buildbucket_id: |
| 88 | build_link = ( |
| 89 | "\nUpdated by" |
| 90 | f" https://ci.chromium.org/b/{self._buildbucket_id}\n" |
| 91 | ) |
| 92 | |
| 93 | for change in open_changes: |
| 94 | logging.info( |
| 95 | "Found a open LKGM roll CL: %s (crrev.com/c/%s).", |
| 96 | change.subject, |
| 97 | change.gerrit_number, |
| 98 | ) |
Yoshiki Iguchi | ab2c4c2 | 2022-09-22 18:43:21 +0900 | [diff] [blame] | 99 | |
| 100 | # Retrieve the version that this CL tries to roll to. |
| 101 | roll_to_string = change.GetFileContents( |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 102 | constants.PATH_TO_CHROME_LKGM |
| 103 | ) |
Yoshiki Iguchi | ab2c4c2 | 2022-09-22 18:43:21 +0900 | [diff] [blame] | 104 | if roll_to_string is None: |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 105 | logging.info("=> No LKGM change found in this CL.") |
| 106 | continue |
| 107 | |
Yoshiki Iguchi | ab2c4c2 | 2022-09-22 18:43:21 +0900 | [diff] [blame] | 108 | roll_to = chromeos_version.VersionInfo(roll_to_string) |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 109 | if roll_to <= self._current_lkgm: |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 110 | # The target version that the CL is changing to is older than |
| 111 | # the current. The roll CL is useless so that it'd be abandoned. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 112 | logging.info( |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 113 | "=> This CL is an older LKGM roll than current: Abandoning" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 114 | ) |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 115 | if not self._dryrun: |
| 116 | abandon_message = ( |
| 117 | "The newer LKGM" |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 118 | f" ({self._current_lkgm.VersionString()}) roll than" |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 119 | f" this CL has been landed.{build_link}" |
| 120 | ) |
| 121 | self._gerrit_helper.AbandonChange( |
| 122 | change, |
| 123 | msg=abandon_message, |
| 124 | ) |
Yoshiki Iguchi | ab2c4c2 | 2022-09-22 18:43:21 +0900 | [diff] [blame] | 125 | continue |
| 126 | |
| 127 | mergeable = change.IsMergeable() |
| 128 | if mergeable is None: |
| 129 | logging.info("=> Failed to get the mergeable state of the CL.") |
| 130 | continue |
| 131 | |
| 132 | # This CL may be in "merge conflict" state. Resolve. |
| 133 | if not mergeable: |
| 134 | # Retrieve the version that this CL tries to roll from. |
| 135 | roll_from_string = change.GetOriginalFileContents( |
| 136 | constants.PATH_TO_CHROME_LKGM |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 137 | ) |
Yoshiki Iguchi | ab2c4c2 | 2022-09-22 18:43:21 +0900 | [diff] [blame] | 138 | roll_from = chromeos_version.VersionInfo( |
| 139 | roll_from_string.strip() |
| 140 | ) |
| 141 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 142 | if roll_from == self._current_lkgm: |
Yoshiki Iguchi | ab2c4c2 | 2022-09-22 18:43:21 +0900 | [diff] [blame] | 143 | # The CL should not be in the merge-conflict state. |
| 144 | # mergeable=False might come from other reason. |
| 145 | logging.info( |
| 146 | "=> This CL tries to roll from the same LKGM. " |
| 147 | "Doing nothing." |
| 148 | ) |
| 149 | continue |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 150 | elif roll_from >= self._current_lkgm: |
Yoshiki Iguchi | ab2c4c2 | 2022-09-22 18:43:21 +0900 | [diff] [blame] | 151 | # This should not happen. |
| 152 | logging.info( |
| 153 | "=> This CL tries to roll from a newer LKGM. Maybe" |
| 154 | "LKGM in Chromium code has been rolled back. Anyway, " |
| 155 | "rebasing forcibly." |
| 156 | ) |
| 157 | |
| 158 | else: |
| 159 | logging.info( |
| 160 | "=> This CL tries to roll from the older LKGM. " |
| 161 | "Rebasing." |
| 162 | ) |
| 163 | |
| 164 | # Resolve the conflict by rebasing. |
| 165 | if not self._dryrun: |
| 166 | change.Rebase(allow_conflicts=True) |
| 167 | self._gerrit_helper.ChangeEdit( |
| 168 | change.gerrit_number, |
| 169 | "chromeos/CHROMEOS_LKGM", |
| 170 | roll_to_string, |
| 171 | ) |
| 172 | continue |
| 173 | |
| 174 | logging.info("=> This CL is not in the merge-conflict state.") |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 175 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 176 | def Run(self): |
| 177 | self.ProcessObsoleteLKGMRolls() |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 178 | |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 179 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 180 | class ChromeLKGMCommitter: |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 181 | """Committer object responsible for obtaining and committing a new LKGM.""" |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 182 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 183 | # The list of trybots we require LKGM updates to run and pass on before |
| 184 | # landing. Since they're internal trybots, the CQ won't automatically |
Ben Pastene | c71e3e0 | 2023-07-11 17:52:57 -0700 | [diff] [blame] | 185 | # trigger them, so we have to explicitly tell it to. If you add a new |
| 186 | # internal builder here, make sure it's also listed in |
| 187 | # https://source.chromium.org/chromium/chromium/src/+/main:infra/config/subprojects/chrome/try.star. |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 188 | _PRESUBMIT_BOTS = ( |
| 189 | "chromeos-betty-pi-arc-chrome", |
| 190 | "chromeos-eve-chrome", |
Eric Lok | 637d927 | 2023-07-07 00:57:20 +0000 | [diff] [blame] | 191 | "chromeos-jacuzzi-chrome", |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 192 | "chromeos-octopus-chrome", |
| 193 | "chromeos-reven-chrome", |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 194 | ) |
| 195 | # Files needed in a local checkout to successfully update the LKGM. The |
| 196 | # OWNERS file allows the --tbr-owners mechanism to select an appropriate |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 197 | # OWNER to TBR. TRANSLATION_OWNERS is necessary to parse CHROMEOS_OWNERS |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 198 | # file since it has the reference. |
| 199 | _NEEDED_FILES = ( |
| 200 | constants.PATH_TO_CHROME_CHROMEOS_OWNERS, |
| 201 | constants.PATH_TO_CHROME_LKGM, |
| 202 | "tools/translation/TRANSLATION_OWNERS", |
| 203 | ) |
| 204 | # First line of the commit message for all LKGM CLs. |
| 205 | _COMMIT_MSG_HEADER = "Automated Commit: LKGM %(lkgm)s for chromeos." |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 206 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 207 | def __init__( |
| 208 | self, |
| 209 | lkgm: str, |
| 210 | branch: str, |
| 211 | current_lkgm: chromeos_version.VersionInfo, |
| 212 | dryrun: bool = False, |
| 213 | buildbucket_id: Optional[str] = None, |
| 214 | ): |
| 215 | self._dryrun = dryrun |
| 216 | self._branch = branch |
| 217 | self._buildbucket_id = buildbucket_id |
| 218 | self._gerrit_helper = gerrit.GetCrosExternal() |
| 219 | |
| 220 | # Strip any chrome branch from the lkgm version. |
| 221 | self._lkgm = chromeos_version.VersionInfo(lkgm).VersionString() |
Jack Neus | d9a0bd9 | 2022-12-12 16:20:55 +0000 | [diff] [blame] | 222 | if self._dryrun: |
| 223 | self._lkgm = "9999999.99.99" |
| 224 | logging.info("dry run, using version %s", self._lkgm) |
| 225 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 226 | self._commit_msg_header = self._COMMIT_MSG_HEADER % {"lkgm": self._lkgm} |
| 227 | self._current_lkgm = current_lkgm |
| 228 | |
| 229 | if not self._lkgm: |
| 230 | raise LKGMNotValid("LKGM not provided.") |
| 231 | logging.info("lkgm=%s", lkgm) |
| 232 | |
| 233 | def Run(self): |
| 234 | self.UpdateLKGM() |
| 235 | |
| 236 | @property |
| 237 | def lkgm_file(self): |
| 238 | return self._committer.FullPath(constants.PATH_TO_CHROME_LKGM) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 239 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 240 | def UpdateLKGM(self): |
| 241 | """Updates the LKGM file with the new version.""" |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 242 | if chromeos_version.VersionInfo(self._lkgm) <= self._current_lkgm: |
Jack Neus | b8a9feb | 2022-11-18 16:28:55 +0000 | [diff] [blame] | 243 | raise LKGMNotValid( |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 244 | f"LKGM version ({self._lkgm}) is not newer than current version" |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 245 | f" ({self._current_lkgm.VersionString()})." |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 246 | ) |
| 247 | |
Ben Pastene | 6a8361a | 2021-08-19 19:52:05 -0700 | [diff] [blame] | 248 | logging.info( |
Yoshiki Iguchi | f8ab011 | 2022-09-15 16:57:26 +0900 | [diff] [blame] | 249 | "Updating LKGM version: %s (was %s),", |
| 250 | self._lkgm, |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 251 | self._current_lkgm.VersionString(), |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 252 | ) |
| 253 | change = self._gerrit_helper.CreateChange( |
| 254 | "chromium/src", self._branch, self.ComposeCommitMsg(), False |
| 255 | ) |
| 256 | self._gerrit_helper.ChangeEdit( |
| 257 | change.gerrit_number, "chromeos/CHROMEOS_LKGM", self._lkgm |
| 258 | ) |
Ben Pastene | 6a8361a | 2021-08-19 19:52:05 -0700 | [diff] [blame] | 259 | |
Jack Neus | 624c8a5 | 2022-09-13 17:33:03 +0000 | [diff] [blame] | 260 | if self._dryrun: |
| 261 | logging.info( |
| 262 | "Would have applied CQ+2 to crrev.com/c/%s", |
| 263 | change.gerrit_number, |
| 264 | ) |
Jack Neus | 4b03d3c | 2022-09-16 20:21:17 +0000 | [diff] [blame] | 265 | self._gerrit_helper.AbandonChange( |
| 266 | change, |
| 267 | msg="Dry run", |
| 268 | ) |
Yoshiki Iguchi | f430084 | 2022-09-14 12:14:03 +0900 | [diff] [blame] | 269 | return |
| 270 | |
| 271 | labels = { |
| 272 | "Bot-Commit": 1, |
| 273 | "Commit-Queue": 2, |
| 274 | } |
Jack Neus | 624c8a5 | 2022-09-13 17:33:03 +0000 | [diff] [blame] | 275 | logging.info( |
| 276 | "Applying %s to crrev.com/c/%s", labels, change.gerrit_number |
| 277 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 278 | self._gerrit_helper.SetReview( |
Yoshiki Iguchi | dad2425 | 2022-09-22 14:21:30 +0900 | [diff] [blame] | 279 | change.gerrit_number, |
| 280 | labels=labels, |
| 281 | notify="NONE", |
| 282 | ready=True, |
| 283 | reviewers=[constants.CHROME_GARDENER_REVIEW_EMAIL], |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 284 | ) |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 285 | self._gerrit_helper.SetHashtags(change.gerrit_number, [HASHTAG], []) |
Ben Pastene | 6a8361a | 2021-08-19 19:52:05 -0700 | [diff] [blame] | 286 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 287 | def ComposeCommitMsg(self): |
| 288 | """Constructs and returns the commit message for the LKGM update.""" |
Jack Neus | 51d2e34 | 2022-09-14 16:40:08 +0000 | [diff] [blame] | 289 | dry_run_message = ( |
| 290 | "This CL was created during a dry run and is not " |
| 291 | "intended to be committed.\n" |
| 292 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 293 | commit_msg_template = ( |
Jack Neus | 51d2e34 | 2022-09-14 16:40:08 +0000 | [diff] [blame] | 294 | "%(header)s\n%(build_link)s\n%(message)s\n%(cq_includes)s" |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 295 | ) |
| 296 | cq_includes = "" |
Jack Neus | 7329df5 | 2022-09-28 18:53:28 +0000 | [diff] [blame] | 297 | if self._branch == "main": |
| 298 | for bot in self._PRESUBMIT_BOTS: |
| 299 | cq_includes += "CQ_INCLUDE_TRYBOTS=luci.chrome.try:%s\n" % bot |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 300 | build_link = "" |
| 301 | if self._buildbucket_id: |
| 302 | build_link = "\nUploaded by https://ci.chromium.org/b/%s\n" % ( |
| 303 | self._buildbucket_id |
| 304 | ) |
| 305 | return commit_msg_template % dict( |
| 306 | header=self._commit_msg_header, |
| 307 | cq_includes=cq_includes, |
| 308 | build_link=build_link, |
Jack Neus | 51d2e34 | 2022-09-14 16:40:08 +0000 | [diff] [blame] | 309 | message=dry_run_message if self._dryrun else "", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 310 | ) |
Ben Pastene | d3b93d4 | 2019-10-10 09:56:29 -0700 | [diff] [blame] | 311 | |
Achuith Bhandarkar | 1b9180f | 2018-02-22 19:12:09 -0800 | [diff] [blame] | 312 | |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 313 | def GetCurrentLKGM(branch: str) -> chromeos_version.VersionInfo: |
| 314 | """Returns the current LKGM version on the branch. |
| 315 | |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 316 | On the first call, this method retrieves the LKGM version from Gitiles |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 317 | server and returns it. On subsequent calls, this method returns the |
| 318 | cached LKGM version. |
| 319 | |
| 320 | Raises: |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 321 | LKGMNotValid: if the retrieved LKGM version from the repository is |
| 322 | invalid. |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 323 | """ |
| 324 | current_lkgm = gob_util.GetFileContents( |
| 325 | constants.CHROMIUM_GOB_URL, |
| 326 | constants.PATH_TO_CHROME_LKGM, |
| 327 | ref=branch, |
| 328 | ) |
| 329 | if current_lkgm is None: |
| 330 | raise LKGMNotValid( |
| 331 | "The retrieved LKGM version from the repository is invalid:" |
| 332 | f" {current_lkgm}." |
| 333 | ) |
| 334 | |
| 335 | return chromeos_version.VersionInfo(current_lkgm.strip()) |
| 336 | |
| 337 | |
Achuith Bhandarkar | b6f4025 | 2019-12-09 16:31:34 -0800 | [diff] [blame] | 338 | def GetOpts(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 339 | """Returns a dictionary of parsed options. |
Achuith Bhandarkar | 1b9180f | 2018-02-22 19:12:09 -0800 | [diff] [blame] | 340 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 341 | Args: |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 342 | argv: raw command line. |
Achuith Bhandarkar | dc3a351 | 2018-03-16 15:10:57 -0700 | [diff] [blame] | 343 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 344 | Returns: |
Alex Klein | 9e7b29e | 2023-04-11 16:10:31 -0600 | [diff] [blame] | 345 | Dictionary of parsed options. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 346 | """ |
| 347 | parser = commandline.ArgumentParser(description=__doc__, add_help=False) |
| 348 | parser.add_argument( |
| 349 | "--dryrun", |
| 350 | action="store_true", |
| 351 | default=False, |
| 352 | help="Don't commit changes or send out emails.", |
| 353 | ) |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 354 | parser.add_argument("--lkgm", help="LKGM version to update to.") |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 355 | parser.add_argument( |
| 356 | "--buildbucket-id", |
| 357 | help="Buildbucket ID of the build that ran this script. " |
| 358 | "Will be linked in the commit message if specified.", |
| 359 | ) |
| 360 | parser.add_argument( |
| 361 | "--branch", |
| 362 | default="main", |
| 363 | help="Branch to upload change to, e.g. " |
| 364 | "refs/branch-heads/5112. Defaults to main.", |
| 365 | ) |
| 366 | return parser.parse_args(argv) |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 367 | |
Ben Pastene | 3ae39bd | 2022-01-04 15:20:05 -0800 | [diff] [blame] | 368 | |
Steven Bennetts | ddf9bcd | 2017-06-14 14:07:43 -0700 | [diff] [blame] | 369 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 370 | opts = GetOpts(argv) |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 371 | current_lkgm = GetCurrentLKGM(opts.branch) |
| 372 | |
| 373 | if opts.lkgm is not None: |
| 374 | committer = ChromeLKGMCommitter( |
| 375 | opts.lkgm, |
| 376 | opts.branch, |
| 377 | current_lkgm, |
| 378 | opts.dryrun, |
| 379 | opts.buildbucket_id, |
| 380 | ) |
| 381 | committer.Run() |
| 382 | |
| 383 | # We need to know the account used by the builder to upload git CLs when |
| 384 | # listing up CLs. |
| 385 | user_email = "" |
Anuj Jamwal | 258529f | 2023-09-08 17:32:55 +0000 | [diff] [blame] | 386 | if hostname_util.host_is_ci_builder(golo_only=True): |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 387 | user_email = "chromeos-commit-bot@chromium.org" |
Anuj Jamwal | 258529f | 2023-09-08 17:32:55 +0000 | [diff] [blame] | 388 | elif hostname_util.host_is_ci_builder(gce_only=True): |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 389 | user_email = "3su6n15k.default@developer.gserviceaccount.com" |
| 390 | else: |
| 391 | raise LKGMFileNotFound("Failed to determine an appropriate user email.") |
| 392 | |
| 393 | cleaner = ChromeLKGMCleaner( |
| 394 | opts.branch, |
| 395 | current_lkgm, |
| 396 | user_email, |
| 397 | opts.dryrun, |
| 398 | opts.buildbucket_id, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 399 | ) |
Yoshiki Iguchi | d5bc792 | 2022-09-22 14:37:48 +0900 | [diff] [blame] | 400 | cleaner.Run() |
| 401 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 402 | return 0 |