mirror of
				https://github.com/actions/setup-go.git
				synced 2025-10-31 23:43:41 +00:00 
			
		
		
		
	Avoid Toolchain download before cache download
`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 https://github.com/actions/setup-go/issues/424
[1] https://go.dev/doc/toolchain#select
			
			
This commit is contained in:
		
							parent
							
								
									883490dfd0
								
							
						
					
					
						commit
						0815ecbd83
					
				| @ -62,7 +62,10 @@ export async function run() { | ||||
|     core.debug(`add bin ${added}`); | ||||
| 
 | ||||
|     const goPath = await io.which('go'); | ||||
|     const goVersion = (cp.execSync(`${goPath} version`) || '').toString(); | ||||
|     // 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(); | ||||
| 
 | ||||
|     if (cache && isCacheFeatureAvailable()) { | ||||
|       const packageManager = 'default'; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user