Use zip file generated by repo under test script.

The repo script knows all the different locations and creating the zip
file there is more deterministic. This also allows us to calculate the
local api docs path to calculate its hash before sending the artifact
for provenance generation.

Bug: https://github.com/flutter/flutter/issues/115489
Change-Id: Idfb63e25f51823da52e2c74e9964c5c3ea67a149
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/36822
Reviewed-by: Jesse Seales <jseales@google.com>
Commit-Queue: Godofredo Contreras <godofredoc@google.com>
diff --git a/recipe_modules/adhoc_validation/__init__.py b/recipe_modules/adhoc_validation/__init__.py
index 9952250..671efed 100644
--- a/recipe_modules/adhoc_validation/__init__.py
+++ b/recipe_modules/adhoc_validation/__init__.py
@@ -1,4 +1,5 @@
 DEPS = [
+    'flutter/archives',
     'flutter/flutter_bcid',
     'flutter/bucket_util',
     'flutter/firebase',
diff --git a/recipe_modules/adhoc_validation/api.py b/recipe_modules/adhoc_validation/api.py
index cf3a8d7..721f832 100644
--- a/recipe_modules/adhoc_validation/api.py
+++ b/recipe_modules/adhoc_validation/api.py
@@ -83,9 +83,11 @@
             # Do not upload on docs_deploy.
             if not validation == 'docs_deploy':
               self.m.flutter_bcid.report_stage(BcidStage.UPLOAD.value)
-              dst = self.m.bucket_util.upload_folder('Upload API Docs', docs_path,
-                'doc', "api_docs.zip")
-              self.m.flutter_bcid.upload_provenance(docs_path, dst)
+              src = docs_path.join('api_docs.zip')
+              commit = self.m.repo_util.get_commit(checkout_path)
+              dst = 'gs://flutter_infra_release/flutter/%s/api_docs.zip' % commit
+              self.m.archives.upload_artifact(src, dst)
+              self.m.flutter_bcid.upload_provenance(src, dst)
               self.m.flutter_bcid.report_stage(BcidStage.UPLOAD_COMPLETE.value)
             project = self.m.properties.get('firebase_project')
             # Only deploy to firebase directly if this is master or main.
diff --git a/recipe_modules/adhoc_validation/examples/full.expected/docs.json b/recipe_modules/adhoc_validation/examples/full.expected/docs.json
index 04b0bbb..a86fcb7 100644
--- a/recipe_modules/adhoc_validation/examples/full.expected/docs.json
+++ b/recipe_modules/adhoc_validation/examples/full.expected/docs.json
@@ -144,9 +144,11 @@
   },
   {
     "cmd": [
-      "python",
-      "RECIPE_MODULE[flutter::zip]/resources/zip.py"
+      "git",
+      "rev-parse",
+      "HEAD"
     ],
+    "cwd": "[START_DIR]/flutter sdk",
     "env": {
       "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
       "GIT_BRANCH": "",
@@ -164,8 +166,8 @@
         "[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\"}",
+    "infra_step": true,
+    "name": "Docs.git rev-parse",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -177,8 +179,10 @@
       "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
       "--json-output",
       "/path/to/tmp/json",
-      "rmtree",
-      "[CLEANUP]/tmp_tmp_1"
+      "ensure-directory",
+      "--mode",
+      "0777",
+      "[CLEANUP]/tmp_tmp_1/flutter/12345abcde12345abcde12345abcde12345abcde"
     ],
     "env": {
       "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
@@ -198,12 +202,83 @@
       ]
     },
     "infra_step": true,
-    "name": "Docs.temp dir for Upload API Docs",
+    "name": "Docs.Ensure flutter/12345abcde12345abcde12345abcde12345abcde",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[START_DIR]/flutter sdk/dev/docs/api_docs.zip",
+      "[CLEANUP]/tmp_tmp_1/flutter/12345abcde12345abcde12345abcde12345abcde"
+    ],
+    "env": {
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "GIT_BRANCH": "",
+      "LUCI_BRANCH": "stable",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "linux",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "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.Copy gs://flutter_infra_release/flutter/12345abcde12345abcde12345abcde12345abcde/api_docs.zip",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python3",
+      "-u",
+      "RECIPE_MODULE[depot_tools::gsutil]/resources/gsutil_smart_retry.py",
+      "--",
+      "RECIPE_REPO[depot_tools]/gsutil.py",
+      "----",
+      "cp",
+      "-r",
+      "[CLEANUP]/tmp_tmp_1/*",
+      "gs://flutter_infra_release/"
+    ],
+    "env": {
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "GIT_BRANCH": "",
+      "LUCI_BRANCH": "stable",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "linux",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "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.gsutil flutter/12345abcde12345abcde12345abcde12345abcde/api_docs.zip",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LINK@gsutil.upload@https://console.cloud.google.com/storage/browser/flutter_infra_release/@@@"
+    ]
+  },
+  {
     "name": "$result"
   }
 ]
\ No newline at end of file
diff --git a/recipe_modules/adhoc_validation/examples/full.expected/linux.json b/recipe_modules/adhoc_validation/examples/full.expected/linux.json
index c862c79..c55128e 100644
--- a/recipe_modules/adhoc_validation/examples/full.expected/linux.json
+++ b/recipe_modules/adhoc_validation/examples/full.expected/linux.json
@@ -144,9 +144,11 @@
   },
   {
     "cmd": [
-      "python",
-      "RECIPE_MODULE[flutter::zip]/resources/zip.py"
+      "git",
+      "rev-parse",
+      "HEAD"
     ],
+    "cwd": "[START_DIR]/flutter sdk",
     "env": {
       "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
       "GIT_BRANCH": "main",
@@ -164,8 +166,8 @@
         "[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\"}",
+    "infra_step": true,
+    "name": "Docs.git rev-parse",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -177,8 +179,10 @@
       "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
       "--json-output",
       "/path/to/tmp/json",
-      "rmtree",
-      "[CLEANUP]/tmp_tmp_1"
+      "ensure-directory",
+      "--mode",
+      "0777",
+      "[CLEANUP]/tmp_tmp_1/flutter/12345abcde12345abcde12345abcde12345abcde"
     ],
     "env": {
       "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
@@ -198,13 +202,84 @@
       ]
     },
     "infra_step": true,
-    "name": "Docs.temp dir for Upload API Docs",
+    "name": "Docs.Ensure flutter/12345abcde12345abcde12345abcde12345abcde",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
     "cmd": [
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "[START_DIR]/flutter sdk/dev/docs/api_docs.zip",
+      "[CLEANUP]/tmp_tmp_1/flutter/12345abcde12345abcde12345abcde12345abcde"
+    ],
+    "env": {
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "GIT_BRANCH": "main",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "linux",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "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.Copy gs://flutter_infra_release/flutter/12345abcde12345abcde12345abcde12345abcde/api_docs.zip",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python3",
+      "-u",
+      "RECIPE_MODULE[depot_tools::gsutil]/resources/gsutil_smart_retry.py",
+      "--",
+      "RECIPE_REPO[depot_tools]/gsutil.py",
+      "----",
+      "cp",
+      "-r",
+      "[CLEANUP]/tmp_tmp_1/*",
+      "gs://flutter_infra_release/"
+    ],
+    "env": {
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "GIT_BRANCH": "main",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "linux",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "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.gsutil flutter/12345abcde12345abcde12345abcde12345abcde/api_docs.zip",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LINK@gsutil.upload@https://console.cloud.google.com/storage/browser/flutter_infra_release/@@@"
+    ]
+  },
+  {
+    "cmd": [
       "luci-auth",
       "token",
       "-scopes",