Skip to content

Avoid Toolchain download before cache download#456

Closed
matthewhughes-uw wants to merge 7 commits intoactions:mainfrom
matthewhughes-uw:avoid-toolchain-download-before-cache-download
Closed

Avoid Toolchain download before cache download#456
matthewhughes-uw wants to merge 7 commits intoactions:mainfrom
matthewhughes-uw:avoid-toolchain-download-before-cache-download

Conversation

@matthewhughes-uw
Copy link

Description:

go version is run before downloading the cache, but if this is run with a version of go that triggers a Toolchain download[1], e.g. if the installed Go is 1.20.0 but go.mod has a toolchain directive go1.20.1 then a toolchain is downloaded to e.g.
$GOMODCACHE/golang.org/toolchain@v0.0.1-go1.21.1.linux-amd64, if this file already exists in the cache (e.g. this is the second run of this action we not cache invalidation) then the cache download will try and overwrite these files resulting in noisy errors like:

/usr/bin/tar: ../../../go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.6.linux-amd64/lib/time/mkzip.go: Cannot open: File exists 

Instead, force go to use the local toolchain (i.e. the one the one that shipped with the go command being run) via setting the GOTOOLCHAIN environment variable[1]:

When GOTOOLCHAIN is set to local, the go command always runs the
bundled Go toolchain.

[1] https://go.dev/doc/toolchain#select

Related issue:

This addresses #424

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.
`go version` is run before downloading the cache, but if this is run with a version of `go` that triggers a Toolchain download[1], e.g. if the installed Go is 1.20.0 but `go.mod` has a toolchain directive `go1.20.1` then a toolchain is downloaded to e.g. `$GOMODCACHE/golang.org/toolchain@v0.0.1-go1.21.1.linux-amd64`, if this file already exists in the cache (e.g. this is the second run of this action we not cache invalidation) then the cache download will try and overwrite these files resulting in noisy errors like: /usr/bin/tar: ../../../go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.6.linux-amd64/lib/time/mkzip.go: Cannot open: File exists Instead, force `go` to use the local toolchain (i.e. the one the one that shipped with the go command being run) via setting the `GOTOOLCHAIN` environment variable[1]: > When GOTOOLCHAIN is set to local, the go command always runs the bundled Go toolchain. This addresses actions#424 [1] https://go.dev/doc/toolchain#select
@matthewhughes-uw matthewhughes-uw requested a review from a team as a code owner February 8, 2024 09:02
src/main.ts Outdated
Comment on lines +65 to +68
// run `go version` with the bundled Go toolchain to avoid potentially
// downloading one into the cache
const goVersion = (cp.execSync(`${goPath} version`) || '',
{env: {...process.env, GOTOOLCHAIN: 'local'}}).toString();
Copy link
Author

@matthewhughes-uw matthewhughes-uw Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to hear any suggestions for testing this (i.e. test that a toolchain isn't downloaded)

EDIT: testing via https://github.com/matthewhughes-uw/setup-go-test, looks like I missed something

@matthewhughes-uw
Copy link
Author

The code is a bit messy right now, but I just want to get a PoC working, which it looks like it is:

  • https://github.com/matthewhughes-uw/setup-go-test/actions/runs/7828709329/job/21359175784 Is a run of this action with no cache, the
  • https://github.com/matthewhughes-uw/setup-go-test/actions/runs/7828709329/job/21359270238 is a re-run (so it fetches the cache), relevant bits
    /home/runner/go/pkg/mod /home/runner/.cache/go-build Received 135885390 of 135885390 (100.0%), 150.5 MBs/sec Cache Size: ~130 MB (135885390 B) /usr/bin/tar -xf /home/runner/work/_temp/1f7ecae3-44ef-4969-b908-d4ffcf921776/cache.tzst -P -C /home/runner/work/setup-go-test/setup-go-test --use-compress-program unzstd Cache restored successfully Cache restored from key: setup-go-Linux-ubuntu22-go-1.21.0-4f4993868a2b816b41e3c5c199728557ac2cff07b1ccbc868d1a562af19625dd go version go1.21.0 linux/amd64 
    i.e. we restore the cache without warnings, the toolchain for go1.21.1 is included in this cache and used later in the go version job
@matthewhughes-uw
Copy link
Author

#460 is a better solution to this

@matthewhughes-uw matthewhughes-uw deleted the avoid-toolchain-download-before-cache-download branch March 4, 2024 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants