[gn-sdk]Publish the GN SDK to GCS

This change publishes the GN SDK to GCS on release alongside CIPD and
the IDK (integrator development kit, formerly known as the "core" SDK)

Change-Id: If203891308ca7ec1d051406f851102dea67d0f4e
diff --git a/recipes/sdk.expected/global_ci.json b/recipes/sdk.expected/global_ci.json
index c622738..8348752 100644
--- a/recipes/sdk.expected/global_ci.json
+++ b/recipes/sdk.expected/global_ci.json
@@ -1752,6 +1752,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1760,21 +1764,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
diff --git a/recipes/sdk.expected/local_ci.json b/recipes/sdk.expected/local_ci.json
index 801d957..397566c 100644
--- a/recipes/sdk.expected/local_ci.json
+++ b/recipes/sdk.expected/local_ci.json
@@ -1738,6 +1738,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1746,21 +1750,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
diff --git a/recipes/sdk.expected/local_ci_mac.json b/recipes/sdk.expected/local_ci_mac.json
index 78f3615..f9f4cfb 100644
--- a/recipes/sdk.expected/local_ci_mac.json
+++ b/recipes/sdk.expected/local_ci_mac.json
@@ -1833,6 +1833,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1841,21 +1845,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
diff --git a/recipes/sdk.expected/local_cq.json b/recipes/sdk.expected/local_cq.json
index 9dd1eb8..eb16d8e 100644
--- a/recipes/sdk.expected/local_cq.json
+++ b/recipes/sdk.expected/local_cq.json
@@ -1855,6 +1855,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1863,21 +1867,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
diff --git a/recipes/sdk.expected/release_ci.json b/recipes/sdk.expected/release_ci.json
index f22d2bc..17f3adb 100644
--- a/recipes/sdk.expected/release_ci.json
+++ b/recipes/sdk.expected/release_ci.json
@@ -1876,6 +1876,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1884,21 +1888,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -2453,14 +2463,41 @@
   },
   {
     "cmd": [],
-    "name": "cipd"
+    "name": "publish gn sdk"
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-vpython-spec",
+      "RECIPE_MODULE[fuchsia::gsutil]/resources/gsutil.vpython",
+      "-u",
+      "[START_DIR]/cipd/gsutil/gsutil",
+      "-o",
+      "GSUtil:software_update_check_period=0",
+      "cp",
+      "[CLEANUP]/gn.tar.gz",
+      "gs://fuchsia/development/8945511751514863184/sdk/linux-amd64/gn.tar.gz"
+    ],
+    "infra_step": true,
+    "name": "publish gn sdk.upload new gn fuchsia-sdk 8945511751514863184",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LINK@gsutil.upload@https://storage.googleapis.com/fuchsia/development/8945511751514863184/sdk/linux-amd64/gn.tar.gz@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "publish gn sdk.cipd",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
   },
   {
     "cmd": [
       "cipd",
       "pkg-build",
       "-pkg-def",
-      "{\"data\": [{\"dir\": \".\", \"exclude\": []}, {\"version_file\": \".versions/gn.cipd_version\"}], \"install_mode\": \"copy\", \"package\": \"fuchsia/sdk/gn/${platform}\", \"root\": \"[CLEANUP]/sdk-gn\"}",
+      "{\"data\": [{\"dir\": \".\", \"exclude\": []}, {\"version_file\": \".versions/gn.cipd_version\"}], \"install_mode\": \"copy\", \"package\": \"fuchsia/sdk/gn/${platform}\", \"root\": \"[CLEANUP]/sdk-bazel\"}",
       "-out",
       "[CLEANUP]/gn.cipd",
       "-hash-algo",
@@ -2468,9 +2505,9 @@
       "-json-output",
       "/path/to/tmp/json"
     ],
-    "name": "cipd.build fuchsia/sdk/gn/${platform}",
+    "name": "publish gn sdk.cipd.build fuchsia/sdk/gn/${platform}",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_NEST_LEVEL@2@@@",
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
       "@@@STEP_LOG_LINE@json.output@    \"instance_id\": \"40-chars-fake-of-the-package-instance_id\", @@@",
@@ -2490,9 +2527,9 @@
       "-json-output",
       "/path/to/tmp/json"
     ],
-    "name": "cipd.cipd search fuchsia/sdk/gn/${platform} git_revision:c22471f4e3f842ae18dd9adec82ed9eb78ed1127",
+    "name": "publish gn sdk.cipd.cipd search fuchsia/sdk/gn/${platform} git_revision:c22471f4e3f842ae18dd9adec82ed9eb78ed1127",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_NEST_LEVEL@2@@@",
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"result\": [@@@",
       "@@@STEP_LOG_LINE@json.output@    {@@@",
@@ -2506,9 +2543,9 @@
   },
   {
     "cmd": [],
-    "name": "cipd.Package is up-to-date",
+    "name": "publish gn sdk.cipd.Package is up-to-date",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
diff --git a/recipes/sdk.expected/release_ci_image_failure.json b/recipes/sdk.expected/release_ci_image_failure.json
index 6542062..14e3633 100644
--- a/recipes/sdk.expected/release_ci_image_failure.json
+++ b/recipes/sdk.expected/release_ci_image_failure.json
@@ -1876,6 +1876,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1884,21 +1888,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
diff --git a/recipes/sdk.expected/release_ci_new_upload.json b/recipes/sdk.expected/release_ci_new_upload.json
index 3d3b68b..4914085 100644
--- a/recipes/sdk.expected/release_ci_new_upload.json
+++ b/recipes/sdk.expected/release_ci_new_upload.json
@@ -1876,6 +1876,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1884,21 +1888,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
@@ -2471,14 +2481,41 @@
   },
   {
     "cmd": [],
-    "name": "cipd"
+    "name": "publish gn sdk"
+  },
+  {
+    "cmd": [
+      "vpython",
+      "-vpython-spec",
+      "RECIPE_MODULE[fuchsia::gsutil]/resources/gsutil.vpython",
+      "-u",
+      "[START_DIR]/cipd/gsutil/gsutil",
+      "-o",
+      "GSUtil:software_update_check_period=0",
+      "cp",
+      "[CLEANUP]/gn.tar.gz",
+      "gs://fuchsia/development/8945511751514863184/sdk/linux-amd64/gn.tar.gz"
+    ],
+    "infra_step": true,
+    "name": "publish gn sdk.upload new gn fuchsia-sdk 8945511751514863184",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LINK@gsutil.upload@https://storage.googleapis.com/fuchsia/development/8945511751514863184/sdk/linux-amd64/gn.tar.gz@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "publish gn sdk.cipd",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
   },
   {
     "cmd": [
       "cipd",
       "pkg-build",
       "-pkg-def",
-      "{\"data\": [{\"dir\": \".\", \"exclude\": []}, {\"version_file\": \".versions/gn.cipd_version\"}], \"install_mode\": \"copy\", \"package\": \"fuchsia/sdk/gn/${platform}\", \"root\": \"[CLEANUP]/sdk-gn\"}",
+      "{\"data\": [{\"dir\": \".\", \"exclude\": []}, {\"version_file\": \".versions/gn.cipd_version\"}], \"install_mode\": \"copy\", \"package\": \"fuchsia/sdk/gn/${platform}\", \"root\": \"[CLEANUP]/sdk-bazel\"}",
       "-out",
       "[CLEANUP]/gn.cipd",
       "-hash-algo",
@@ -2486,9 +2523,9 @@
       "-json-output",
       "/path/to/tmp/json"
     ],
-    "name": "cipd.build fuchsia/sdk/gn/${platform}",
+    "name": "publish gn sdk.cipd.build fuchsia/sdk/gn/${platform}",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_NEST_LEVEL@2@@@",
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
       "@@@STEP_LOG_LINE@json.output@    \"instance_id\": \"40-chars-fake-of-the-package-instance_id\", @@@",
@@ -2508,9 +2545,9 @@
       "-json-output",
       "/path/to/tmp/json"
     ],
-    "name": "cipd.cipd search fuchsia/sdk/gn/${platform} git_revision:c22471f4e3f842ae18dd9adec82ed9eb78ed1127",
+    "name": "publish gn sdk.cipd.cipd search fuchsia/sdk/gn/${platform} git_revision:c22471f4e3f842ae18dd9adec82ed9eb78ed1127",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_NEST_LEVEL@2@@@",
       "@@@STEP_LOG_LINE@json.output@{@@@",
       "@@@STEP_LOG_LINE@json.output@  \"result\": [@@@",
       "@@@STEP_LOG_LINE@json.output@    {@@@",
@@ -2524,9 +2561,9 @@
   },
   {
     "cmd": [],
-    "name": "cipd.Package is up-to-date",
+    "name": "publish gn sdk.cipd.Package is up-to-date",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@1@@@"
+      "@@@STEP_NEST_LEVEL@2@@@"
     ]
   },
   {
diff --git a/recipes/sdk.expected/snapshot_ci.json b/recipes/sdk.expected/snapshot_ci.json
index 89afe52..960766a 100644
--- a/recipes/sdk.expected/snapshot_ci.json
+++ b/recipes/sdk.expected/snapshot_ci.json
@@ -1802,6 +1802,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1810,21 +1814,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
diff --git a/recipes/sdk.expected/snapshot_cq.json b/recipes/sdk.expected/snapshot_cq.json
index f751862..7bc6888 100644
--- a/recipes/sdk.expected/snapshot_cq.json
+++ b/recipes/sdk.expected/snapshot_cq.json
@@ -1928,6 +1928,10 @@
     ]
   },
   {
+    "cmd": [],
+    "name": "generate gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
@@ -1936,21 +1940,27 @@
       "[CLEANUP]/merged_sdk_archive.tar.gz",
       "--output",
       "[CLEANUP]/sdk-gn",
+      "--output-archive",
+      "[CLEANUP]/gn.tar.gz",
       "--tests",
       "[CLEANUP]/tests"
     ],
-    "name": "test sdk.create gn sdk",
+    "name": "generate gn sdk.create gn sdk",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
   },
   {
+    "cmd": [],
+    "name": "test gn sdk"
+  },
+  {
     "cmd": [
       "python",
       "-u",
       "[CLEANUP]/tests/run.py"
     ],
-    "name": "test sdk.run gn tests",
+    "name": "test gn sdk.run gn tests",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@"
     ]
diff --git a/recipes/sdk.py b/recipes/sdk.py
index 735d224..42f4adc 100644
--- a/recipes/sdk.py
+++ b/recipes/sdk.py
@@ -336,12 +336,13 @@
               bazel_path,
           ],
       )
-
-  # Generate a GN workspace along with its tests.
-  # These tests are being run for every SDK flavor.
+  with api.step.nest('generate gn sdk'):
+    # Generate a GN workspace along with its tests.
+    # These tests are being run for every SDK flavor.
     generate_gn_path = checkout.root_dir.join('scripts', 'sdk', 'gn',
                                               'generate.py')
     gn_sdk_dir = api.path['cleanup'].join('sdk-gn')
+    gn_sdk_archive = api.path['cleanup'].join('gn.tar.gz')
     test_workspace_dir = api.path['cleanup'].join('tests')
 
     api.python(
@@ -352,10 +353,13 @@
             full_archive_path,
             '--output',
             gn_sdk_dir,
+            '--output-archive',
+            gn_sdk_archive,
             '--tests',
             test_workspace_dir,
         ],
     )
+  with api.step.nest('test gn sdk'):
     api.python('run gn tests', test_workspace_dir.join('run.py'))
 
   if image_builds:
@@ -371,9 +375,11 @@
     )
 
   # Publish the core and GN SDK.
+  #
   # GCS publishing paths:
   # gs://fuchsia/development/${sdk_id}/sdk/${platform}
   # |-- core.tar.gz
+  # `-- gn-sdk.tar.gz
   #
   # CIPD publishing paths (versioning is built into CIPD):
   # https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/
@@ -409,13 +415,25 @@
       checkout_root=checkout.root_dir)
 
   # Publish GN SDK
-  # Upload GN SDK CIPD
-  api.upload.cipd_package(
-      '%s/sdk/gn/${platform}' % cipd_root,
-      gn_sdk_dir, [api.upload.DirectoryPath(gn_sdk_dir)],
-      {'git_revision': revision},
-      repository=None,
-      extra_tags={'jiri_snapshot': sdk_id})
+  with api.step.nest('publish gn sdk'):
+    # Upload SDK dir to CIPD and tarball to GCS
+    gcs_path = 'development/%s/sdk/%s-amd64/gn.tar.gz' % (sdk_id,
+                                                          api.platform.name)
+    api.gsutil.upload(
+        bucket=gcs_bucket,
+        src=gn_sdk_archive,
+        dst=gcs_path,
+        name='upload new gn fuchsia-sdk %s' % sdk_id,
+        # Publicly available.
+        unauthenticated_url=True)
+
+    # Upload GN SDK CIPD
+    api.upload.cipd_package(
+        '%s/sdk/gn/${platform}' % cipd_root,
+        sdk_dir, [api.upload.DirectoryPath(sdk_dir)],
+        {'git_revision': revision},
+        repository=None,
+        extra_tags={'jiri_snapshot': sdk_id})
 
 
 def upload_core(api, sdk_name, gcs_archive_bucket, gcs_archive_path,