mirror of
https://github.com/actions/runner-images.git
synced 2025-12-19 08:22:12 +00:00
Switch provisioners to install Go from GitHub releases on Ubuntu (#1025)
* install go * added validation * check zero build version * add versions and for ubuntu2004 * setup for ubuntu * fix execute command * fix issue with cat * fix go.sh * fix comments * remove documentation * fix comment position go.sh ubuntu2004 * fix version * remove import * remove variables * remove fake url * fix linking to default version Co-authored-by: Dmitry Shibanov <v-dmshib@microsoft.com>
This commit is contained in:
@@ -28,7 +28,8 @@ $ErrorActionPreference = "Stop"
|
||||
|
||||
# Get toolset content
|
||||
$toolsetJson = Get-Content -Path "$env:INSTALLER_SCRIPT_FOLDER/toolset.json" -Raw
|
||||
$toolsToInstall = @("Python", "Node", "Boost")
|
||||
$toolsToInstall = @("Python", "Node", "Boost", "Go")
|
||||
|
||||
$tools = ConvertFrom-Json -InputObject $toolsetJson | Select-Object -ExpandProperty toolcache | Where {$ToolsToInstall -contains $_.Name}
|
||||
|
||||
foreach ($tool in $tools) {
|
||||
@@ -54,4 +55,5 @@ foreach ($tool in $tools) {
|
||||
}
|
||||
|
||||
chown -R "$($env:SUDO_USER):$($env:SUDO_USER)" /opt/hostedtoolcache/Python
|
||||
chown -R "$($env:SUDO_USER):$($env:SUDO_USER)" /opt/hostedtoolcache/node
|
||||
chown -R "$($env:SUDO_USER):$($env:SUDO_USER)" /opt/hostedtoolcache/node
|
||||
chown -R "$($env:SUDO_USER):$($env:SUDO_USER)" /opt/hostedtoolcache/go
|
||||
@@ -9,13 +9,13 @@ function Run-ExecutableTests {
|
||||
[Parameter(Mandatory)] [string[]] $Executables,
|
||||
[Parameter(Mandatory)] [string] $ToolPath
|
||||
)
|
||||
$versionCommand = $Executables["command"]
|
||||
|
||||
foreach ($executable in $Executables) {
|
||||
foreach ($executable in $Executables["tools"]) {
|
||||
$executablePath = Join-Path $ToolPath $executable
|
||||
|
||||
Write-Host "Check $executable..."
|
||||
if (Test-Path $executablePath) {
|
||||
Write-Host "$executable is successfully installed: $(& $executablePath --version)"
|
||||
Write-Host "$executable is successfully installed: $(& $executablePath $versionCommand)"
|
||||
} else {
|
||||
Write-Host "$executablePath is not installed!"
|
||||
exit 1
|
||||
@@ -27,9 +27,22 @@ $ErrorActionPreference = "Stop"
|
||||
|
||||
# Define executables for cached tools
|
||||
$toolsExecutables = @{
|
||||
Python = @("python", "bin/pip")
|
||||
node = @("bin/node", "bin/npm")
|
||||
PyPy = @("bin/python", "bin/pip")
|
||||
Python = @{
|
||||
tools = @("python", "bin/pip")
|
||||
command = "--version"
|
||||
}
|
||||
node = @{
|
||||
tools = @("bin/node", "bin/npm")
|
||||
command = "--version"
|
||||
}
|
||||
PyPy = @{
|
||||
tools = @("bin/python", "bin/pip")
|
||||
command = "--version"
|
||||
}
|
||||
go = @{
|
||||
tools = @("bin/go")
|
||||
command = "version"
|
||||
}
|
||||
}
|
||||
|
||||
# Get toolset content
|
||||
|
||||
@@ -4,55 +4,23 @@
|
||||
## Desc: Installs go, configures GOROOT, and adds go to the path
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/document.sh
|
||||
golangTags="/tmp/golang_tags.json"
|
||||
# Fail out if any setups fail
|
||||
set -e
|
||||
|
||||
# This function installs Go using the specified arguments:
|
||||
# $1=MajorVersion (1.11)
|
||||
# $2=IsDefaultVersion (true or false)
|
||||
function InstallGo () {
|
||||
version=$( getFullGoVersion $1 )
|
||||
downloadVersion="go$version.linux-amd64.tar.gz"
|
||||
goFolder="$AGENT_TOOLSDIRECTORY/go/$version/x64"
|
||||
toolsetJson="$INSTALLER_SCRIPT_FOLDER/toolset.json"
|
||||
toolsetVersions=(`ls $AGENT_TOOLSDIRECTORY/go`)
|
||||
defaultVersion=$(jq -r '.toolcache[] | select(.name | contains("go")) | .default' $toolsetJson)
|
||||
|
||||
echo "Install Go $version"
|
||||
curl -sL https://dl.google.com/go/${downloadVersion} -o ${downloadVersion}
|
||||
mkdir -p $goFolder
|
||||
tar -C $goFolder -xzf $downloadVersion --strip-components=1 go
|
||||
rm $downloadVersion
|
||||
echo "GOROOT_${1//./_}_X64=$goFolder" | tee -a /etc/environment
|
||||
DocumentInstalledItem "Go $version ($($goFolder/bin/go version))"
|
||||
for toolsetVersion in ${toolsetVersions[@]}
|
||||
do
|
||||
major="$(cut -d'.' -f1 <<< "$toolsetVersion")"
|
||||
minor="$(cut -d'.' -f2 <<< "$toolsetVersion")"
|
||||
goFolder="$AGENT_TOOLSDIRECTORY/go/$toolsetVersion/x64"
|
||||
|
||||
# Create symlink in old location /usr/local/go<version> to new location
|
||||
ln -s $goFolder /usr/local/go$version
|
||||
echo "GOROOT_${major}_${minor}_X64=$goFolder" | tee -a /etc/environment
|
||||
|
||||
# If this version of Go is to be the default version,
|
||||
# symlink it into the path and point GOROOT to it.
|
||||
if [ $2 = true ]
|
||||
then
|
||||
if [[ "$toolsetVersion" =~ $defaultVersion ]]; then
|
||||
ln -s $goFolder/bin/* /usr/bin/
|
||||
echo "GOROOT=$goFolder" | tee -a /etc/environment
|
||||
fi
|
||||
}
|
||||
|
||||
function getFullGoVersion () {
|
||||
local pattern="refs/tags/go$1([.0-9]{0,3})$"
|
||||
local query='[.[] | select( .ref | test($pattern))] | .[-1] | .ref'
|
||||
refValue=$(jq --arg pattern "$pattern" "$query" $golangTags)
|
||||
version=$(echo "$refValue" | cut -d '/' -f 3 | awk -F 'go' '{print $2}')
|
||||
version=$(echo "${version//\"}") # 1.12.17
|
||||
echo $version
|
||||
}
|
||||
|
||||
# load golang_tags.json file
|
||||
curl -s 'https://api.github.com/repos/golang/go/git/refs/tags' > $golangTags
|
||||
# Install Go versions
|
||||
for go in ${GO_VERSIONS}; do
|
||||
echo "Installing Go ${go}"
|
||||
if [[ $go == $GO_DEFAULT ]]; then
|
||||
InstallGo $go true
|
||||
else
|
||||
InstallGo $go false
|
||||
fi
|
||||
done
|
||||
done
|
||||
Reference in New Issue
Block a user