mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-20 06:29:50 +00:00
Install latest patch versions of Golang for Windows (#502)
* add golang for windows * minor changes * fix comments * resolve comments * add 1.14 version * add debug lines * fix arrays * better way to remove ecmpty strings * add path * minor fix Co-authored-by: Dmitry Shibanov <v-dmshib@microsoft.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
Import-Module -Name ImageHelpers -Force
|
||||
|
||||
$refsJson = Invoke-RestMethod "https://api.github.com/repos/golang/go/git/refs/tags"
|
||||
function Install-GoVersion
|
||||
{
|
||||
Param
|
||||
@@ -13,17 +14,20 @@ function Install-GoVersion
|
||||
[Switch]$addToDefaultPath
|
||||
)
|
||||
|
||||
$latestVersionObject = $refsJson | Where-Object { $_.ref -Match "refs/tags/go$goVersion[./d]*" } | Select-Object -Last 1
|
||||
$latestVersion = $latestVersionObject.ref.replace('refs/tags/go','')
|
||||
|
||||
# Download the Go zip archive.
|
||||
Write-Host "Downloading Go $goVersion..."
|
||||
Write-Host "Downloading Go $latestVersion..."
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
Invoke-WebRequest -UseBasicParsing -Uri "https://dl.google.com/go/go$goVersion.windows-amd64.zip" -OutFile go$goVersion.windows-amd64.zip
|
||||
Invoke-WebRequest -UseBasicParsing -Uri "https://dl.google.com/go/go$latestVersion.windows-amd64.zip" -OutFile go$latestVersion.windows-amd64.zip
|
||||
|
||||
# Extract the zip archive. It contains a single directory named "go".
|
||||
Write-Host "Extracting Go $goVersion..."
|
||||
Expand-Archive -Path go$goVersion.windows-amd64.zip -DestinationPath "C:\" -Force
|
||||
Write-Host "Extracting Go $latestVersion..."
|
||||
Expand-Archive -Path go$latestVersion.windows-amd64.zip -DestinationPath "C:\" -Force
|
||||
|
||||
# Delete unnecessary files to conserve space
|
||||
Write-Host "Cleaning directories of Go $goVersion..."
|
||||
Write-Host "Cleaning directories of Go $latestVersion..."
|
||||
if (Test-Path "C:\go\doc")
|
||||
{
|
||||
Remove-Item -Recurse -Force "C:\go\doc"
|
||||
@@ -34,17 +38,17 @@ function Install-GoVersion
|
||||
}
|
||||
|
||||
# Rename the extracted "go" directory to include the Go version number (to support side-by-side versions of Go).
|
||||
$newDirName = "Go$goVersion"
|
||||
$newDirName = "Go$latestVersion"
|
||||
Rename-Item -path "C:\go" -newName $newDirName
|
||||
|
||||
# Delete the Go zip archive.
|
||||
Write-Host "Deleting downloaded archive of Go $goVersion..."
|
||||
Remove-Item go$goVersion.windows-a`md64.zip
|
||||
Write-Host "Deleting downloaded archive of Go $latestVersion..."
|
||||
Remove-Item go$latestVersion.windows-amd64.zip
|
||||
|
||||
# Make this the default version of Go?
|
||||
if ($addToDefaultPath)
|
||||
{
|
||||
Write-Host "Adding Go $goVersion to the path..."
|
||||
Write-Host "Adding Go $latestVersion to the path..."
|
||||
# Add the Go binaries to the path.
|
||||
Add-MachinePathItem "C:\$newDirName\bin" | Out-Null
|
||||
# Set the GOROOT environment variable.
|
||||
@@ -52,12 +56,12 @@ function Install-GoVersion
|
||||
}
|
||||
|
||||
# Done
|
||||
Write-Host "Done installing Go $goVersion."
|
||||
Write-Host "Done installing Go $latestVersion."
|
||||
return "C:\$newDirName"
|
||||
}
|
||||
|
||||
# Install Go
|
||||
$goVersionsToInstall = $env:GO_VERSIONS.split(",")
|
||||
$goVersionsToInstall = $env:GO_VERSIONS.split(", ", [System.StringSplitOptions]::RemoveEmptyEntries)
|
||||
|
||||
foreach($go in $goVersionsToInstall) {
|
||||
Write-Host "Installing Go ${go}"
|
||||
@@ -66,6 +70,6 @@ foreach($go in $goVersionsToInstall) {
|
||||
} else {
|
||||
$installDirectory = Install-GoVersion -goVersion $go
|
||||
}
|
||||
$envName = "GOROOT_{0}_{1}_X64" -f $go.split(".")
|
||||
$envName = "GOROOT_{0}_{1}_X64" -f $go.split(".")
|
||||
setx $envName "$installDirectory" /M
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user