Migrate how flutter/docs determines a release branch.

General cleanup after https://github.com/flutter/flutter/issues/171045; we don't want to have multiple ways of determining a release branch across the recipes codebase.

Change-Id: If8536e2826e88d3d07c46b49a5f8796602995850
Bug: https://github.com/flutter/flutter/issues/171045
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/67100
Reviewed-by: Jason Simmons <jsimmons@google.com>
Commit-Queue: Matan Lurey <matanl@google.com>
diff --git a/recipes/flutter/docs.expected/docs_generated_but_not_uploaded_on_release_candidate_branch.json b/recipes/flutter/docs.expected/docs_generated_but_not_uploaded_on_release_candidate_branch.json
index c7af4d4..b68ce2f 100644
--- a/recipes/flutter/docs.expected/docs_generated_but_not_uploaded_on_release_candidate_branch.json
+++ b/recipes/flutter/docs.expected/docs_generated_but_not_uploaded_on_release_candidate_branch.json
@@ -445,9 +445,14 @@
   },
   {
     "cmd": [
-      "git",
-      "rev-parse",
-      "remotes/origin/flutter-3.2-candidate.5"
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[START_DIR]/flutter/bin/internal/release-candidate-branch.version",
+      "/path/to/tmp/"
     ],
     "cwd": "[START_DIR]/flutter",
     "env": {
@@ -481,47 +486,11 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "git rev-parse (2)"
-  },
-  {
-    "cmd": [
-      "git",
-      "rev-parse",
-      "HEAD"
-    ],
-    "cwd": "[START_DIR]/flutter",
-    "env": {
-      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
-      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
-      "GIT_BRANCH": "",
-      "LUCI_BRANCH": "",
-      "LUCI_CI": "True",
-      "LUCI_PR": "",
-      "OS": "linux",
-      "PUB_CACHE": "[START_DIR]/.pub-cache",
-      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
-      "SDK_CHECKOUT_PATH": "[START_DIR]/flutter"
-    },
-    "env_prefixes": {
-      "PATH": [
-        "[START_DIR]/flutter/bin",
-        "[START_DIR]/flutter/bin/cache/dart-sdk/bin"
-      ]
-    },
-    "infra_step": true,
-    "luci_context": {
-      "realm": {
-        "name": "flutter:flutter"
-      },
-      "resultdb": {
-        "current_invocation": {
-          "name": "invocations/build:8945511751514863184",
-          "update_token": "token"
-        },
-        "hostname": "rdbhost"
-      }
-    },
-    "name": "git rev-parse (3)"
+    "name": "read release-candidate-branch.version",
+    "~followup_annotations": [
+      "@@@STEP_LOG_LINE@release-candidate-branch.version@flutter-3.2-candidate.5@@@",
+      "@@@STEP_LOG_END@release-candidate-branch.version@@@"
+    ]
   },
   {
     "cmd": [
@@ -689,7 +658,7 @@
         "hostname": "rdbhost"
       }
     },
-    "name": "git rev-parse (4)"
+    "name": "git rev-parse (2)"
   },
   {
     "cmd": [
diff --git a/recipes/flutter/docs.py b/recipes/flutter/docs.py
index 1348042..a512fc5 100644
--- a/recipes/flutter/docs.py
+++ b/recipes/flutter/docs.py
@@ -8,6 +8,7 @@
 
 DEPS = [
     'flutter/archives',
+    'flutter/common',
     'flutter/firebase',
     'flutter/flutter_bcid',
     'flutter/flutter_deps',
@@ -19,6 +20,7 @@
     'recipe_engine/buildbucket',
     'recipe_engine/context',
     'recipe_engine/defer',
+    'recipe_engine/file',
     'recipe_engine/path',
     'recipe_engine/properties',
     'recipe_engine/raw_io',
@@ -56,7 +58,8 @@
   checkout_path = api.repo_util.sdk_checkout_path()
   validation = api.properties.get('validation')
   if (validation
-      == 'docs') and api.repo_util.is_release_candidate_branch(checkout_path):
+      == 'docs') and api.common.get_release_candidate_branch_from_checkout(
+          checkout_path):
     env['LUCI_BRANCH'] = 'stable'
     env['LUCI_CI'] = True
 
@@ -67,7 +70,8 @@
       'release_ref'
   ) or api.buildbucket.gitiles_commit.ref
   with api.context(env=env, env_prefixes=env_prefixes):
-    if (validation in ('docs', 'docs_deploy') and api.properties.get('firebase_project')):
+    if (validation in ('docs', 'docs_deploy') and
+        api.properties.get('firebase_project')):
       docs_path = checkout_path / 'dev/docs'
       # Do not upload on docs_deploy.
       if not validation == 'docs_deploy':
@@ -165,10 +169,18 @@
       )
   )
   # Test release candidate branch.
+  flutter_path = api.path.start_dir / 'flutter'
+  version_path = flutter_path / 'bin/internal/release-candidate-branch.version'
+
   yield api.test(
       'docs_generated_but_not_uploaded_on_release_candidate_branch',
       api.repo_util.flutter_environment_data(),
       api.properties(validation='docs', firebase_project='myproject'),
+      api.path.exists(version_path),
+      api.step_data(
+          'read release-candidate-branch.version',
+          api.file.read_text('flutter-3.2-candidate.5'),
+      ),
       api.buildbucket.ci_build(
           project='flutter',
           bucket='flutter',