ci: only go test -race on latest Go+linux, and master

Builds of CLs take some time because every entry in the build matrix
runs a go test -race step. Whilst nice, this is probably overkill.

Instead:

* on master commit, run go test -race on all entries in the build
  matrix. No change here.
* for CL builds, only run go test -race for the entry in the build
  matrix that corresponds to the latest stable Go version running on
  Linux.

Change-Id: I83fa2e41a9059a06436c250bfee99a430425dc6c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8361
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 8a52c04..8c72bc8 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -59,7 +59,9 @@
       run: go generate ./...
     - name: Test
       run: go test ./...
-    - name: Test with -race
+    - if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/ci/')
+        && matrix.go-version == '1.15.x' && matrix.os == 'ubuntu-18.04' }}
+      name: Test with -race
       run: go test -race ./...
     - name: gorelease check
       run: go run golang.org/x/exp/cmd/gorelease
diff --git a/internal/ci/workflows.cue b/internal/ci/workflows.cue
index baf70c1..78c9502 100644
--- a/internal/ci/workflows.cue
+++ b/internal/ci/workflows.cue
@@ -7,6 +7,9 @@
 
 workflowsDir: *"./" | string @tag(workflowsDir)
 
+_#masterBranch:      "master"
+_#releaseTagPattern: "v*"
+
 workflows: [...{file: string, schema: (json.#Workflow & {})}]
 workflows: [
 	{
@@ -33,7 +36,7 @@
 	on: {
 		push: {
 			branches: ["**"] // any branch (including '/' namespaced branches)
-			"tags-ignore": ["v*"]
+			"tags-ignore": [_#releaseTagPattern]
 		}
 	}
 
@@ -56,7 +59,9 @@
 				_#cacheGoModules,
 				_#goGenerate,
 				_#goTest,
-				_#goTestRace,
+				_#goTestRace & {
+					if: "${{ \(_#isMaster) || \(_#isCLCITestBranch) && matrix.go-version == '\(_#latestStableGo)' && matrix.os == '\(_#linuxMachine)' }}"
+				},
 				_#goReleaseCheck,
 				_#checkGitClean,
 				_#pullThroughProxy,
@@ -93,10 +98,10 @@
 
 	// _#isMaster is an expression that evaluates to true if the
 	// job is running as a result of a master commit push
-	_#isMaster: "github.ref == '\(_#branchRefPrefix)master'"
+	_#isMaster: "github.ref == '\(_#branchRefPrefix+_#masterBranch)'"
 
 	_#pullThroughProxy: _#step & {
-		name: "Pull this commit through the proxy on master"
+		name: "Pull this commit through the proxy on \(_#masterBranch)"
 		run: """
 			v=$(git rev-parse HEAD)
 			cd $(mktemp -d)
@@ -181,7 +186,7 @@
 release: _#bashWorkflow & {
 
 	name: "Release"
-	on: push: tags: ["v*"]
+	on: push: tags: [_#releaseTagPattern]
 	jobs: {
 		goreleaser: {
 			"runs-on": _#linuxMachine
@@ -239,7 +244,7 @@
 rebuild_tip_cuelang_org: _#bashWorkflow & {
 
 	name: "Push to tip"
-	on: push: branches: ["master"]
+	on: push: branches: [_#masterBranch]
 	jobs: push: {
 		"runs-on": _#linuxMachine
 		steps: [{
@@ -259,7 +264,8 @@
 _#step: ((_#job & {steps:                 _}).steps & [_])[0]
 
 // We need at least go1.14 for code generation
-_#codeGenGo: "1.14.9"
+_#codeGenGo:      "1.14.9"
+_#latestStableGo: "1.15.x"
 
 _#linuxMachine:   "ubuntu-18.04"
 _#macosMachine:   "macos-10.15"
@@ -269,7 +275,7 @@
 	"fail-fast": false
 	matrix: {
 		// Use a stable version of 1.14.x for go generate
-		"go-version": ["1.13.x", _#codeGenGo, "1.15.x"]
+		"go-version": ["1.13.x", _#codeGenGo, _#latestStableGo]
 		os: [_#linuxMachine, _#macosMachine, _#windowsMachine]
 	}
 }