release/release_builder.py schedule all platform targets when in monorepo context

Bug: https://github.com/flutter/flutter/issues/161782
Change-Id: If4485d0160e7d790adf9cecf7eb4b3f9d504c4ae
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/62220
Commit-Queue: Christopher Fujino <fujino@google.com>
Reviewed-by: Jackson Gardner <jacksongardner@google.com>
diff --git a/recipes/release/release_builder.expected/engine_monorepo.json b/recipes/release/release_builder.expected/linux_engine_monorepo.json
similarity index 96%
rename from recipes/release/release_builder.expected/engine_monorepo.json
rename to recipes/release/release_builder.expected/linux_engine_monorepo.json
index d33f549..bfea999 100644
--- a/recipes/release/release_builder.expected/engine_monorepo.json
+++ b/recipes/release/release_builder.expected/linux_engine_monorepo.json
@@ -289,21 +289,18 @@
       "@@@STEP_LOG_LINE@json.output@      \"enabled_branches\": [@@@",
       "@@@STEP_LOG_LINE@json.output@        \"flutter-3.2-candidate.5\"@@@",
       "@@@STEP_LOG_LINE@json.output@      ],@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"name\": \"linux packaging one\",@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"properties\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"$flutter/osx_sdk\": \"{\\\"sdk_version\\\": \\\"14a5294e\\\"}\"@@@",
-      "@@@STEP_LOG_LINE@json.output@      },@@@",
+      "@@@STEP_LOG_LINE@json.output@      \"name\": \"Linux flutter_test\",@@@",
+      "@@@STEP_LOG_LINE@json.output@      \"properties\": {},@@@",
       "@@@STEP_LOG_LINE@json.output@      \"recipe\": \"release/something\"@@@",
       "@@@STEP_LOG_LINE@json.output@    },@@@",
       "@@@STEP_LOG_LINE@json.output@    {@@@",
       "@@@STEP_LOG_LINE@json.output@      \"drone_dimensions\": [@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"os=Linux\"@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"os=Mac\"@@@",
       "@@@STEP_LOG_LINE@json.output@      ],@@@",
       "@@@STEP_LOG_LINE@json.output@      \"enabled_branches\": [@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"beta\",@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"main\"@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"flutter-3.2-candidate.5\"@@@",
       "@@@STEP_LOG_LINE@json.output@      ],@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"name\": \"linux packaging two\",@@@",
+      "@@@STEP_LOG_LINE@json.output@      \"name\": \"Mac flutter_test\",@@@",
       "@@@STEP_LOG_LINE@json.output@      \"properties\": {@@@",
       "@@@STEP_LOG_LINE@json.output@        \"$flutter/osx_sdk\": \"{\\\"sdk_version\\\": \\\"14a5294e\\\"}\"@@@",
       "@@@STEP_LOG_LINE@json.output@      },@@@",
diff --git a/recipes/release/release_builder.expected/framework_single_repo.json b/recipes/release/release_builder.expected/linux_framework_single_repo.json
similarity index 94%
rename from recipes/release/release_builder.expected/framework_single_repo.json
rename to recipes/release/release_builder.expected/linux_framework_single_repo.json
index 9e292f7..785dbdc 100644
--- a/recipes/release/release_builder.expected/framework_single_repo.json
+++ b/recipes/release/release_builder.expected/linux_framework_single_repo.json
@@ -289,21 +289,18 @@
       "@@@STEP_LOG_LINE@json.output@      \"enabled_branches\": [@@@",
       "@@@STEP_LOG_LINE@json.output@        \"flutter-3.2-candidate.5\"@@@",
       "@@@STEP_LOG_LINE@json.output@      ],@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"name\": \"linux packaging one\",@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"properties\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"$flutter/osx_sdk\": \"{\\\"sdk_version\\\": \\\"14a5294e\\\"}\"@@@",
-      "@@@STEP_LOG_LINE@json.output@      },@@@",
+      "@@@STEP_LOG_LINE@json.output@      \"name\": \"Linux flutter_test\",@@@",
+      "@@@STEP_LOG_LINE@json.output@      \"properties\": {},@@@",
       "@@@STEP_LOG_LINE@json.output@      \"recipe\": \"release/something\"@@@",
       "@@@STEP_LOG_LINE@json.output@    },@@@",
       "@@@STEP_LOG_LINE@json.output@    {@@@",
       "@@@STEP_LOG_LINE@json.output@      \"drone_dimensions\": [@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"os=Linux\"@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"os=Mac\"@@@",
       "@@@STEP_LOG_LINE@json.output@      ],@@@",
       "@@@STEP_LOG_LINE@json.output@      \"enabled_branches\": [@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"beta\",@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"main\"@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"flutter-3.2-candidate.5\"@@@",
       "@@@STEP_LOG_LINE@json.output@      ],@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"name\": \"linux packaging two\",@@@",
+      "@@@STEP_LOG_LINE@json.output@      \"name\": \"Mac flutter_test\",@@@",
       "@@@STEP_LOG_LINE@json.output@      \"properties\": {@@@",
       "@@@STEP_LOG_LINE@json.output@        \"$flutter/osx_sdk\": \"{\\\"sdk_version\\\": \\\"14a5294e\\\"}\"@@@",
       "@@@STEP_LOG_LINE@json.output@      },@@@",
diff --git a/recipes/release/release_builder.expected/throws_assertion_on_unsupported_repo.json b/recipes/release/release_builder.expected/throws_assertion_on_unsupported_repo.json
index a4ef653..ffde707 100644
--- a/recipes/release/release_builder.expected/throws_assertion_on_unsupported_repo.json
+++ b/recipes/release/release_builder.expected/throws_assertion_on_unsupported_repo.json
@@ -231,10 +231,10 @@
       "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/recipe_deps.py\", in run_steps",
       "    recipe_result = self.global_symbols['RunSteps'](*args)",
       "                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
-      "  File \"RECIPE_REPO[flutter]/recipes/release/release_builder.py\", line 151, in RunSteps",
+      "  File \"RECIPE_REPO[flutter]/recipes/release/release_builder.py\", line 161, in RunSteps",
       "    context = GetRepoContext(api, repository, checkout_path)",
       "              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
-      "  File \"RECIPE_REPO[flutter]/recipes/release/release_builder.py\", line 113, in GetRepoContext",
+      "  File \"RECIPE_REPO[flutter]/recipes/release/release_builder.py\", line 120, in GetRepoContext",
       "    assert False, f'the repository {repository} is not supported by the release/release_builder.py recipe'",
       "           ^^^^^",
       "AssertionError: the repository openpay is not supported by the release/release_builder.py recipe"
diff --git a/recipes/release/release_builder.py b/recipes/release/release_builder.py
index d71cfbf..6be9f7f 100644
--- a/recipes/release/release_builder.py
+++ b/recipes/release/release_builder.py
@@ -47,8 +47,13 @@
   MONOREPO = 2
 
 
-def ShouldRun(api, git_ref, target, release_branch, retry_override_list):
-  """Validates if a target should run based on platform, channel and repo."""
+def ShouldRun(
+    api, git_ref, target, release_branch, retry_override_list, repo_context
+):
+  """Validates if a target should run based on platform, channel and repo.
+
+  If repo_context == RepoContext.MONOREPO, then the target platform does not
+  need to match the current platform."""
 
   # If retry_override_list list of targets to retry has been provided,
   # skip the target if not specified on list.
@@ -71,8 +76,10 @@
       return False
 
   release_build = target.get('properties', {}).get('release_build', False)
-  for_this_platform = target['name'].lower().startswith(api.platform.name)
+  for_this_platform = repo_context == RepoContext.MONOREPO or target[
+      'name'].lower().startswith(api.platform.name)
   # Postsubmit for engine and flutter repositories.
+  # TODO(fujino): once 3.29 reaches stable, ignore [for_this_platform]
   if (release_build and for_this_platform and
       (git_ref not in RELEASE_CHANNELS)):
     return True
@@ -113,7 +120,9 @@
   assert False, f'the repository {repository} is not supported by the release/release_builder.py recipe'
 
 
-def ScheduleBuildsForRepo(api, checkout_path, git_ref, retry_override_list):
+def ScheduleBuildsForRepo(
+    api, checkout_path, git_ref, retry_override_list, context
+):
   ci_yaml_path = checkout_path / '.ci.yaml'
   ci_yaml = api.yaml.read('read ci yaml', ci_yaml_path, api.json.output())
 
@@ -128,7 +137,8 @@
   build_results = []
   with api.step.nest('launch builds') as presentation:
     for target in ci_yaml.json.output['targets']:
-      if ShouldRun(api, git_ref, target, release_branch, retry_override_list):
+      if ShouldRun(api, git_ref, target, release_branch, retry_override_list,
+                   context):
         target = api.shard_util.pre_process_properties(target)
         tasks.update(
             api.shard_util.schedule([target],
@@ -165,7 +175,9 @@
 
   if context in (RepoContext.SINGLE_REPO_FRAMEWORK, RepoContext.SINGLE_REPO_ENGINE):
     collect_and_display_builds(
-        ScheduleBuildsForRepo(api, checkout_path, git_ref, retry_override_list)
+        ScheduleBuildsForRepo(
+            api, checkout_path, git_ref, retry_override_list, context
+        )
     )
   elif context == RepoContext.MONOREPO:
     collect_and_display_builds(
@@ -174,11 +186,18 @@
             checkout_path / 'engine' / 'src' / 'flutter',
             git_ref,
             retry_override_list,
+            context,
         )
     )
 
     collect_and_display_builds(
-        ScheduleBuildsForRepo(api, checkout_path, git_ref, retry_override_list)
+        ScheduleBuildsForRepo(
+            api,
+            checkout_path,
+            git_ref,
+            retry_override_list,
+            context,
+        )
     )
   else:
     assert False, "You must update release/release_builder.py to handle a new RepoContext"  # pragma: nocover
@@ -227,13 +246,35 @@
         api.step_data('read ci yaml.parse', api.json.output(tasks_dict)),
     )
 
+  multiplatform_tasks = {
+      'targets': [
+          {
+              'name': 'Linux flutter_test',
+              'recipe': 'release/something',
+              'properties': {},
+              'enabled_branches': ['flutter-3.2-candidate.5'],
+              'drone_dimensions': ['os=Linux']
+          },
+          {
+              'name': 'Mac flutter_test',
+              'recipe': 'release/something',
+              'properties': {
+                  '$flutter/osx_sdk': '{"sdk_version": "14a5294e"}'
+              },
+              'enabled_branches': ['flutter-3.2-candidate.5'],
+              'drone_dimensions': ['os=Mac']
+          },
+      ]
+  }
   tasks_dict_scheduler = {
       'targets': [
           {
               'name': 'linux packaging one',
               'recipe': 'release/something',
               #'scheduler': 'release',
-              'properties': {'$flutter/osx_sdk': '{"sdk_version": "14a5294e"}'},
+              'properties': {
+                  '$flutter/osx_sdk': '{"sdk_version": "14a5294e"}'
+              },
               'enabled_branches': ['flutter-3.2-candidate.5'],
               'drone_dimensions': ['os=Linux']
           },
@@ -241,7 +282,9 @@
               'name': 'linux packaging two',
               'recipe': 'release/something',
               #'scheduler': 'release',
-              'properties': {'$flutter/osx_sdk': '{"sdk_version": "14a5294e"}'},
+              'properties': {
+                  '$flutter/osx_sdk': '{"sdk_version": "14a5294e"}'
+              },
               'enabled_branches': ['beta', 'main'],
               'drone_dimensions': ['os=Linux']
           }
@@ -310,8 +353,9 @@
       ),
   )
   yield api.test(
-      'framework_single_repo',
+      'linux_framework_single_repo',
       api.properties(environment='Staging', repository='framework'),
+      api.platform.name('linux'),
       api.buildbucket.try_build(
           project='dart-internal',
           bucket='flutter',
@@ -322,7 +366,7 @@
           git_ref='refs/heads/%s' % git_ref,
       ),
       api.step_data(
-          'read ci yaml.parse', api.json.output(tasks_dict_scheduler)
+          'read ci yaml.parse', api.json.output(multiplatform_tasks)
       ),
       api.step_data(
           'Identify branches.git branch',
@@ -331,11 +375,12 @@
       ),
   )
   yield api.test(
-      'engine_monorepo',
+      'linux_engine_monorepo',
       api.properties(
           environment='Staging',
           repository='flutter',
       ),
+      api.platform.name('linux'),
       api.path.dirs_exist(
           api.path.start_dir / 'mirrors' / 'flutter' / 'engine',
       ),
@@ -350,7 +395,7 @@
       ),
       # Engine .ci.yaml
       api.step_data(
-          'read ci yaml.parse', api.json.output(tasks_dict_scheduler)
+          'read ci yaml.parse', api.json.output(multiplatform_tasks)
       ),
       # Framework .ci.yaml
       api.step_data(