diff --git a/.buildkite/scripts/run-tests.ps1 b/.buildkite/scripts/run-tests.ps1 index 6bdd47210..4d65d5896 100644 --- a/.buildkite/scripts/run-tests.ps1 +++ b/.buildkite/scripts/run-tests.ps1 @@ -8,19 +8,36 @@ function fixCRLF { git reset --quiet --hard } +function ensureBinPath { + $workDir = if ($env:WORKSPACE) { $env:WORKSPACE } else { $PWD.Path } + $binDir = Join-Path $workDir "bin" + if (-not (Test-Path $binDir)) { New-Item -ItemType Directory -Path $binDir | Out-Null } + $env:PATH = "$binDir;$env:PATH" + return $binDir +} + function withGolang($version) { - Write-Host "--- Install golang" - $latest_1_25_versions = @('1.25.8') - # not all latest Golang versions of 1.25.x are available since 1.26.0 is released - if ($version -in $latest_1_25_versions) { - Write-Host "$version not available in cholocatey, using 1.25.7" - # latest Golang version available for 1.25.x - $version = '1.25.7' + Write-Host "--- Install golang (GVM)" + $binDir = ensureBinPath + $gvmExe = Join-Path $binDir "gvm-windows-amd64.exe" + $gvmUrl = "https://github.com/andrewkroh/gvm/releases/download/$env:SETUP_GVM_VERSION/gvm-windows-amd64.exe" + + Write-Host "Installing GVM tool" + $maxTries = 5 + for ($i = 1; $i -le $maxTries; $i++) { + try { + Invoke-WebRequest -Uri $gvmUrl -OutFile $gvmExe -UseBasicParsing + break + } catch { + if ($i -eq $maxTries) { throw } + Start-Sleep -Seconds 3 + } } - choco install -y golang --version $version - $env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." - Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" - refreshenv + + Write-Host "Installing Go version $version" + # GVM with --format=powershell prints env-setting code; Invoke-Expression runs it in this session so Go is on PATH + & $gvmExe --format=powershell $version | Invoke-Expression + $env:PATH = "$(go env GOPATH)\bin;$env:PATH" go version go env }