Use recipes from corresponding release candidate branch.

This is to ensure builders are using branched out versions of recipes.

Bug: https://github.com/flutter/flutter/issues/128079
Change-Id: Ic2c079de7c12712139e488ea6c58a3a254617f49
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/45321
Commit-Queue: Godofredo Contreras <godofredoc@google.com>
Reviewed-by: Jesse Seales <jseales@google.com>
Reviewed-by: Drew Roen <drewroen@google.com>
(cherry picked from commit 32bf5af4857768f17e36add4e41c58f774557c31)
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/45360
diff --git a/recipes/release/release_builder.expected/basic_linux_beta.json b/recipes/release/release_builder.expected/basic_linux_beta.json
index 94c5598..167fdbd 100644
--- a/recipes/release/release_builder.expected/basic_linux_beta.json
+++ b/recipes/release/release_builder.expected/basic_linux_beta.json
@@ -291,6 +291,62 @@
   },
   {
     "cmd": [],
+    "name": "Identify branches"
+  },
+  {
+    "cmd": [
+      "git",
+      "rev-parse",
+      "HEAD"
+    ],
+    "cwd": "[START_DIR]/mirrors/engine",
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "prod:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Identify branches.git rev-parse",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "branch",
+      "-a",
+      "--contains",
+      "12345abcde12345abcde12345abcde12345abcde"
+    ],
+    "cwd": "[START_DIR]/mirrors/engine",
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "prod:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Identify branches.git branch",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [],
     "name": "launch builds"
   },
   {
diff --git a/recipes/release/release_builder.expected/basic_linux_main.json b/recipes/release/release_builder.expected/basic_linux_main.json
index 4c3646b..9574748 100644
--- a/recipes/release/release_builder.expected/basic_linux_main.json
+++ b/recipes/release/release_builder.expected/basic_linux_main.json
@@ -292,6 +292,62 @@
   },
   {
     "cmd": [],
+    "name": "Identify branches"
+  },
+  {
+    "cmd": [
+      "git",
+      "rev-parse",
+      "HEAD"
+    ],
+    "cwd": "[START_DIR]/mirrors/engine",
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "prod:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Identify branches.git rev-parse",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
+      "branch",
+      "-a",
+      "--contains",
+      "12345abcde12345abcde12345abcde12345abcde"
+    ],
+    "cwd": "[START_DIR]/mirrors/engine",
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "prod:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Identify branches.git branch",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [],
     "name": "launch builds"
   },
   {
diff --git a/recipes/release/release_builder.py b/recipes/release/release_builder.py
index 7ff7378..e595a3b 100644
--- a/recipes/release/release_builder.py
+++ b/recipes/release/release_builder.py
@@ -67,6 +67,11 @@
   ci_yaml_path = checkout_path.join('.ci.yaml')
   ci_yaml = api.yaml.read('read ci yaml', ci_yaml_path, api.json.output())
 
+  # Get release branch.
+  branches = api.repo_util.current_commit_branches(checkout_path)
+  branches = [b for b in branches if b.startswith('flutter')]
+  release_branch = branches[0] if branches else 'main'
+
   # Foreach target defined in .ci.yaml, if it contains
   # release_build: True, then spawn a subbuild.
   tasks = {}
@@ -75,9 +80,13 @@
     for target in ci_yaml.json.output['targets']:
       if ShouldRun(api, git_ref, target):
         target = api.shard_util_v2.pre_process_properties(target)
-        tasks.update(api.shard_util_v2.schedule([
-            target,
-        ], presentation))
+        tasks.update(
+            api.shard_util_v2.schedule([
+                target,
+            ],
+                                       presentation,
+                                       branch=release_branch)
+        )
   with api.step.nest('collect builds') as presentation:
     build_results = api.shard_util_v2.collect(tasks)