mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-20 06:29:50 +00: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"
|
||||
|
||||
Reference in New Issue
Block a user