Skip to content

Commit

Permalink
feat: multi_scm_type parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
suztomo committed Dec 16, 2024
1 parent 2e88c2d commit 4695c53
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 66 deletions.
3 changes: 3 additions & 0 deletions autorelease/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down
18 changes: 13 additions & 5 deletions autorelease/kokoro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions autorelease/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"])
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
31 changes: 31 additions & 0 deletions protos/kokoro_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
}
73 changes: 12 additions & 61 deletions protos/kokoro_api_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/test_autorelease_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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",
)


Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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",
)


Expand Down Expand Up @@ -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",
)

0 comments on commit 4695c53

Please sign in to comment.