From 4695c53fb367861fd2aeb57fb7536ca8dd6c62ea Mon Sep 17 00:00:00 2001 From: Tomo Suzuki Date: Mon, 16 Dec 2024 11:23:56 -0500 Subject: [PATCH] feat: multi_scm_type parameter --- autorelease/__main__.py | 3 ++ autorelease/kokoro.py | 18 +++++--- autorelease/trigger.py | 6 +++ protos/kokoro_api.proto | 31 +++++++++++++ protos/kokoro_api_pb2.py | 73 +++++-------------------------- tests/test_autorelease_trigger.py | 6 +++ 6 files changed, 71 insertions(+), 66 deletions(-) diff --git a/autorelease/__main__.py b/autorelease/__main__.py index 6613e1c..b81b973 100644 --- a/autorelease/__main__.py +++ b/autorelease/__main__.py @@ -51,6 +51,7 @@ def main(): parser.add_argument("--lang", default=None) parser.add_argument("command") parser.add_argument("--multi-scm-name") + parser.add_argument("--multi-scm-type", default="github") args = parser.parse_args() @@ -86,6 +87,7 @@ def main(): args.release, trigger.to_pysafe_language_name(args.lang), args.multi_scm_name, + args.multi_scm_type, ) if not args.pull: raise Exception("missing required arg --pull") @@ -95,6 +97,7 @@ def main(): args.kokoro_credentials, args.pull, multi_scm_name=args.multi_scm_name, + scm_type=args.multi_scm_type, ) if args.report: diff --git a/autorelease/kokoro.py b/autorelease/kokoro.py index ee7d379..e673165 100644 --- a/autorelease/kokoro.py +++ b/autorelease/kokoro.py @@ -43,7 +43,8 @@ def _send_pubsub_message( def _make_build_request( - job_name: str, sha: str, env_vars: dict = None, multi_scm_name: str = "" + job_name: str, sha: str, env_vars: dict = None, multi_scm_name: str = "", + multi_scm_type: str = "github" ) -> str: request = kokoro_api_pb2.BuildRequest( full_job_name=job_name, @@ -52,9 +53,14 @@ def _make_build_request( # If the job is configured to use multiple SCMs, then we need to send # the scm_name field as part of the request if multi_scm_name: - request.multi_scm_revision.github_scm_revision.add( - name=multi_scm_name, commit_sha=sha - ) + if multi_scm_type == 'git-on-borg': + request.multi_scm_revision.git_on_borg_scm_revision.add( + name=multi_scm_name, commit_sha=sha + ) + else: + request.multi_scm_revision.github_scm_revision.add( + name=multi_scm_name, commit_sha=sha + ) else: request.scm_revision.github_scm_revision.commit_sha = sha @@ -105,8 +111,10 @@ def trigger_build( sha: str, env_vars: dict = None, multi_scm_name: str = "", + multi_scm_type: str = "github" ): build_request = _make_build_request( - job_name, sha, env_vars=env_vars, multi_scm_name=multi_scm_name + job_name, sha, env_vars=env_vars, multi_scm_name=multi_scm_name, + multi_scm_type=multi_scm_type ) _send_pubsub_message(session, _DEVREL_PROD_KOKORO_TOPIC, build_request) diff --git a/autorelease/trigger.py b/autorelease/trigger.py index 00ce135..3e355ea 100644 --- a/autorelease/trigger.py +++ b/autorelease/trigger.py @@ -59,6 +59,7 @@ def trigger_kokoro_build_for_pull_request( update_labels: bool = True, use_allowlist: bool = True, multi_scm_name: str = "", + multi_scm_type: str = "github", ) -> None: """Triggers the Kokoro job for a given pull request if possible. @@ -125,6 +126,7 @@ def trigger_kokoro_build_for_pull_request( sha=sha, env_vars={"AUTORELEASE_PR": pull_request_url}, multi_scm_name=multi_scm_name, + multi_scm_type=multi_scm_type, ) if update_labels: gh.update_pull_labels(pull, add=["autorelease: triggered"]) @@ -143,6 +145,7 @@ def trigger_for_release( release_url: str, pysafe_lang: str, multi_scm_name: str = "", + multi_scm_type: str = "github", ) -> reporter.Reporter: """Trigger a Kokoro job based on a release PR URL. @@ -187,6 +190,7 @@ def trigger_for_release( sha=sha, env_vars={}, multi_scm_name=multi_scm_name, + multi_scm_type=multi_scm_type, ) report.add(result) @@ -198,6 +202,7 @@ def trigger_single( kokoro_credentials: str, pull_request_url: str, multi_scm_name: str = "", + multi_scm_type: str = "github", ) -> reporter.Reporter: """Trigger a Kokoro job based on a release PR URL. @@ -241,6 +246,7 @@ def trigger_single( False, False, multi_scm_name=multi_scm_name, + multi_scm_type=multi_scm_type, ) # Failing any one PR is fine, just record it in the log and continue. except Exception as exc: diff --git a/protos/kokoro_api.proto b/protos/kokoro_api.proto index 64462b1..4e683a0 100644 --- a/protos/kokoro_api.proto +++ b/protos/kokoro_api.proto @@ -16,6 +16,9 @@ // This has been heavily modified from the upstream source to just contain // the fields we need. // Source: https://cs.corp.google.com/piper///depot/google3/devtools/kokoro/api/proto/kokoro_api.proto +// How to generate protos/kokoro_api_pb2.py: +// 1. Download appropriate protoc from https://github.com/protocolbuffers/protobuf/releases +// 2. Run `/tmp/protoc-21.6/bin/protoc --python_out=. protos/kokoro_api.proto` syntax = "proto2"; @@ -60,6 +63,7 @@ message BuildRequest { // Represents a specific revision in one of the supported SCM systems. message ScmRevision { oneof scmrevision { + GitOnBorgScmRevision git_on_borg_scm_revision = 2; GithubScmRevision github_scm_revision = 4; } } @@ -95,3 +99,30 @@ message GithubScmRevision { // next index: 7 } + +// Represents a specific revision in a Git-on-Borg repository. +message GitOnBorgScmRevision { + // Name of the scm that this revision belongs to. This name should be the same + // as multi_scm.git_on_borg_scm.name + // If name is provided, repo_url is ignored. + optional string name = 3; + + // The SHA1 hash identifying a revision. In the build request from user, this + // can be a commit or a branch (e.g. 'master'). In the build status response, + // this will be a commit sha. + optional string sha1 = 1; + + // The URL for the change in Git on borg repository. This field will be + // populated in the build result, and will be ignored if it is specified in + // the query. Previously called repository_url. + optional string revision_url = 5; + + // This is optional for builds manually triggered by the users. For the builds + // automatically triggered by Kokoro, it should be the branch to which the + // sha1 is belongs to. + optional string branch = 4; + + reserved 2; + + // next index: 8 +} diff --git a/protos/kokoro_api_pb2.py b/protos/kokoro_api_pb2.py index f28fab0..5712b66 100644 --- a/protos/kokoro_api_pb2.py +++ b/protos/kokoro_api_pb2.py @@ -2,10 +2,9 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: protos/kokoro_api.proto """Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database # @@protoc_insertion_point(imports) @@ -14,60 +13,10 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x17protos/kokoro_api.proto\x12\x19\x64\x65vtools.kokoro.api.proto\"\xc2\x03\n\x0c\x42uildRequest\x12\x15\n\rfull_job_name\x18\x01 \x01(\t\x12<\n\x0cscm_revision\x18\x03 \x01(\x0b\x32&.devtools.kokoro.api.proto.ScmRevision\x12G\n\x12multi_scm_revision\x18\t \x01(\x0b\x32+.devtools.kokoro.api.proto.MultiScmRevision\x12\x18\n\x10input_file_paths\x18\x04 \x03(\t\x12\x46\n\x08\x65nv_vars\x18\x06 \x03(\x0b\x32\x34.devtools.kokoro.api.proto.BuildRequest.EnvVarsEntry\x12N\n\x0c\x62uild_params\x18\x0c \x03(\x0b\x32\x38.devtools.kokoro.api.proto.BuildRequest.BuildParamsEntry\x1a.\n\x0c\x45nvVarsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x32\n\x10\x42uildParamsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"i\n\x0bScmRevision\x12K\n\x13github_scm_revision\x18\x04 \x01(\x0b\x32,.devtools.kokoro.api.proto.GithubScmRevisionH\x00\x42\r\n\x0bscmrevision\"]\n\x10MultiScmRevision\x12I\n\x13github_scm_revision\x18\x04 \x03(\x0b\x32,.devtools.kokoro.api.proto.GithubScmRevision\"\x8d\x01\n\x11GithubScmRevision\x12\x0c\n\x04name\x18\x04 \x01(\t\x12\x12\n\ncommit_sha\x18\x01 \x01(\t\x12\x1b\n\x13pull_request_number\x18\x02 \x01(\t\x12\x16\n\x0erepository_url\x18\x03 \x01(\t\x12\r\n\x05owner\x18\x05 \x01(\t\x12\x12\n\nrepository\x18\x06 \x01(\t') - - - -_BUILDREQUEST = DESCRIPTOR.message_types_by_name['BuildRequest'] -_BUILDREQUEST_ENVVARSENTRY = _BUILDREQUEST.nested_types_by_name['EnvVarsEntry'] -_BUILDREQUEST_BUILDPARAMSENTRY = _BUILDREQUEST.nested_types_by_name['BuildParamsEntry'] -_SCMREVISION = DESCRIPTOR.message_types_by_name['ScmRevision'] -_MULTISCMREVISION = DESCRIPTOR.message_types_by_name['MultiScmRevision'] -_GITHUBSCMREVISION = DESCRIPTOR.message_types_by_name['GithubScmRevision'] -BuildRequest = _reflection.GeneratedProtocolMessageType('BuildRequest', (_message.Message,), { - - 'EnvVarsEntry' : _reflection.GeneratedProtocolMessageType('EnvVarsEntry', (_message.Message,), { - 'DESCRIPTOR' : _BUILDREQUEST_ENVVARSENTRY, - '__module__' : 'protos.kokoro_api_pb2' - # @@protoc_insertion_point(class_scope:devtools.kokoro.api.proto.BuildRequest.EnvVarsEntry) - }) - , - - 'BuildParamsEntry' : _reflection.GeneratedProtocolMessageType('BuildParamsEntry', (_message.Message,), { - 'DESCRIPTOR' : _BUILDREQUEST_BUILDPARAMSENTRY, - '__module__' : 'protos.kokoro_api_pb2' - # @@protoc_insertion_point(class_scope:devtools.kokoro.api.proto.BuildRequest.BuildParamsEntry) - }) - , - 'DESCRIPTOR' : _BUILDREQUEST, - '__module__' : 'protos.kokoro_api_pb2' - # @@protoc_insertion_point(class_scope:devtools.kokoro.api.proto.BuildRequest) - }) -_sym_db.RegisterMessage(BuildRequest) -_sym_db.RegisterMessage(BuildRequest.EnvVarsEntry) -_sym_db.RegisterMessage(BuildRequest.BuildParamsEntry) - -ScmRevision = _reflection.GeneratedProtocolMessageType('ScmRevision', (_message.Message,), { - 'DESCRIPTOR' : _SCMREVISION, - '__module__' : 'protos.kokoro_api_pb2' - # @@protoc_insertion_point(class_scope:devtools.kokoro.api.proto.ScmRevision) - }) -_sym_db.RegisterMessage(ScmRevision) - -MultiScmRevision = _reflection.GeneratedProtocolMessageType('MultiScmRevision', (_message.Message,), { - 'DESCRIPTOR' : _MULTISCMREVISION, - '__module__' : 'protos.kokoro_api_pb2' - # @@protoc_insertion_point(class_scope:devtools.kokoro.api.proto.MultiScmRevision) - }) -_sym_db.RegisterMessage(MultiScmRevision) - -GithubScmRevision = _reflection.GeneratedProtocolMessageType('GithubScmRevision', (_message.Message,), { - 'DESCRIPTOR' : _GITHUBSCMREVISION, - '__module__' : 'protos.kokoro_api_pb2' - # @@protoc_insertion_point(class_scope:devtools.kokoro.api.proto.GithubScmRevision) - }) -_sym_db.RegisterMessage(GithubScmRevision) +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x17protos/kokoro_api.proto\x12\x19\x64\x65vtools.kokoro.api.proto\"\xc2\x03\n\x0c\x42uildRequest\x12\x15\n\rfull_job_name\x18\x01 \x01(\t\x12<\n\x0cscm_revision\x18\x03 \x01(\x0b\x32&.devtools.kokoro.api.proto.ScmRevision\x12G\n\x12multi_scm_revision\x18\t \x01(\x0b\x32+.devtools.kokoro.api.proto.MultiScmRevision\x12\x18\n\x10input_file_paths\x18\x04 \x03(\t\x12\x46\n\x08\x65nv_vars\x18\x06 \x03(\x0b\x32\x34.devtools.kokoro.api.proto.BuildRequest.EnvVarsEntry\x12N\n\x0c\x62uild_params\x18\x0c \x03(\x0b\x32\x38.devtools.kokoro.api.proto.BuildRequest.BuildParamsEntry\x1a.\n\x0c\x45nvVarsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x32\n\x10\x42uildParamsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xbe\x01\n\x0bScmRevision\x12S\n\x18git_on_borg_scm_revision\x18\x02 \x01(\x0b\x32/.devtools.kokoro.api.proto.GitOnBorgScmRevisionH\x00\x12K\n\x13github_scm_revision\x18\x04 \x01(\x0b\x32,.devtools.kokoro.api.proto.GithubScmRevisionH\x00\x42\r\n\x0bscmrevision\"]\n\x10MultiScmRevision\x12I\n\x13github_scm_revision\x18\x04 \x03(\x0b\x32,.devtools.kokoro.api.proto.GithubScmRevision\"\x8d\x01\n\x11GithubScmRevision\x12\x0c\n\x04name\x18\x04 \x01(\t\x12\x12\n\ncommit_sha\x18\x01 \x01(\t\x12\x1b\n\x13pull_request_number\x18\x02 \x01(\t\x12\x16\n\x0erepository_url\x18\x03 \x01(\t\x12\r\n\x05owner\x18\x05 \x01(\t\x12\x12\n\nrepository\x18\x06 \x01(\t\"^\n\x14GitOnBorgScmRevision\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x0c\n\x04sha1\x18\x01 \x01(\t\x12\x14\n\x0crevision_url\x18\x05 \x01(\t\x12\x0e\n\x06\x62ranch\x18\x04 \x01(\tJ\x04\x08\x02\x10\x03') +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'protos.kokoro_api_pb2', globals()) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None @@ -81,10 +30,12 @@ _BUILDREQUEST_ENVVARSENTRY._serialized_end=453 _BUILDREQUEST_BUILDPARAMSENTRY._serialized_start=455 _BUILDREQUEST_BUILDPARAMSENTRY._serialized_end=505 - _SCMREVISION._serialized_start=507 - _SCMREVISION._serialized_end=612 - _MULTISCMREVISION._serialized_start=614 - _MULTISCMREVISION._serialized_end=707 - _GITHUBSCMREVISION._serialized_start=710 - _GITHUBSCMREVISION._serialized_end=851 + _SCMREVISION._serialized_start=508 + _SCMREVISION._serialized_end=698 + _MULTISCMREVISION._serialized_start=700 + _MULTISCMREVISION._serialized_end=793 + _GITHUBSCMREVISION._serialized_start=796 + _GITHUBSCMREVISION._serialized_end=937 + _GITONBORGSCMREVISION._serialized_start=939 + _GITONBORGSCMREVISION._serialized_end=1033 # @@protoc_insertion_point(module_scope) diff --git a/tests/test_autorelease_trigger.py b/tests/test_autorelease_trigger.py index 8eb7e24..b5a3270 100644 --- a/tests/test_autorelease_trigger.py +++ b/tests/test_autorelease_trigger.py @@ -206,6 +206,7 @@ def test_trigger_single( "AUTORELEASE_PR": "https://github.com/googleapis/php-trace/pull/1234" }, multi_scm_name="", + multi_scm_type="github", ) update_pull_labels.assert_not_called() @@ -250,6 +251,7 @@ def test_trigger_single_default_multi_scm( "AUTORELEASE_PR": "https://github.com/googleapis/java-trace/pull/1234" }, multi_scm_name="java-trace", + multi_scm_type="github", ) update_pull_labels.assert_not_called() @@ -278,6 +280,7 @@ def test_trigger_for_release(trigger_build, get_url, make_authorized_session): sha="abcd1234", env_vars={}, multi_scm_name="", + multi_scm_type="github", ) @@ -324,6 +327,7 @@ def test_trigger_single_multi_scm( "AUTORELEASE_PR": "https://github.com/googleapis/java-trace/pull/1234" }, multi_scm_name="java-trace", + multi_scm_type="github", ) update_pull_labels.assert_not_called() @@ -368,6 +372,7 @@ def test_trigger_package( "AUTORELEASE_PR": "https://github.com/GoogleCloudPlatform/functions-framework-java/pull/111" }, multi_scm_name="functions-framework-java", + multi_scm_type="github", ) @@ -465,4 +470,5 @@ def test_trigger_multi_scm( "AUTORELEASE_PR": "https://github.com/GoogleCloudPlatform/functions-framework-java/pull/111" }, multi_scm_name="functions-framework-java", + multi_scm_type="github", )