[infra] Set GOCACHE in tasks that use go.

Bug: skia:8423
Change-Id: If079c958cb9d0d82fe13da44aaebd5913b40b9d1
Reviewed-on: https://skia-review.googlesource.com/c/179065
Auto-Submit: Ben Wagner <benjaminwagner@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
Commit-Queue: Eric Boren <borenet@google.com>
diff --git a/infra/bots/gen_tasks.go b/infra/bots/gen_tasks.go
index 5ec6e79..95d8589 100644
--- a/infra/bots/gen_tasks.go
+++ b/infra/bots/gen_tasks.go
@@ -126,6 +126,12 @@
 			Path: "cache/git_cache",
 		},
 	}
+	CACHES_GO = []*specs.Cache{
+		&specs.Cache{
+			Name: "go_cache",
+			Path: "cache/go_cache",
+		},
+	}
 	CACHES_WORKDIR = []*specs.Cache{
 		&specs.Cache{
 			Name: "work",
@@ -778,6 +784,15 @@
 	t.CipdPackages = append(t.CipdPackages, CIPD_PKGS_GIT...)
 }
 
+// usesGo adds attributes to tasks which use go. Recipes should use
+// "with api.context(env=api.infra.go_env)".
+// (Not needed for tasks that just want to run Go code from the infra repo -- instead use go_deps.)
+func usesGo(b *specs.TasksCfgBuilder, t *specs.TaskSpec) {
+	t.Caches = append(t.Caches, CACHES_GO...)
+	t.CipdPackages = append(t.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
+	t.Dependencies = append(t.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
+}
+
 // usesDocker adds attributes to tasks which use docker.
 func usesDocker(t *specs.TaskSpec, name string) {
 	// currently, just the WASM (using EMCC) builder uses Docker.
@@ -926,8 +941,7 @@
 	}
 	task := kitchenTask(name, "recreate_skps", "swarm_recipe.isolate", SERVICE_ACCOUNT_RECREATE_SKPS, dims, nil, OUTPUT_NONE)
 	task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
-	task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
-	task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
+	usesGo(b, task)
 	timeout(task, 4*time.Hour)
 	b.MustAddTask(name, task)
 	return name
@@ -940,8 +954,7 @@
 	dims := linuxGceDimensions(MACHINE_TYPE_LARGE)
 	task := kitchenTask(name, "update_go_deps", "swarm_recipe.isolate", SERVICE_ACCOUNT_UPDATE_GO_DEPS, dims, nil, OUTPUT_NONE)
 	task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
-	task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
-	task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
+	usesGo(b, task)
 	b.MustAddTask(name, task)
 	return name
 }
@@ -991,8 +1004,7 @@
 func infra(b *specs.TasksCfgBuilder, name string) string {
 	task := kitchenTask(name, "infra", "swarm_recipe.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(MACHINE_TYPE_SMALL), nil, OUTPUT_NONE)
 	usesGit(task, name)
-	task.CipdPackages = append(task.CipdPackages, b.MustGetCipdPackageFromAsset("go"))
-	task.Dependencies = append(task.Dependencies, isolateCIPDAsset(b, ISOLATE_GO_DEPS_NAME))
+	usesGo(b, task)
 	b.MustAddTask(name, task)
 	return name
 }