diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index a8984ca9f..3a460d4da 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -35,9 +35,6 @@ steps: - label: ":windows: Tests on Windows" key: windows-test command: ".buildkite/scripts/run-win-tests.ps1" - env: - # Latest 1.24 version supported by Chocolatey. - GO_VERSION: "1.24.6" agents: provider: "gcp" image: "${GO_WINDOWS_AGENT_IMAGE}" diff --git a/.buildkite/scripts/run-win-tests.ps1 b/.buildkite/scripts/run-win-tests.ps1 index 60c231969..2859914a5 100644 --- a/.buildkite/scripts/run-win-tests.ps1 +++ b/.buildkite/scripts/run-win-tests.ps1 @@ -7,12 +7,35 @@ function fixCRLF { git rm --quiet --cached -r . 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 $version" - choco install -y golang --version $version - $env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." - Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" - refreshenv + 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 + } + } + + Write-Host "Installing Go version $version" + & $gvmExe --format=powershell $version | Invoke-Expression + $env:PATH = "$(go env GOPATH)\bin;$env:PATH" go version go env }