devtools: introduce revision tagging

- Add optional revision tagging to segment billing costs.

Change-Id: I74a7584e98700d3c8f003e65d11135eb52daff16
Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/744423
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ethan Lee <ethanalee@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Nicholas Husin <nsh@golang.org>
diff --git a/deploy/worker.yaml b/deploy/worker.yaml
index efe05f6..f050566 100644
--- a/deploy/worker.yaml
+++ b/deploy/worker.yaml
@@ -10,6 +10,7 @@
 substitutions:
   _ENV: ''
   _BQ_DATASET: ''
+  _TAG: ''
 
 steps:
   - id: Lock
@@ -99,7 +100,8 @@
         service=${_ENV}-ecosystem-worker
         for region in "us-central1" "us-east1"; do
           args="--project $PROJECT_ID --region $region"
-          gcloud beta run deploy $args $service --image $image --execution-environment=gen2
+          gcloud beta run deploy $args $service --image $image --execution-environment=gen2 \
+                          --labels=deploy_tag=${_TAG}
           # If there was a rollback, `gcloud run deploy` will create a revision but
           # not point traffic to it. The following command ensures that the new revision
           # will get traffic.
diff --git a/devtools/deploy.sh b/devtools/deploy.sh
index dd6f397..e7b15ba 100755
--- a/devtools/deploy.sh
+++ b/devtools/deploy.sh
@@ -11,7 +11,7 @@
 source devtools/lib.sh || { echo "Are you at repo root?"; exit 1; }
 
 usage() {
-  die "usage: $0 [-n] (dev | prod) BIGQUERY_DATASET"
+  die "usage: $0 [-n] (dev | prod) BIGQUERY_DATASET [TAG]"
 }
 
 # Report whether the current repo's workspace has no uncommitted files.
@@ -38,6 +38,9 @@
     usage
   fi
 
+  local tag=$3
+  local deploy_tag=${tag:-$commit}
+
   if which grants > /dev/null; then
     local allowed=false
     while read _ _ ok _; do
@@ -63,7 +66,7 @@
   $prefix gcloud builds submit \
     --project $project \
     --config deploy/worker.yaml \
-    --substitutions SHORT_SHA=${commit}${unclean},_ENV=$env,_BQ_DATASET=$dataset
+    --substitutions SHORT_SHA=${commit}${unclean},_ENV=$env,_BQ_DATASET=$dataset,_TAG=$deploy_tag
 }
 
 main "$@"