Add script to help with CIPD updates

This script generates the cipd.yaml file and shows instructions on how
to update CIPD

Change-Id: I88ab530047ac53c548974d32a3e9e9042ef9e1bb
Reviewed-on: https://fuchsia-review.googlesource.com/c/fargo/+/560521
Reviewed-by: Rob Tsuk <robtsuk@google.com>
diff --git a/.gitignore b/.gitignore
index 5e66a2d..02f99b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 target/
 **/*.rs.bk
 .DS_Store
+cipd.yaml
diff --git a/README.md b/README.md
index c81e14e..4472761 100644
--- a/README.md
+++ b/README.md
@@ -75,9 +75,9 @@
 
 From the directory you cloned into.
 
-    cargo build --release
+    ./scripts/build_cipd_prebuilt.sh
 
-The resulting `fargo` binary will be in the target/release directory.
+This will generate a `cipd.yaml` file for uploading to CIPD.
 
 ### Testing if Fargo is working
 
diff --git a/scripts/build_cipd_prebuilt.sh b/scripts/build_cipd_prebuilt.sh
new file mode 100755
index 0000000..4121daa
--- /dev/null
+++ b/scripts/build_cipd_prebuilt.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+# Copyright 2021 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set -euo pipefail
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
+
+# Build the binary
+cd "$SCRIPT_DIR/.." && cargo build --release
+
+# Determine the os+arch
+case "$(uname -s)" in
+    Linux*)     OS=linux;;
+    Darwin*)    OS=mac;;
+    *)          echo "Unsupported OS"; exit 1
+esac
+case "$(uname -m)" in
+    x86_64*)    ARCH=amd64;;
+    *)          echo "Unsupported Arch"; exit 1
+esac
+
+# Get the git revision
+GIT_REV="$(git describe --dirty --always --match="" --abbrev=0)"
+
+# Generate a cipd.yaml
+cat <<EOF > "$SCRIPT_DIR/../cipd.yaml"
+# To upload the files in this CIPD package do:
+#
+#   cipd create -pkg-def cipd.yaml -tag git_revision:$GIT_REV
+#
+# Optionally mark it as "latest"
+#
+#   cipd set-ref fuchsia/third_party/fargo/$OS-$ARCH -ref latest -version [insert version from previous command's output]
+#
+package: fuchsia/third_party/fargo/$OS-$ARCH
+root: target/release
+data:
+  - file: fargo
+EOF
+
+cat "$SCRIPT_DIR/../cipd.yaml" | grep "#"