[current_results] Add script to generate protos

Change-Id: Id4f2457ca751c6e0c76eefa0b38ce0f877d9feb3
Reviewed-on: https://dart-review.googlesource.com/c/dart_ci/+/197063
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: Karl Klose <karlklose@google.com>
diff --git a/current_results/README.md b/current_results/README.md
index c6ee709..3411e6e 100644
--- a/current_results/README.md
+++ b/current_results/README.md
@@ -15,23 +15,17 @@
 new version.
 
 ### Generating protogen classes
-To generate the Dart code reading the records from results.json,
-and the gRPC server and client code from query.proto,
-run protogen on the .proto files declaring them:
-```
-protoc --dart_out=lib/src/generated -I../common ../common/result.proto
-protoc --dart_out=grpc:lib/src/generated -Ilib/protos -Ithird_party/proto lib/protos/query.proto
-dart format lib/src/generated/query* lib/src/generated/result*
-```
 
-Our gRPC api protocol uses the gRPC api of Pub/Sub from google/pubsub/v1, so we
-need to check out the googleapis protocol buffer definitions and generate them.
-They are not checked into the repository, and must be generated.
-```
-protoc --dart_out=lib/src/generated -I[protobuf checkout]/src [protobuf checkout]/src/google/protobuf/*.proto
-protoc --dart_out=grpc:lib/src/generated -I[googleapis checkout] [googleapis checkout]/google/pubsub/v1/pubsub.proto
-```
+Pre-requisites:
+- Install the protoc compiler: https://developers.google.com/protocol-buffers/docs/downloads
+- Install https://pub.dev/packages/protoc_plugin/install
+- A copy of https://github.com/googleapis/googleapis
+- A copy of https://github.com/protocolbuffers/protobuf
 
+To generate the required Dart files for the protos, run
+`tools/generate_protogen.sh` with the environtment variables
+`GOOGLEAPIS_PATH` and `PROTOBUF_PATH` set to the location of the checkouts
+mentioned above.
 
 ### Staging
 To build the server and deploy to cloud run on staging, run
diff --git a/current_results/tools/generate_protogen.sh b/current_results/tools/generate_protogen.sh
new file mode 100755
index 0000000..e6cd8d7
--- /dev/null
+++ b/current_results/tools/generate_protogen.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+# Copyright (c) 2021, the Dart project authors.  Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+# Generate the required Dart files for protobufs
+
+set -e
+
+if [ -z "$GOOGLEAPIS_PATH" ]
+then
+  echo Set the variable \'GOOGLEAPIS_PATH\' to a checkout of \
+    \'https://github.com/googleapis/googleapis/\'!
+  exit 1
+fi
+
+if [ -z "$PROTOBUF_PATH" ]
+then
+  echo Set the variable \'PROTOBUF_PATH\' to a checkout of \
+    \'https://github.com/protocolbuffers/protobuf.git\'!
+  exit 1
+fi
+
+protoc --dart_out=lib/src/generated -I$PROTOBUF_PATH/src $PROTOBUF_PATH/src/google/protobuf/*.proto
+protoc --dart_out=grpc:lib/src/generated -I$GOOGLEAPIS_PATH $GOOGLEAPIS_PATH/google/pubsub/v1/pubsub.proto
+protoc --dart_out=grpc:lib/src/generated -I$GOOGLEAPIS_PATH $GOOGLEAPIS_PATH/google/pubsub/v1/schema.proto
+
+protoc --dart_out=lib/src/generated ../common/result.proto -I../common
+protoc --dart_out=grpc:lib/src/generated -Ilib/protos -Ithird_party/proto lib/protos/query.proto
+dartfmt -w lib/src/generated/query* lib/src/generated/result*