deploy: use gcloud to manage triggers, trigger from GCR

The GCP UI is nicer for editing triggers, and the gcloud command now has
beta support for import/export. It wants YAML format, though. Delete the
json versions and replace them with freshly pulled versions, including
the change to trigger from GCR.

Change-Id: I3a20951d94b9a9522f28b07cc772d097679fb5a2
Reviewed-on: https://go-review.googlesource.com/c/playground/+/327349
Trust: Heschi Kreinick <heschi@google.com>
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
diff --git a/Makefile b/Makefile
index de22119..4dedfd6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,3 @@
-CLOUDBUILD_PLAYGROUND_TRIGGER_JSON := deploy/playground_trigger.json
-CLOUDBUILD_PLAYGROUND_TRIGGER_ID := $(shell jq -r .id ${CLOUDBUILD_PLAYGROUND_TRIGGER_JSON})
-CLOUDBUILD_GO_TRIGGER_JSON := deploy/go_trigger.json
-CLOUDBUILD_GO_TRIGGER_ID := $(shell jq -r .id ${CLOUDBUILD_GO_TRIGGER_JSON})
-GCLOUD_ACCESS_TOKEN := $(shell gcloud auth print-access-token)
 LATEST_GO := $(shell go run ./cmd/latestgo)
 
 .PHONY: docker test update-cloudbuild-trigger
@@ -28,11 +23,10 @@
 # directory)
 test: test_go
 
-update-cloudbuild-trigger:
-	# The gcloud CLI doesn't yet support updating a trigger.
-	curl -H "Authorization: Bearer $(GCLOUD_ACCESS_TOKEN)" -H "Content-Type: application/json" \
-		-d @$(CLOUDBUILD_GO_TRIGGER_JSON) \
-		-X PATCH https://cloudbuild.googleapis.com/v1/projects/golang-org/triggers/$(CLOUDBUILD_GO_TRIGGER_ID)
-	curl -H "Authorization: Bearer $(GCLOUD_ACCESS_TOKEN)" -H "Content-Type: application/json" \
-		-d @$(CLOUDBUILD_PLAYGROUND_TRIGGER_JSON) \
-		-X PATCH https://cloudbuild.googleapis.com/v1/projects/golang-org/triggers/$(CLOUDBUILD_PLAYGROUND_TRIGGER_ID)
+push-cloudbuild-triggers:
+	gcloud beta builds triggers import --project golang-org --source deploy/go_trigger.yaml
+	gcloud beta builds triggers import --project golang-org --source deploy/playground_trigger.yaml
+
+pull-cloudbuild-triggers:
+	gcloud beta builds triggers export --project golang-org playground-redeploy-go-release --destination deploy/go_trigger.yaml
+	gcloud beta builds triggers export --project golang-org playground-redeploy-playground --destination deploy/playground_trigger.yaml
diff --git a/README.md b/README.md
index 8a73ff4..5001f98 100644
--- a/README.md
+++ b/README.md
@@ -27,15 +27,12 @@
 Playground releases automatically triggered when new Go repository tags are pushed to GitHub, or when master is pushed
 on the playground repository.
 
-For details, see [deploy/go_trigger.json](deploy/go_trigger.json),
-[deploy/playground_trigger.json](deploy/playground_trigger.json),
+For details, see [deploy/go_trigger.yaml](deploy/go_trigger.yaml),
+[deploy/playground_trigger.yaml](deploy/playground_trigger.yaml),
 and [deploy/deploy.json](deploy/deploy.json).
 
-After making changes to trigger configuration, update configuration by running the following Make target:
-
-```bash
-make update-cloudbuild-trigger
-```
+Changes to the trigger configuration can be made to the YAML files, or in the GCP UI, which should be kept in sync
+using the `push-cloudbuild-trigger` and `pull-cloudbuild-trigger` make targets.
 
 ### Deploy via Cloud Build
 
diff --git a/deploy/go_trigger.json b/deploy/go_trigger.json
deleted file mode 100644
index b7e7ff5..0000000
--- a/deploy/go_trigger.json
+++ /dev/null
@@ -1,36 +0,0 @@
-{
-  "id": "5a2c9e25-a71a-4adf-a785-76c3eca2ac8a",
-  "description": "Go repository release trigger for x/playground",
-  "github": {
-    "name": "go",
-    "owner": "golang",
-    "push": {
-      "tag": "^go[0-9](\\.[0-9]+)+$"
-    }
-  },
-  "build": {
-    "steps": [
-      {
-        "name": "gcr.io/cloud-builders/git",
-        "args": [
-          "clone",
-          "--depth",
-          "1",
-          "https://go.googlesource.com/playground"
-        ]
-      },
-      {
-        "dir": "playground",
-        "name": "gcr.io/cloud-builders/gcloud",
-        "args": [
-          "builds",
-          "submit",
-          "--async",
-          "--config",
-          "deploy/deploy.json",
-          "."
-        ]
-      }
-    ]
-  }
-}
diff --git a/deploy/go_trigger.yaml b/deploy/go_trigger.yaml
new file mode 100644
index 0000000..4880069
--- /dev/null
+++ b/deploy/go_trigger.yaml
@@ -0,0 +1,25 @@
+build:
+  steps:
+  - args:
+    - clone
+    - --depth
+    - '1'
+    - https://go.googlesource.com/playground
+    name: gcr.io/cloud-builders/git
+  - args:
+    - builds
+    - submit
+    - --async
+    - --config
+    - deploy/deploy.json
+    - .
+    dir: playground
+    name: gcr.io/cloud-builders/gcloud
+createTime: '2019-06-18T17:59:14.019265678Z'
+description: Redeploy playground on new tagged Go release
+id: 5a2c9e25-a71a-4adf-a785-76c3eca2ac8a
+name: playground-redeploy-go-release
+triggerTemplate:
+  projectId: golang-org
+  repoName: go
+  tagName: ^go[0-9](\.[0-9]+)+$
diff --git a/deploy/playground_trigger.json b/deploy/playground_trigger.json
deleted file mode 100644
index 3685fe5..0000000
--- a/deploy/playground_trigger.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-  "id": "cb46eb75-8665-4365-8e93-b8f7bfbd4807",
-  "description": "Playground repository release trigger for x/playground",
-  "github": {
-    "name": "playground",
-    "owner": "golang",
-    "push": {
-      "branch": "^master$"
-    }
-  },
-  "filename": "deploy/deploy.json"
-}
diff --git a/deploy/playground_trigger.yaml b/deploy/playground_trigger.yaml
new file mode 100644
index 0000000..bfb7585
--- /dev/null
+++ b/deploy/playground_trigger.yaml
@@ -0,0 +1,9 @@
+createTime: '2019-07-09T19:50:40.493493139Z'
+description: Redeploy playground on x/playground commit
+filename: deploy/deploy.json
+id: cb46eb75-8665-4365-8e93-b8f7bfbd4807
+name: playground-redeploy-playground
+triggerTemplate:
+  branchName: ^master$
+  projectId: golang-org
+  repoName: playground