ci: fix start message of CI jobs for CL builds

The message "Started the build..." that is written as a review comment
to a CL when a CI build starts is currently broken. It links to the CI
job that creates the build branch, as opposed to the subsequent workflow
run that is the testing of build branch.

This change fixes that.

Change-Id: If1e0f956cbd0943f179f7889337f49f450f35839
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8292
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 7970706..8a52c04 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -8,6 +8,20 @@
     tags-ignore:
     - v*
 jobs:
+  start:
+    runs-on: ubuntu-18.04
+    defaults:
+      run:
+        shell: bash
+    if: ${{ startsWith(github.ref, 'refs/heads/ci/') }}
+    steps:
+    - name: Write the gitcookies file
+      run: echo "${{ secrets.gerritCookie }}" > ~/.gitcookies
+    - name: Update Gerrit CL message with starting message
+      run: 'curl -f -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/$(basename
+        $(dirname $GITHUB_REF))/revisions/$(basename $GITHUB_REF)/review'
   test:
     strategy:
       fail-fast: false
diff --git a/.github/workflows/test_dispatch.yml b/.github/workflows/test_dispatch.yml
index bd136bf..c723d1a 100644
--- a/.github/workflows/test_dispatch.yml
+++ b/.github/workflows/test_dispatch.yml
@@ -11,14 +11,6 @@
       run:
         shell: bash
     steps:
-    - name: Write the gitcookies file
-      run: echo "${{ secrets.gerritCookie }}" > ~/.gitcookies
-    - name: Update Gerrit CL message with starting message
-      run: 'curl -f -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'
     - name: Checkout ref
       run: |-
         mkdir tmpgit
diff --git a/internal/ci/workflows.cue b/internal/ci/workflows.cue
index a42e1d7..baf70c1 100644
--- a/internal/ci/workflows.cue
+++ b/internal/ci/workflows.cue
@@ -38,6 +38,14 @@
 	}
 
 	jobs: {
+		start: {
+			"runs-on": _#linuxMachine
+			if:        "${{ \(_#isCLCITestBranch) }}"
+			steps: [
+				_#writeCookiesFile,
+				_#startCLBuild,
+			]
+		}
 		test: {
 			strategy:  _#testStrategy
 			"runs-on": "${{ matrix.os }}"
@@ -98,6 +106,13 @@
 		if: "${{ \(_#isMaster) }}"
 	}
 
+	_#startCLBuild: _#step & {
+		name: "Update Gerrit CL message with starting message"
+		run:  (_#gerrit._#setCodeReview & {
+			#args: message: "Started the build... see progress at ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}"
+		}).res
+	}
+
 	_#failCLBuild: _#step & {
 		if:   "${{ \(_#isCLCITestBranch) && failure() }}"
 		name: "Post any failures for this matrix entry"
@@ -149,13 +164,6 @@
 			if:        "${{ startsWith(github.event.action, 'Build for refs/changes/') }}"
 			"runs-on": _#linuxMachine
 			steps: [
-				_#writeCookiesFile,
-				_#step & {
-					name: "Update Gerrit CL message with starting message"
-					run:  (_#gerrit._#setCodeReview & {
-						#args: message: "Started the build... see progress at ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}"
-					}).res
-				},
 				_#step & {
 					name: "Checkout ref"
 					run:  """
@@ -168,20 +176,6 @@
 			]
 		}
 	}
-
-	_#gerrit: {
-		_#setCodeReview: {
-			#args: {
-				message: string
-				labels?: {
-					"Code-Review": int
-				}
-			}
-			res: #"""
-			curl -f -s -H "Content-Type: application/json" --request POST --data '\#(encjson.Marshal(#args))' -b ~/.gitcookies https://cue-review.googlesource.com/a/changes/${{ github.event.client_payload.changeID }}/revisions/${{ github.event.client_payload.commit }}/review
-			"""#
-		}
-	}
 }
 
 release: _#bashWorkflow & {