ci: fix error in workflow generation task

An error in the workflow generation task meant that the test workflow
was generated into each of the four workflow configurations: test,
test_dispatch, release and rebuild_tip_cuelang_org.

Fix the generation task to restore the workflow definitions to their
previous state (modulo the source of truth now being CUE).

Change-Id: I8245bedb015cef65251d7cadb8d576b510fca03c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6102
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/.github/workflows/rebuild_tip_cuelang_org.yml b/.github/workflows/rebuild_tip_cuelang_org.yml
index a8d5047..db5c112 100644
--- a/.github/workflows/rebuild_tip_cuelang_org.yml
+++ b/.github/workflows/rebuild_tip_cuelang_org.yml
@@ -1,59 +1,14 @@
 # Generated by internal/ci/ci_tool.cue; do not edit
 
-name: Test
-defaults:
-  run:
-    shell: bash
+name: Push to tip
 on:
   push:
     branches:
-    - '*'
-    tags-ignore:
-    - v*
+    - master
 jobs:
-  test:
-    runs-on: ${{ matrix.os }}
+  push:
+    runs-on: ubuntu-latest
     steps:
-    - name: Install Go
-      uses: actions/setup-go@v2
-      with:
-        go-version: ${{ matrix.go-version }}
-    - name: Checkout code
-      uses: actions/checkout@v2
-    - name: Cache Go modules
-      uses: actions/cache@v1
-      with:
-        path: ~/go/pkg/mod
-        key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum')
-          }}
-        restore-keys: ${{ runner.os }}-${{ matrix.go-version }}-go-
-    - name: Generate
-      if: matrix.go-version == '1.14.3' && matrix.os != 'windows-latest'
-      run: |-
-        go generate ./...
-        go generate ./.github/workflows
-    - name: Test
-      run: go test ./...
-    - name: Test with -race
-      run: go test -race ./...
-    - name: gorelease check
-      run: go run golang.org/x/exp/cmd/gorelease
-    - name: Check that git is clean post generate and tests
-      run: test -z "$(git status --porcelain)" || (git status; git diff; false)
-    - name: Pull this commit through the proxy on master
-      if: github.ref == 'refs/heads/master'
-      run: |-
-        v=$(git rev-parse HEAD)
-        cd $(mktemp -d)
-        go mod init mod.com
-        GOPROXY=https://proxy.golang.org go get -d cuelang.org/go@$v
-    strategy:
-      matrix:
-        go-version:
-        - 1.13.x
-        - 1.14.3
-        os:
-        - ubuntu-latest
-        - macos-latest
-        - windows-latest
-      fail-fast: false
+    - name: Rebuild tip.cuelang.org
+      run: curl -X POST -d {} https://api.netlify.com/build_hooks/${{ secrets.CuelangOrgTipRebuildHook
+        }}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index a8d5047..c169636 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1,59 +1,50 @@
 # Generated by internal/ci/ci_tool.cue; do not edit
 
-name: Test
-defaults:
-  run:
-    shell: bash
+name: Release
 on:
   push:
-    branches:
-    - '*'
-    tags-ignore:
+    tags:
     - v*
 jobs:
-  test:
-    runs-on: ${{ matrix.os }}
+  goreleaser:
+    runs-on: ubuntu-latest
     steps:
-    - name: Install Go
-      uses: actions/setup-go@v2
-      with:
-        go-version: ${{ matrix.go-version }}
     - name: Checkout code
       uses: actions/checkout@v2
-    - name: Cache Go modules
-      uses: actions/cache@v1
+    - name: Unshallow
+      run: git fetch --prune --unshallow
+    - name: Run GoReleaser
+      env:
+        GITHUB_TOKEN: ${{ secrets.ACTIONS_GITHUB_TOKEN }}
+      uses: docker://goreleaser/goreleaser:latest
       with:
-        path: ~/go/pkg/mod
-        key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum')
+        args: release --rm-dist
+  docker:
+    name: docker
+    runs-on: ubuntu-latest
+    steps:
+    - name: Check out the repo
+      uses: actions/checkout@v2
+    - name: Set version environment
+      run: |-
+        CUE_VERSION=$(echo ${GITHUB_REF##refs/tags/v})
+        echo "CUE_VERSION=$CUE_VERSION"
+        echo "::set-env name=CUE_VERSION::$(echo $CUE_VERSION)"
+    - name: Push to Docker Hub
+      env:
+        DOCKER_BUILDKIT: 1
+        GOLANG_VERSION: 1.14
+        CUE_VERSION: ${{ env.CUE_VERSION }}
+      uses: docker/build-push-action@v1
+      with:
+        tags: ${{ env.CUE_VERSION }},latest
+        repository: cuelang/cue
+        username: ${{ secrets.DOCKER_USERNAME }}
+        password: ${{ secrets.DOCKER_PASSWORD }}
+        tag_with_ref: false
+        tag_with_sha: false
+        target: cue
+        always_pull: true
+        build_args: GOLANG_VERSION=${{ env.GOLANG_VERSION }},CUE_VERSION=v${{ env.CUE_VERSION
           }}
-        restore-keys: ${{ runner.os }}-${{ matrix.go-version }}-go-
-    - name: Generate
-      if: matrix.go-version == '1.14.3' && matrix.os != 'windows-latest'
-      run: |-
-        go generate ./...
-        go generate ./.github/workflows
-    - name: Test
-      run: go test ./...
-    - name: Test with -race
-      run: go test -race ./...
-    - name: gorelease check
-      run: go run golang.org/x/exp/cmd/gorelease
-    - name: Check that git is clean post generate and tests
-      run: test -z "$(git status --porcelain)" || (git status; git diff; false)
-    - name: Pull this commit through the proxy on master
-      if: github.ref == 'refs/heads/master'
-      run: |-
-        v=$(git rev-parse HEAD)
-        cd $(mktemp -d)
-        go mod init mod.com
-        GOPROXY=https://proxy.golang.org go get -d cuelang.org/go@$v
-    strategy:
-      matrix:
-        go-version:
-        - 1.13.x
-        - 1.14.3
-        os:
-        - ubuntu-latest
-        - macos-latest
-        - windows-latest
-      fail-fast: false
+        add_git_labels: true
diff --git a/.github/workflows/test_dispatch.yml b/.github/workflows/test_dispatch.yml
index a8d5047..ed30610 100644
--- a/.github/workflows/test_dispatch.yml
+++ b/.github/workflows/test_dispatch.yml
@@ -1,25 +1,30 @@
 # Generated by internal/ci/ci_tool.cue; do not edit
 
 name: Test
+env:
+  GERRIT_COOKIE: ${{ secrets.gerritCookie }}
 defaults:
   run:
     shell: bash
 on:
-  push:
-    branches:
-    - '*'
-    tags-ignore:
-    - v*
+- repository_dispatch
 jobs:
   test:
+    needs: start
     runs-on: ${{ matrix.os }}
     steps:
+    - name: Write the gitcookies file
+      run: echo "$GERRIT_COOKIE" > ~/.gitcookies
     - name: Install Go
       uses: actions/setup-go@v2
       with:
         go-version: ${{ matrix.go-version }}
     - name: Checkout code
       uses: actions/checkout@v2
+    - name: Checkout ref
+      run: |-
+        git fetch https://cue-review.googlesource.com/cue ${{ github.event.client_payload.ref }}
+        git checkout FETCH_HEAD
     - name: Cache Go modules
       uses: actions/cache@v1
       with:
@@ -40,13 +45,14 @@
       run: go run golang.org/x/exp/cmd/gorelease
     - name: Check that git is clean post generate and tests
       run: test -z "$(git status --porcelain)" || (git status; git diff; false)
-    - name: Pull this commit through the proxy on master
-      if: github.ref == 'refs/heads/master'
-      run: |-
-        v=$(git rev-parse HEAD)
-        cd $(mktemp -d)
-        go mod init mod.com
-        GOPROXY=https://proxy.golang.org go get -d cuelang.org/go@$v
+    - name: Post any failures for this matrix entry
+      if: ${{ failure() }}
+      run: 'curl -s -H "Content-Type: application/json" --request POST --data ''{"labels":
+        { "Code-Review": -1 }, "message":"Build failed for ${{ runner.os }}-${{ matrix.go-version
+        }}; see ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id
+        }} for more details"}'' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{
+        github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit
+        }}/review'
     strategy:
       matrix:
         go-version:
@@ -57,3 +63,26 @@
         - macos-latest
         - windows-latest
       fail-fast: false
+  start:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Write the gitcookies file
+      run: echo "$GERRIT_COOKIE" > ~/.gitcookies
+    - name: Update Gerrit CL message with starting message
+      run: 'curl -s -H "Content-Type: application/json" --request POST --data ''{"message":"Started
+        the build... see progress at ${{ github.event.repository.html_url }}/actions/runs/${{
+        github.run_id }}"}'' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{
+        github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit
+        }}/review'
+  end:
+    needs: test
+    runs-on: ubuntu-latest
+    steps:
+    - name: Write the gitcookies file
+      run: echo "$GERRIT_COOKIE" > ~/.gitcookies
+    - name: Update Gerrit CL message with success message
+      run: 'curl -s -H "Content-Type: application/json" --request POST --data ''{"labels":
+        { "Code-Review": 1 }, "message":"Build succeeded for ${{ github.event.repository.html_url
+        }}/actions/runs/${{ github.run_id }}"}'' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{
+        github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit
+        }}/review'
diff --git a/internal/ci/ci_tool.cue b/internal/ci/ci_tool.cue
index 47e930d..90e1143 100644
--- a/internal/ci/ci_tool.cue
+++ b/internal/ci/ci_tool.cue
@@ -14,7 +14,7 @@
 			contents: """
 				# Generated by internal/ci/ci_tool.cue; do not edit
 
-				\(yaml.Marshal(test))
+				\(yaml.Marshal(w.schema))
 				"""
 		}
 	}