Reland "Start uploading docs to GCS".

Start uploading docs to GCS to simplify the release workflows and bring
down release time down to 15 mins.

This change has been reverted twice:

* Trying to upload to GCS multiple times on retries without actually
  passing the override flag.
* Trying to zip the documentation in the path where documents were are
  not created.

Change-Id: I9995e2ace5d995cb9bab94d242995ad91e812dc8
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/34121
Commit-Queue: Godofredo Contreras <godofredoc@google.com>
Reviewed-by: Keyong Han <keyonghan@google.com>
diff --git a/recipe_modules/adhoc_validation/__init__.py b/recipe_modules/adhoc_validation/__init__.py
index 80ac1c5..5ab5be1 100644
--- a/recipe_modules/adhoc_validation/__init__.py
+++ b/recipe_modules/adhoc_validation/__init__.py
@@ -1,4 +1,5 @@
 DEPS = [
+    'flutter/bucket_util',
     'flutter/firebase',
     'flutter/flutter_deps',
     'flutter/kms',
diff --git a/recipe_modules/adhoc_validation/api.py b/recipe_modules/adhoc_validation/api.py
index 1881191..b036157 100644
--- a/recipe_modules/adhoc_validation/api.py
+++ b/recipe_modules/adhoc_validation/api.py
@@ -62,6 +62,7 @@
           self.m.test_utils.run_test(validation, [resource_name])
           if validation == 'docs' and self.m.properties.get('firebase_project'):
             docs_path = checkout_path.join('dev', 'docs')
+            self.m.bucket_util.upload_folder('Upload API Docs', docs_path, 'doc', "api_docs.zip")
             project = self.m.properties.get('firebase_project')
             self.m.firebase.deploy_docs(
                 env=env,
diff --git a/recipe_modules/adhoc_validation/examples/full.expected/linux.json b/recipe_modules/adhoc_validation/examples/full.expected/linux.json
index da960ab..f91dc9d 100644
--- a/recipe_modules/adhoc_validation/examples/full.expected/linux.json
+++ b/recipe_modules/adhoc_validation/examples/full.expected/linux.json
@@ -75,6 +75,67 @@
   },
   {
     "cmd": [
+      "python",
+      "RECIPE_MODULE[flutter::zip]/resources/zip.py"
+    ],
+    "env": {
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "GIT_BRANCH": "",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "linux",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "",
+      "SDK_CHECKOUT_PATH": "[START_DIR]/flutter sdk"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[START_DIR]/flutter sdk/bin",
+        "[START_DIR]/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "name": "Docs.Zip doc",
+    "stdin": "{\"entries\": [{\"path\": \"[START_DIR]/flutter sdk/dev/docs/doc\", \"type\": \"dir\"}], \"output\": \"[CLEANUP]/tmp_tmp_1/api_docs.zip\", \"root\": \"[START_DIR]/flutter sdk/dev/docs\"}",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "rmtree",
+      "[CLEANUP]/tmp_tmp_1"
+    ],
+    "env": {
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "GIT_BRANCH": "",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "linux",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "",
+      "SDK_CHECKOUT_PATH": "[START_DIR]/flutter sdk"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[START_DIR]/flutter sdk/bin",
+        "[START_DIR]/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "infra_step": true,
+    "name": "Docs.temp dir for Upload API Docs",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
       "luci-auth",
       "token",
       "-scopes",
@@ -114,7 +175,7 @@
       "/path/to/tmp/json",
       "copy",
       "extra.secret.token.should.not.be.logged",
-      "[CLEANUP]/tmp_tmp_1"
+      "[CLEANUP]/tmp_tmp_2"
     ],
     "env": {
       "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
@@ -164,7 +225,7 @@
       "PUB_CACHE": "[START_DIR]/.pub-cache",
       "REVISION": "",
       "SDK_CHECKOUT_PATH": "[START_DIR]/flutter sdk",
-      "TOKEN_PATH": "[CLEANUP]/tmp_tmp_1"
+      "TOKEN_PATH": "[CLEANUP]/tmp_tmp_2"
     },
     "env_prefixes": {
       "PATH": [
@@ -193,7 +254,7 @@
       "PUB_CACHE": "[START_DIR]/.pub-cache",
       "REVISION": "",
       "SDK_CHECKOUT_PATH": "[START_DIR]/flutter sdk",
-      "TOKEN_PATH": "[CLEANUP]/tmp_tmp_1"
+      "TOKEN_PATH": "[CLEANUP]/tmp_tmp_2"
     },
     "env_prefixes": {
       "PATH": [
diff --git a/recipe_modules/bucket_util/api.py b/recipe_modules/bucket_util/api.py
index e7b1d40..264f98e 100644
--- a/recipe_modules/bucket_util/api.py
+++ b/recipe_modules/bucket_util/api.py
@@ -72,7 +72,8 @@
       remote_name = '%s/%s' % (platform, zip_name) if platform else zip_name
       local_zip = temp_dir.join(zip_name)
       remote_zip = self.get_cloud_path(remote_name)
-      parent_directory = self.m.path['cache'].join('builder', parent_directory)
+      if isinstance(parent_directory, str):
+        parent_directory = self.m.path['cache'].join('builder', parent_directory)
       pkg = self.m.zip.make_package(parent_directory, local_zip)
       pkg.add_directory(parent_directory.join(folder_name))