Skip to content

Commit bb24c7c

Browse files
committed
internal/ci: set GOTOOLCHAIN=local as part of installGo
Installing a specific version of Go in a CI matrix has intent: i.e. we intend to use that verison for everything. The default value for GOTOOLCHAIN is 'auto'. Per: https://go.dev/doc/toolchain this has the effect of downloading other toolchains as required by go.mod files of dependencies etc. We don't want this: we want to fail in case the version intended by CI is not appropriate. The doc comment in internal/ci/base/github.cue motivates why (for now) we set this variable as part of the installGo step. TL;DR - it localises the setting of a variable pertinent only to jobs that require Go (and the installation of Go is required because it is not part of the base image on all platforms), and an environment variable approach does not work where a matrix of Go versions is involved. Signed-off-by: Paul Jolly <[email protected]> Change-Id: I3b0fa04c69dc51d75bafcdf513e0415adf85564d Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200599 Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent d7852d7 commit bb24c7c

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

Diff for: .github/workflows/release.yml

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ jobs:
5858
with:
5959
cache: false
6060
go-version: 1.23.0
61+
- name: Set common go env vars
62+
run: |-
63+
go env -w GOTOOLCHAIN=local
64+
65+
# Dump env for good measure
66+
go env
6167
- name: Setup qemu
6268
uses: docker/setup-qemu-action@v3
6369
- name: Set up Docker Buildx

Diff for: .github/workflows/trybot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ jobs:
7171
with:
7272
cache: false
7373
go-version: ${{ matrix.go-version }}
74+
- name: Set common go env vars
75+
run: |-
76+
go env -w GOTOOLCHAIN=local
77+
78+
# Dump env for good measure
79+
go env
7480
- name: Get go mod cache directory
7581
id: go-mod-cache-dir
7682
run: echo "dir=$(go env GOMODCACHE)" >> ${GITHUB_OUTPUT}

Diff for: internal/ci/base/github.cue

+45-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,51 @@ bashWorkflow: json.#Workflow & {
1515
jobs: [string]: defaults: run: shell: "bash"
1616
}
1717

18-
installGo: json.#step & {
19-
name: "Install Go"
20-
uses: "actions/setup-go@v5"
21-
with: {
22-
// We do our own caching in setupGoActionsCaches.
23-
cache: false
24-
"go-version": string
18+
installGo: {
19+
#setupGo: json.#step & {
20+
name: "Install Go"
21+
uses: "actions/setup-go@v5"
22+
with: {
23+
// We do our own caching in setupGoActionsCaches.
24+
cache: false
25+
"go-version": string
26+
}
2527
}
28+
29+
// Why set GOTOOLCHAIN here? As opposed to an environment variable
30+
// elsewhere? No perfect answer to this question but here is the thinking:
31+
//
32+
// Setting the variable here localises it with the installation of Go. Doing
33+
// it elsewhere creates distance between the two steps which are
34+
// intrinsically related. And it's also hard to do: "when we use this step,
35+
// also ensure that we establish an environment variable in the job for
36+
// GOTOOLCHAIN".
37+
//
38+
// Environment variables can only be set at a workflow, job or step level.
39+
// Given we currently use a matrix strategy which varies the Go version,
40+
// that rules out using an environment variable based approach, because the
41+
// Go version is only available at runtime via GitHub actions provided
42+
// context. Whether we should instead be templating multiple workflows (i.e.
43+
// exploding the matrix ourselves) is a different question, but one that
44+
// has performance implications.
45+
//
46+
// So as clumsy as it is to use a step "template" that includes more than
47+
// one step, it's the best option available to us for now.
48+
[
49+
#setupGo,
50+
51+
{
52+
json.#step & {
53+
name: "Set common go env vars"
54+
run: """
55+
go env -w GOTOOLCHAIN=local
56+
57+
# Dump env for good measure
58+
go env
59+
"""
60+
}
61+
},
62+
]
2663
}
2764

2865
checkoutCode: {
@@ -100,7 +137,7 @@ checkoutCode: {
100137

101138
earlyChecks: json.#step & {
102139
name: "Early git and code sanity checks"
103-
run: "go run ./internal/ci/checks"
140+
run: "go run ./internal/ci/checks"
104141
}
105142

106143
curlGitHubAPI: {

Diff for: internal/ci/github/release.cue

+6-3
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ workflows: release: _repo.bashWorkflow & {
4242
jobs: goreleaser: {
4343
"runs-on": _repo.linuxMachine
4444
if: "${{github.repository == '\(_repo.githubRepositoryPath)'}}"
45+
46+
let installGo = _repo.installGo & {
47+
#setupGo: with: "go-version": _repo.pinnedReleaseGo
48+
_
49+
}
4550
steps: [
4651
for v in _repo.checkoutCode {v},
47-
_repo.installGo & {
48-
with: "go-version": _repo.pinnedReleaseGo
49-
},
52+
for v in installGo {v},
5053
json.#step & {
5154
name: "Setup qemu"
5255
uses: "docker/setup-qemu-action@v3"

Diff for: internal/ci/github/trybot.cue

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ workflows: trybot: _repo.bashWorkflow & {
4343
_
4444
}
4545

46+
let installGo = _repo.installGo & {
47+
#setupGo: with: "go-version": goVersionVal
48+
_
49+
}
50+
4651
// Only run the trybot workflow if we have the trybot trailer, or
4752
// if we have no special trailers. Note this condition applies
4853
// after and in addition to the "on" condition above.
@@ -51,9 +56,7 @@ workflows: trybot: _repo.bashWorkflow & {
5156
steps: [
5257
for v in _repo.checkoutCode {v},
5358

54-
_repo.installGo & {
55-
with: "go-version": goVersionVal
56-
},
59+
for v in installGo {v},
5760

5861
// cachePre must come after installing Node and Go, because the cache locations
5962
// are established by running each tool.

0 commit comments

Comments
 (0)