From 32ebc30d43fc2ab95f01c6acbedbd134ef896006 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Wed, 6 May 2020 19:53:08 +0300 Subject: [PATCH 1/5] Move installed go versions to toolcache directory --- images/win/scripts/Installers/Install-Go.ps1 | 25 ++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/images/win/scripts/Installers/Install-Go.ps1 b/images/win/scripts/Installers/Install-Go.ps1 index 6d98ef800f..af766afafa 100644 --- a/images/win/scripts/Installers/Install-Go.ps1 +++ b/images/win/scripts/Installers/Install-Go.ps1 @@ -29,36 +29,37 @@ function Install-GoVersion # Extract the zip archive. It contains a single directory named "go". Write-Host "Extracting Go $latestVersion..." - Expand-Archive -Path $goArchPath -DestinationPath "C:\" -Force + $toolDirectory = Join-Path $env:AGENT_TOOLSDIRECTORY "Go\$latestVersion" + 7z.exe x $goArchPath -o"$toolDirectory" -y | Out-Null + + # Rename the extracted "go" directory to "x64" for full path "C:\hostedtoolcache\windows\Go\1.14.2\x64\..." + Rename-Item -path "$toolDirectory\go" -newName "x64" + $fullArchPath = "$toolDirectory\x64" # Delete unnecessary files to conserve space Write-Host "Cleaning directories of Go $latestVersion..." - if (Test-Path "C:\go\doc") + if (Test-Path "$fullArchPath\doc") { - Remove-Item -Recurse -Force "C:\go\doc" + Remove-Item -Recurse -Force "$fullArchPath\doc" } - if (Test-Path "C:\go\blog") + if (Test-Path "$fullArchPath\blog") { - Remove-Item -Recurse -Force "C:\go\blog" + Remove-Item -Recurse -Force "$fullArchPath\blog" } - # Rename the extracted "go" directory to include the Go version number (to support side-by-side versions of Go). - $newDirName = "Go$latestVersion" - Rename-Item -path "C:\go" -newName $newDirName - # Make this the default version of Go? if ($addToDefaultPath) { Write-Host "Adding Go $latestVersion to the path..." # Add the Go binaries to the path. - Add-MachinePathItem "C:\$newDirName\bin" | Out-Null + Add-MachinePathItem "$fullArchPath\bin" | Out-Null # Set the GOROOT environment variable. - setx GOROOT "C:\$newDirName" /M | Out-Null + setx GOROOT "$fullArchPath" /M | Out-Null } # Done Write-Host "Done installing Go $latestVersion." - return "C:\$newDirName" + return $fullArchPath } # Install Go From 651416faae0440384d08a1046bca30e7f22ec8a1 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Wed, 6 May 2020 20:12:48 +0300 Subject: [PATCH 2/5] Fix go validation script --- images/win/scripts/Installers/Validate-Go.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/images/win/scripts/Installers/Validate-Go.ps1 b/images/win/scripts/Installers/Validate-Go.ps1 index 059ea8fabe..7289350398 100644 --- a/images/win/scripts/Installers/Validate-Go.ps1 +++ b/images/win/scripts/Installers/Validate-Go.ps1 @@ -11,9 +11,9 @@ function Get-GoVersion [String]$goVersion ) Write-Host "Check if $goVersion is presented in the system" - $DestinationPath = "$($env:SystemDrive)\" - $goDirectory = Get-ChildItem -Path $DestinationPath -Filter "Go$goVersion*" | Select-Object -First 1 - $goPath = Join-Path $env:SystemDrive $goDirectory + $DestinationPath = "$($env:AGENT_TOOLSDIRECTORY)\Go" + $goDirectory = Get-ChildItem -Path $DestinationPath -Filter "$goVersion*" | Select-Object -First 1 + $goPath = Join-Path $env:SystemDrive "$goDirectory\x64" $env:Path = "$goPath\bin;" + $env:Path $version = $(go version) From 6f4054323508845bc62371b3d0b90097a253030f Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 7 May 2020 08:47:29 +0300 Subject: [PATCH 3/5] Minor fix --- images/win/scripts/Installers/Validate-Go.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/images/win/scripts/Installers/Validate-Go.ps1 b/images/win/scripts/Installers/Validate-Go.ps1 index 7289350398..c64c365a26 100644 --- a/images/win/scripts/Installers/Validate-Go.ps1 +++ b/images/win/scripts/Installers/Validate-Go.ps1 @@ -11,9 +11,9 @@ function Get-GoVersion [String]$goVersion ) Write-Host "Check if $goVersion is presented in the system" - $DestinationPath = "$($env:AGENT_TOOLSDIRECTORY)\Go" - $goDirectory = Get-ChildItem -Path $DestinationPath -Filter "$goVersion*" | Select-Object -First 1 - $goPath = Join-Path $env:SystemDrive "$goDirectory\x64" + $destinationPath = "$($env:AGENT_TOOLSDIRECTORY)\Go" + $goDirectory = Get-ChildItem -Path $destinationPath -Filter "$goVersion*" | Select-Object -First 1 + $goPath = Join-Path $destinationPath "$goDirectory\x64" $env:Path = "$goPath\bin;" + $env:Path $version = $(go version) From a4cd9472ab7bbd0ee14bbb2712e158345e0d7153 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 7 May 2020 20:18:35 +0300 Subject: [PATCH 4/5] Fix dir name --- images/win/scripts/Installers/Install-Go.ps1 | 2 +- images/win/scripts/Installers/Validate-Go.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/images/win/scripts/Installers/Install-Go.ps1 b/images/win/scripts/Installers/Install-Go.ps1 index af766afafa..58b67f43f8 100644 --- a/images/win/scripts/Installers/Install-Go.ps1 +++ b/images/win/scripts/Installers/Install-Go.ps1 @@ -29,7 +29,7 @@ function Install-GoVersion # Extract the zip archive. It contains a single directory named "go". Write-Host "Extracting Go $latestVersion..." - $toolDirectory = Join-Path $env:AGENT_TOOLSDIRECTORY "Go\$latestVersion" + $toolDirectory = Join-Path $env:AGENT_TOOLSDIRECTORY "go\$latestVersion" 7z.exe x $goArchPath -o"$toolDirectory" -y | Out-Null # Rename the extracted "go" directory to "x64" for full path "C:\hostedtoolcache\windows\Go\1.14.2\x64\..." diff --git a/images/win/scripts/Installers/Validate-Go.ps1 b/images/win/scripts/Installers/Validate-Go.ps1 index c64c365a26..4c88cc1dba 100644 --- a/images/win/scripts/Installers/Validate-Go.ps1 +++ b/images/win/scripts/Installers/Validate-Go.ps1 @@ -11,7 +11,7 @@ function Get-GoVersion [String]$goVersion ) Write-Host "Check if $goVersion is presented in the system" - $destinationPath = "$($env:AGENT_TOOLSDIRECTORY)\Go" + $destinationPath = "$($env:AGENT_TOOLSDIRECTORY)\go" $goDirectory = Get-ChildItem -Path $destinationPath -Filter "$goVersion*" | Select-Object -First 1 $goPath = Join-Path $destinationPath "$goDirectory\x64" From 68a42bfd0af315c6267980b436d5de53969f2875 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 8 May 2020 18:22:24 +0300 Subject: [PATCH 5/5] Add symlink in old location --- images/win/scripts/Installers/Install-Go.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/images/win/scripts/Installers/Install-Go.ps1 b/images/win/scripts/Installers/Install-Go.ps1 index 58b67f43f8..c5d4c144c3 100644 --- a/images/win/scripts/Installers/Install-Go.ps1 +++ b/images/win/scripts/Installers/Install-Go.ps1 @@ -47,6 +47,9 @@ function Install-GoVersion Remove-Item -Recurse -Force "$fullArchPath\blog" } + # Create symlink in old location + New-Item -Path "C:\go$latestVersion" -ItemType SymbolicLink -Value $fullArchPath + # Make this the default version of Go? if ($addToDefaultPath) {