diff options
author | Caveh Jalali <caveh@chromium.org> | 2022-09-08 16:12:14 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-12 20:18:21 +0000 |
commit | 9de3957c15bfaf3874ec2c3e0e2dc2a6b6b2e668 (patch) | |
tree | f82be793463f64711b847661115122eb04496028 | |
parent | 71b2ef709dcb14260f5fdaa3ab4ced005a29fb46 (diff) | |
download | chrome-ec-9de3957c15bfaf3874ec2c3e0e2dc2a6b6b2e668.tar.gz |
util/update_release_branch: Add support for internal branches
This adds support for updating internal (private) branches. These are
distinguished by using the "cros-internal" branch name prefix instead of
the usual "cros" prefix. This is done by adding a "--remote_prefix"
option to override the default "cros" prefix".
In addition, since the notion of "baseboard" or "board" does not exist
in some repos, the use of these flags is no longer mandated. The
"--relevant_path_file" can still be used to augment the generated commit
message in these cases.
Plus, minor lint improvements suggested by repo upload.
BRANCH=none
BUG=b:244387210
TEST=performed update on a private branch. ran:
".../util/update_release_branch.py --remote_prefix cros-internal
<internal-branch-name>" and confirmed branch files were updated
to match ToT.
Change-Id: I97e48cfe068ba5a1b7774c256262accf75ce763a
Signed-off-by: Caveh Jalali <caveh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3885227
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rwxr-xr-x | util/update_release_branch.py | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/util/update_release_branch.py b/util/update_release_branch.py index 07d013db1f..f03fc91253 100755 --- a/util/update_release_branch.py +++ b/util/update_release_branch.py @@ -22,7 +22,7 @@ import textwrap BUG_NONE_PATTERN = re.compile("none", flags=re.IGNORECASE) -def git_commit_msg(branch, head, merge_head, rel_paths, cmd): +def git_commit_msg(cros_main, branch, head, merge_head, rel_paths, cmd): """Generates a merge commit message based off of relevant changes. This function obtains the relevant commits from the given relative paths in @@ -30,6 +30,7 @@ def git_commit_msg(branch, head, merge_head, rel_paths, cmd): showing the command used to find the relevant commits. Args: + cros_main: String indicating the origin branch name branch: String indicating the release branch name head: String indicating the HEAD refspec merge_head: String indicating the merge branch refspec. @@ -59,8 +60,8 @@ def git_commit_msg(branch, head, merge_head, rel_paths, cmd): # TODO(b/179509333): remove Cq-Include-Trybots line when regular CQ and # firmware CQ do not behave differently. - COMMIT_MSG_TEMPLATE = """ -Merge remote-tracking branch cros/main into {BRANCH} + commit_msg_template = """ +Merge remote-tracking branch {CROS_MAIN} into {BRANCH} Generated by: {COMMAND_LINE} @@ -87,7 +88,8 @@ Cq-Include-Trybots: chromeos/cq:cq-orchestrator # Remove the final newline since the template adds it for us. bug_field = bug_field[:-1] - return COMMIT_MSG_TEMPLATE.format( + return commit_msg_template.format( + CROS_MAIN=cros_main, BRANCH=branch, RELEVANT_COMMITS_CMD=relevant_commits_cmd, RELEVANT_COMMITS=relevant_commits, @@ -187,6 +189,14 @@ def main(argv): "release_branch", help=("The name of the target release" " branch") ) parser.add_argument( + "--remote_prefix", + help=( + "The name of the remote branch prefix (default cros). " + "Private repos typically use cros-internal instead." + ), + default="cros", + ) + parser.add_argument( "--relevant_paths_file", help=( "A path to a text file which includes other " @@ -228,13 +238,13 @@ def main(argv): board_dir = os.path.relpath(os.path.realpath(board_dir)) boards = [opts.board] else: - parser.error("You must specify a board OR a baseboard") + boards = [] print("Gathering relevant paths...") relevant_paths = [] if opts.baseboard: relevant_paths.append(baseboard_dir) - else: + elif opts.board: relevant_paths.append(board_dir) for board in boards: @@ -246,7 +256,8 @@ def main(argv): for line in relevant_paths_file: if not line.startswith("#"): relevant_paths.append(line.rstrip()) - relevant_paths.append("util/getversion.sh") + if os.path.exists("util/getversion.sh"): + relevant_paths.append("util/getversion.sh") relevant_paths = " ".join(relevant_paths) # Check if we are already in merge process @@ -290,7 +301,7 @@ def main(argv): "checkout", "-B", opts.release_branch, - "cros/" + opts.release_branch, + opts.remote_prefix + "/" + opts.release_branch, ], check=True, ) @@ -305,12 +316,13 @@ def main(argv): else "" ), ) + cros_main = opts.remote_prefix + "/" + "main" arglist = [ "git", "merge", "--no-ff", "--no-commit", - "cros/main", + cros_main, "-s", opts.merge_strategy, ] @@ -337,7 +349,7 @@ def main(argv): # Prune OWNERS files for file in unmerged: if file in prunelist: - subprocess.run(["git", "rm", file]) + subprocess.run(["git", "rm", file], check=False) unmerged.remove(file) print("Removed non-root OWNERS files.") @@ -377,7 +389,9 @@ def main(argv): cmd = " ".join(argv) print("Typing as fast as I can...") - commit_msg = git_commit_msg(branch, head, merge_head, relevant_paths, cmd) + commit_msg = git_commit_msg( + cros_main, branch, head, merge_head, relevant_paths, cmd + ) subprocess.run(["git", "commit", "--signoff", "-m", commit_msg], check=True) subprocess.run(["git", "commit", "--amend"], check=True) print( |