Add results processing to release_builder.

This will be reporting the build results using buildbucket messages.

Bug: https://github.com/flutter/flutter/issues/115730
Change-Id: I2335650e89112471ddfc5c090a6e8362a0ceb6dc
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/36646
Reviewed-by: Yusuf Mohsinally <mohsinally@google.com>
Commit-Queue: Godofredo Contreras <godofredoc@google.com>
diff --git a/recipes/engine/release_builder.expected/basic_linux.json b/recipes/engine/release_builder.expected/basic_linux.json
index fdc3ab4..bbb605a 100644
--- a/recipes/engine/release_builder.expected/basic_linux.json
+++ b/recipes/engine/release_builder.expected/basic_linux.json
@@ -516,6 +516,158 @@
   },
   {
     "cmd": [],
+    "name": "Publish results"
+  },
+  {
+    "cmd": [],
+    "name": "Publish results.ensure gcloud",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "copy",
+      "RECIPE_MODULE[fuchsia::gcloud]/resources/tool_manifest.json",
+      "/path/to/tmp/json"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "proj:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Publish results.ensure gcloud.read manifest",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_LINE@tool_manifest.json@{@@@",
+      "@@@STEP_LOG_LINE@tool_manifest.json@  \"path\": \"path/to/gcloud\",@@@",
+      "@@@STEP_LOG_LINE@tool_manifest.json@  \"version\": \"version:pinned-version\"@@@",
+      "@@@STEP_LOG_LINE@tool_manifest.json@}@@@",
+      "@@@STEP_LOG_END@tool_manifest.json@@@"
+    ]
+  },
+  {
+    "cmd": [],
+    "name": "Publish results.ensure gcloud.install path/to/gcloud",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "ensure-directory",
+      "--mode",
+      "0777",
+      "[START_DIR]/cipd_tool/path/to/gcloud/version%3Apinned-version"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "proj:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Publish results.ensure gcloud.install path/to/gcloud.ensure package directory",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@3@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "cipd",
+      "ensure",
+      "-root",
+      "[START_DIR]/cipd_tool/path/to/gcloud/version%3Apinned-version",
+      "-ensure-file",
+      "path/to/gcloud version:pinned-version",
+      "-max-threads",
+      "0",
+      "-json-output",
+      "/path/to/tmp/json"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "proj:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Publish results.ensure gcloud.install path/to/gcloud.ensure_installed",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@3@@@",
+      "@@@STEP_LOG_LINE@json.output@{@@@",
+      "@@@STEP_LOG_LINE@json.output@  \"result\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@    \"\": [@@@",
+      "@@@STEP_LOG_LINE@json.output@      {@@@",
+      "@@@STEP_LOG_LINE@json.output@        \"instance_id\": \"resolved-instance_id-of-version:pinned-v\", @@@",
+      "@@@STEP_LOG_LINE@json.output@        \"package\": \"path/to/gcloud\"@@@",
+      "@@@STEP_LOG_LINE@json.output@      }@@@",
+      "@@@STEP_LOG_LINE@json.output@    ]@@@",
+      "@@@STEP_LOG_LINE@json.output@  }@@@",
+      "@@@STEP_LOG_LINE@json.output@}@@@",
+      "@@@STEP_LOG_END@json.output@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "[START_DIR]/cipd_tool/path/to/gcloud/version%3Apinned-version/lib/gcloud.py",
+      "pubsub",
+      "topics",
+      "publish",
+      "projects/flutter-dashboard/topics/luci-builds-prod",
+      "--message='{\n  \"id\": \"8945511751514863186\",\n  \"builder\": {\n    \"project\": \"fuchsia\",\n    \"bucket\": \"try\",\n    \"builder\": \"builder-subbuild1\"\n  },\n  \"createdBy\": \"project:fuchsia\",\n  \"createTime\": \"2018-05-25T23:50:17Z\",\n  \"status\": \"SUCCESS\",\n  \"input\": {\n    \"gerritChanges\": [\n      {\n        \"host\": \"chromium-review.googlesource.com\",\n        \"project\": \"fuchsia\",\n        \"change\": \"123456\",\n        \"patchset\": \"7\"\n      }\n    ]\n  },\n  \"output\": {\n    \"properties\": {\n      \"test_orchestration_inputs_hash\": \"abc\"\n    }\n  },\n  \"infra\": {\n    \"swarming\": {\n      \"taskId\": \"abc123\",\n      \"priority\": 30\n    },\n    \"resultdb\": {\n      \"invocation\": \"invocations/build:8945511751514863186\"\n    }\n  },\n  \"tags\": [\n    {\n      \"key\": \"cq_experimental\",\n      \"value\": \"false\"\n    }\n  ]\n}'"
+    ],
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "proj:try"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Publish results.gcloud pubsub",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [],
     "name": "display builds"
   },
   {
diff --git a/recipes/engine/release_builder.py b/recipes/engine/release_builder.py
index ec8866b..26410b7 100644
--- a/recipes/engine/release_builder.py
+++ b/recipes/engine/release_builder.py
@@ -21,6 +21,7 @@
   'flutter/display_util',
   'flutter/repo_util',
   'flutter/shard_util_v2',
+  'flutter/status_reporting',
   'recipe_engine/buildbucket',
   'recipe_engine/json',
   'recipe_engine/path',
@@ -64,6 +65,7 @@
   with api.step.nest('collect builds') as presentation:
     build_results = api.shard_util_v2.collect(tasks, presentation)
 
+  api.status_reporting.publish_builds(build_results)
   api.display_util.display_subbuilds(
     step_name='display builds',
     subbuilds=build_results,