Skip to content

Commit

Permalink
feat(autorelease): automatically assume multiScm for node and python (#…
Browse files Browse the repository at this point in the history
…567)

* feat(autorelease): automatically assume multiScm for node and python

* test: don't run on python 3.8
  • Loading branch information
chingor13 authored Nov 11, 2024
1 parent f082c86 commit cc1e66d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 14 deletions.
12 changes: 12 additions & 0 deletions autorelease/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

LANGUAGE_ALLOWLIST = []
ORGANIZATIONS_TO_SCAN = ["googleapis", "GoogleCloudPlatform"]
LANGUAGES_ON_MULTI_SCM = ["java", "python", "nodejs"]

# Whenever we add new languages to the allowlist, update this value as
# well to prevent trying to release old versions.
Expand Down Expand Up @@ -98,6 +99,11 @@ def trigger_kokoro_build_for_pull_request(
result.print(f"Language {lang} not in allowlist, skipping.")
return

# For languages migrated to release configs that always use multiScm, default the
# scmName to the repository name
if not multi_scm_name and lang in LANGUAGES_ON_MULTI_SCM:
multi_scm_name = pull["base"]["repo"]["name"]

language_module = importlib.import_module(f"releasetool.commands.tag.{lang}")
package_name = language_module.package_name(pull)
kokoro_job_name = language_module.kokoro_job_name(
Expand Down Expand Up @@ -159,6 +165,12 @@ def trigger_for_release(

language_module = importlib.import_module(f"releasetool.commands.tag.{pysafe_lang}")
owner, repo = _repo_name_from_github_url(release_url)

# For languages migrated to release configs that always use multiScm, default the
# scmName to the repository name
if not multi_scm_name and pysafe_lang in LANGUAGES_ON_MULTI_SCM:
multi_scm_name = repo

kokoro_job_name = language_module.kokoro_job_name(f"{owner}/{repo}", None)
result = reporter.Result(release_url)
if kokoro_job_name is None:
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()

ALL_PYTHON = ["3.8", "3.9", "3.10", "3.11", "3.12"]
ALL_PYTHON = ["3.9", "3.10", "3.11", "3.12"]

@nox.session(python='3.8')
def blacken(session):
Expand Down
94 changes: 81 additions & 13 deletions tests/test_autorelease_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ def test_processes_issues(
make_authorized_session, list_org_issues, trigger_kokoro_build_for_pull_request
):
pr1 = {
"base": {"ref": "abc123", "repo": {"full_name": "googleapis/java-asset"}},
"base": {
"ref": "abc123",
"repo": {"full_name": "googleapis/java-asset", "name": "java-asset"},
},
"pull_request": {"html_url": "https://github.com/googleapis/java-asset"},
"title": "chore: release 1.2.3",
}
pr2 = {
"base": {"ref": "def456", "repo": {"full_name": "googleapis/nodejs-container"}},
"base": {
"ref": "def456",
"repo": {
"full_name": "googleapis/nodejs-container",
"name": "nodejs-container",
},
},
"pull_request": {"html_url": "https://github.com/nodejs/java-container"},
"title": "chore: release 1.0.0",
}
Expand All @@ -80,7 +89,7 @@ def test_trigger_kokoro_build_for_pull_request_skips_non_merged(trigger_build):
github.update_pull_labels = Mock()
github.get_url.return_value = {
"merged_at": None,
"base": {"repo": {"full_name": "googleapis/java-asset"}},
"base": {"repo": {"full_name": "googleapis/java-asset", "name": "java-asset"}},
}
issue = {
"pull_request": {"url": "https://api.github.com/googleapis/java-asset/pull/5"}
Expand All @@ -97,7 +106,7 @@ def test_trigger_kokoro_build_for_pull_request_triggers_kokoro(trigger_build):
github.get_url.return_value = {
"merged_at": "2021-01-01T09:00:00.000Z",
"merge_commit_sha": "abcd1234",
"base": {"repo": {"full_name": "googleapis/java-asset"}},
"base": {"repo": {"full_name": "googleapis/java-asset", "name": "java-asset"}},
"html_url": "https://github.com/googleapis/java-asset/pulls/5",
}
issue = {
Expand All @@ -119,7 +128,7 @@ def test_trigger_kokoro_build_for_pull_request_skips_kokoro_if_not_in_allowlist(
github.get_url.return_value = {
"merged_at": "2021-01-01T09:00:00.000Z",
"merge_commit_sha": "abcd1234",
"base": {"repo": {"full_name": "googleapis/java-asset"}},
"base": {"repo": {"full_name": "googleapis/java-asset", "name": "java-asset"}},
"html_url": "https://github.com/googleapis/java-asset/pulls/5",
}
issue = {
Expand All @@ -138,7 +147,12 @@ def test_trigger_kokoro_build_for_pull_request_skips_kokoro_if_already_triggered
github = Mock()
github.get_url.return_value = {
"merged_at": "2021-01-01T09:00:00.000Z",
"base": {"repo": {"full_name": "googleapis/google-cloud-php-bigquery"}},
"base": {
"repo": {
"full_name": "googleapis/google-cloud-php-bigquery",
"name": "google-cloud-php-bigquery",
}
},
"html_url": "https://github.com/googleapis/google-cloud-php-bigquery/pulls/5",
"labels": [{"id": 12345, "name": "autorelease: triggered"}],
}
Expand All @@ -160,6 +174,50 @@ def test_trigger_kokoro_build_for_pull_request_skips_kokoro_if_already_triggered
@patch("autorelease.kokoro.trigger_build")
def test_trigger_single(
trigger_build, update_pull_labels, get_url, get_issue, make_authorized_session
):
kokoro_session = Mock()
make_authorized_session.return_value = kokoro_session
get_issue.return_value = {
"title": "chore: release 1.2.3",
"pull_request": {
"html_url": "https://github.com/googleapis/php-trace/pull/1234",
"url": "https://api.github.com/repos/googleapis/php-trace/pulls/1234",
},
}
get_url.return_value = {
"merged_at": "2021-07-20T09:00:00.123Z",
"base": {"repo": {"full_name": "googleapis/php-trace", "name": "php-trace"}},
"html_url": "https://github.com/googleapis/php-trace/pull/1234",
"merge_commit_sha": "abcd1234",
"labels": [{"id": 12345, "name": "autorelease: tagged"}],
}

pull_request_url = "https://github.com/googleapis/php-trace/pull/1234"
reporter = trigger.trigger_single(
"fake-github-token", "fake-kokoro-credentials", pull_request_url
)

assert len(reporter.results) == 1
trigger_build.assert_called_with(
kokoro_session,
job_name="cloud-devrel/client-libraries/php/googleapis/php-trace/release",
sha="abcd1234",
env_vars={
"AUTORELEASE_PR": "https://github.com/googleapis/php-trace/pull/1234"
},
multi_scm_name="",
)
update_pull_labels.assert_not_called()


@patch("autorelease.trigger.LANGUAGE_ALLOWLIST", ["java"])
@patch("autorelease.kokoro.make_authorized_session")
@patch("autorelease.github.GitHub.get_issue")
@patch("autorelease.github.GitHub.get_url")
@patch("autorelease.github.GitHub.update_pull_labels")
@patch("autorelease.kokoro.trigger_build")
def test_trigger_single_default_multi_scm(
trigger_build, update_pull_labels, get_url, get_issue, make_authorized_session
):
kokoro_session = Mock()
make_authorized_session.return_value = kokoro_session
Expand All @@ -172,7 +230,7 @@ def test_trigger_single(
}
get_url.return_value = {
"merged_at": "2021-07-20T09:00:00.123Z",
"base": {"repo": {"full_name": "googleapis/java-trace"}},
"base": {"repo": {"full_name": "googleapis/java-trace", "name": "java-trace"}},
"html_url": "https://github.com/googleapis/java-trace/pull/1234",
"merge_commit_sha": "abcd1234",
"labels": [{"id": 12345, "name": "autorelease: tagged"}],
Expand All @@ -191,7 +249,7 @@ def test_trigger_single(
env_vars={
"AUTORELEASE_PR": "https://github.com/googleapis/java-trace/pull/1234"
},
multi_scm_name="",
multi_scm_name="java-trace",
)
update_pull_labels.assert_not_called()

Expand Down Expand Up @@ -243,7 +301,7 @@ def test_trigger_single_multi_scm(
}
get_url.return_value = {
"merged_at": "2021-07-20T09:00:00.123Z",
"base": {"repo": {"full_name": "googleapis/java-trace"}},
"base": {"repo": {"full_name": "googleapis/java-trace", "name": "java-trace"}},
"html_url": "https://github.com/googleapis/java-trace/pull/1234",
"merge_commit_sha": "abcd1234",
"labels": [{"id": 12345, "name": "autorelease: tagged"}],
Expand Down Expand Up @@ -283,7 +341,12 @@ def test_trigger_package(
kokoro_session = Mock()
github.get_url.return_value = {
"merged_at": "2021-01-01T09:00:00.000Z",
"base": {"repo": {"full_name": "GoogleCloudPlatform/functions-framework-java"}},
"base": {
"repo": {
"full_name": "GoogleCloudPlatform/functions-framework-java",
"name": "functions-framework-java",
}
},
"html_url": "https://github.com/GoogleCloudPlatform/functions-framework-java/pull/111",
"labels": [{"id": 111, "name": "autorelease: tagged"}],
"merge_commit_sha": "abcd111",
Expand All @@ -304,7 +367,7 @@ def test_trigger_package(
env_vars={
"AUTORELEASE_PR": "https://github.com/GoogleCloudPlatform/functions-framework-java/pull/111"
},
multi_scm_name="",
multi_scm_name="functions-framework-java",
)


Expand Down Expand Up @@ -342,7 +405,7 @@ def test_trigger_single_skips_already_triggered(
}
get_url.return_value = {
"merged_at": "2021-07-20T09:00:00.123Z",
"base": {"repo": {"full_name": "googleapis/java-trace"}},
"base": {"repo": {"full_name": "googleapis/java-trace", "name": "java-trace"}},
"html_url": "https://github.com/googleapis/java-trace/pull/1234",
"merge_commit_sha": "abcd1234",
"labels": [
Expand Down Expand Up @@ -373,7 +436,12 @@ def test_trigger_multi_scm(
kokoro_session = Mock()
github.get_url.return_value = {
"merged_at": "2021-01-01T09:00:00.000Z",
"base": {"repo": {"full_name": "GoogleCloudPlatform/functions-framework-java"}},
"base": {
"repo": {
"full_name": "GoogleCloudPlatform/functions-framework-java",
"name": "functions-framework-java",
}
},
"html_url": "https://github.com/GoogleCloudPlatform/functions-framework-java/pull/111",
"labels": [{"id": 111, "name": "autorelease: tagged"}],
"merge_commit_sha": "abcd111",
Expand Down

0 comments on commit cc1e66d

Please sign in to comment.