mirror of
https://github.com/actions/runner-images.git
synced 2025-12-30 13:58:18 +08:00
Toolcache: Add NPM Toolcache support for Windows/Linux
This commit is contained in:
@@ -1,51 +1,62 @@
|
||||
################################################################################
|
||||
## File: Download-ToolCache.ps1
|
||||
## Team: CI-Build
|
||||
## Desc: Download tool cache
|
||||
################################################################################
|
||||
|
||||
Function InstallTool
|
||||
{
|
||||
Param
|
||||
(
|
||||
[System.Object]$ExecutablePath
|
||||
Function Install-NpmPackage {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[System.String]
|
||||
$Name,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[System.String]
|
||||
$NpmRegistry
|
||||
)
|
||||
|
||||
Write-Host $ExecutablePath.DirectoryName
|
||||
Set-Location -Path $ExecutablePath.DirectoryName
|
||||
Get-Location | Write-Host
|
||||
if (Test-Path 'tool.zip')
|
||||
{
|
||||
Write-Host "Installing npm '$Name' package from '$NpmRegistry'"
|
||||
|
||||
npm install $Name --registry=$NpmRegistry
|
||||
}
|
||||
|
||||
Function InstallTool {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[System.IO.FileInfo]$ExecutablePath
|
||||
)
|
||||
|
||||
Set-Location -Path $ExecutablePath.DirectoryName -PassThru | Write-Host
|
||||
if (Test-Path 'tool.zip') {
|
||||
Expand-Archive 'tool.zip' -DestinationPath '.'
|
||||
}
|
||||
cmd.exe /c 'install_to_tools_cache.bat'
|
||||
}
|
||||
|
||||
$SourceUrl = "https://vstsagenttools.blob.core.windows.net/tools"
|
||||
|
||||
# HostedToolCache Path
|
||||
$Dest = "C:/"
|
||||
|
||||
$Path = "hostedtoolcache/windows"
|
||||
|
||||
$env:Path = "C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy;" + $env:Path
|
||||
|
||||
Write-Host "Started AzCopy from $SourceUrl to $Dest"
|
||||
|
||||
AzCopy /Source:$SourceUrl /Dest:$Dest /S /V /Pattern:$Path
|
||||
|
||||
$ToolsDirectory = $Dest + $Path
|
||||
|
||||
$current = Get-Location
|
||||
Set-Location -Path $ToolsDirectory
|
||||
|
||||
Get-ChildItem -Recurse -Depth 4 -Filter install_to_tools_cache.bat | ForEach-Object {
|
||||
#In order to work correctly Python 3.4 x86 must be installed after x64, this is achieved by current toolcache catalog structure
|
||||
InstallTool($_)
|
||||
}
|
||||
|
||||
Set-Location -Path $current
|
||||
|
||||
# Define AGENT_TOOLSDIRECTORY environment variable
|
||||
$env:AGENT_TOOLSDIRECTORY = $ToolsDirectory
|
||||
setx AGENT_TOOLSDIRECTORY $ToolsDirectory /M
|
||||
|
||||
# Install tools form NPM
|
||||
|
||||
$ToolVersionsFileContent = Get-Content -Path "$env:ROOT_FOLDER/toolcache.json" -Raw
|
||||
$ToolVersions = ConvertFrom-Json -InputObject $ToolVersionsFileContent
|
||||
|
||||
$ToolVersions.PSObject.Properties | ForEach-Object {
|
||||
$PackageName = $_.Name
|
||||
$PackageVersions = $_.Value
|
||||
$NpmPackages = $PackageVersions | ForEach-Object { "$PackageName@$_" }
|
||||
foreach($NpmPackage in $NpmPackages) {
|
||||
Install-NpmPackage -Name $NpmPackage -NpmRegistry $env:TOOLCACHE_REGISTRY
|
||||
}
|
||||
}
|
||||
|
||||
#junction point from the previous Python2 directory to the toolcache Python2
|
||||
Write-Host "Create symlink to Python2"
|
||||
$python2Dir = (Get-Item -Path ($ToolsDirectory + '/Python/2.7*/x64')).FullName
|
||||
cmd.exe /c mklink /d "C:\Python27amd64" "$python2Dir"
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
################################################################################
|
||||
## File: Install-Boost.ps1
|
||||
## File: Set-BoostRoot.ps1
|
||||
## Team: CI-Build
|
||||
## Desc: Install boost using tool cache
|
||||
################################################################################
|
||||
|
||||
$ToolCache = 'C:\hostedtoolcache\windows\boost'
|
||||
$BoostDirectory = Join-Path -Path $env:ProgramFiles -ChildPath "Boost"
|
||||
$BoostVersionsToInstall = $env:BOOST_VERSIONS.split(',')
|
||||
$BoostVersions = $env:BOOST_VERSIONS.split(',')
|
||||
$BoostDefault = $env:BOOST_DEFAULT
|
||||
|
||||
foreach($BoostVersion in $BoostVersionsToInstall)
|
||||
foreach($BoostVersion in $BoostVersions)
|
||||
{
|
||||
$ZipName = Join-Path -Path $ToolCache -ChildPath "boost_${BoostVersion}_msvc-14.1.zip"
|
||||
|
||||
if (-Not (Test-Path $ZipName))
|
||||
{
|
||||
Write-Host "$ZipName not found"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Expanding $ZipName"
|
||||
|
||||
$BoostInstallationDir = Join-Path -Path $BoostDirectory -ChildPath $BoostVersion
|
||||
# Expand-Archive slower for 70% than 7z
|
||||
& "$env:ProgramFiles\7-Zip\7z.exe" x $ZipName -o"$BoostDirectory" -y
|
||||
|
||||
$EnvBoostPath = "BOOST_ROOT_{0}" -f ($BoostVersion.Replace('.', '_'))
|
||||
setx $EnvBoostPath $BoostInstallationDir /M | Out-Null
|
||||
@@ -36,10 +24,3 @@ foreach($BoostVersion in $BoostVersionsToInstall)
|
||||
setx BOOST_ROOT $BoostInstallationDir /M | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# Removing boost cache folder
|
||||
Write-Host "Removing boost cache folder"
|
||||
if (Test-Path $ToolCache)
|
||||
{
|
||||
Remove-Item -Path $ToolCache -Force -Recurse
|
||||
}
|
||||
|
||||
@@ -12,6 +12,21 @@ function GetChildFolders {
|
||||
return Get-ChildItem -Path $Path -Directory -Name
|
||||
}
|
||||
|
||||
function Get-ToolcachePackages {
|
||||
$toolcachePath = Join-Path $env:ROOT_FOLDER "toolcache.json"
|
||||
return Get-Content -Raw $toolcachePath | ConvertFrom-Json
|
||||
}
|
||||
|
||||
$packages = (Get-ToolcachePackages).PSObject.Properties | ForEach-Object {
|
||||
$packageNameParts = $_.Name.Split("-")
|
||||
$toolName = $packageNameParts[1]
|
||||
return [PSCustomObject] @{
|
||||
ToolName = $packageNameParts[1]
|
||||
Versions = $_.Value
|
||||
Arch = $packageNameParts[3]
|
||||
}
|
||||
}
|
||||
|
||||
function ToolcacheTest {
|
||||
param (
|
||||
[Parameter(Mandatory = $True)]
|
||||
@@ -22,36 +37,53 @@ function ToolcacheTest {
|
||||
if (Test-Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName")
|
||||
{
|
||||
$description = ""
|
||||
[array]$versions = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName"
|
||||
if ($versions.count -gt 0){
|
||||
foreach ($version in $versions)
|
||||
[array]$instaledVersions = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName"
|
||||
if ($instaledVersions.count -gt 0){
|
||||
$softwarePackages = $packages | Where-Object { $_.ToolName -eq $SoftwareName }
|
||||
foreach($softwarePackage in $softwarePackages)
|
||||
{
|
||||
$architectures = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version"
|
||||
|
||||
Write-Host "$SoftwareName version - $version : $([system.String]::Join(",", $architectures))"
|
||||
|
||||
foreach ($arch in $architectures)
|
||||
foreach ($version in $softwarePackage.Versions)
|
||||
{
|
||||
$path = "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version\$arch"
|
||||
foreach ($test in $ExecTests)
|
||||
{
|
||||
if (Test-Path "$path\$test")
|
||||
{
|
||||
Write-Host "$SoftwareName($test) $version($arch) is successfully installed:"
|
||||
Write-Host (& "$path\$test" --version)
|
||||
$foundVersion = $instaledVersions | where { $_.StartsWith($version) }
|
||||
|
||||
if ($foundVersion -ne $null){
|
||||
|
||||
$architectures = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion"
|
||||
|
||||
$softwareArch = $softwarePackage.Arch
|
||||
|
||||
if ($architectures -Contains $softwareArch) {
|
||||
$path = "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion\$softwareArch"
|
||||
foreach ($test in $ExecTests)
|
||||
{
|
||||
if (Test-Path "$path\$test")
|
||||
{
|
||||
Write-Host "$SoftwareName($test) $foundVersion($softwareArch) is successfully installed:"
|
||||
Write-Host (& "$path\$test" --version)
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "$SoftwareName($test) $foundVersion ($softwareArch) is not installed"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
$description += "_Version:_ $foundVersion ($softwareArch)<br/>"
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "$SoftwareName($test) $version ($arch) is not installed"
|
||||
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion does not include required architecture"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
$description += "_Version:_ $version ($arch)<br/>"
|
||||
else
|
||||
{
|
||||
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version.* was not found"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $description
|
||||
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $description
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user