Switch Windows hostedtoolcache provisioner to GitHub Actions NPM registry (#315)

* Toolcache: add basic error handling in Windows toolcache provisioner

* Toolcache: add GITHUB_FEED_TOKEN into packer templates for Windows

* Toolcache: separate toolcache.json for Windows

* Rework "Validate-ToolCache" script (#6)

* Rework validate toolcache script

* change boost root folder

* Add boost 1.69 for windows-2019

* Add toolcache config variable to Windows 16, 19

* Revert "Add toolcache config variable to Windows 16, 19"

* Add default boost version for validate-boost VS19

* Remove bjam test for boost

* Add boost 1.72 validation for win-2016

Co-authored-by: MaksimZhukov <46996400+MaksimZhukov@users.noreply.github.com>
Co-authored-by: Aleksandr Chebotov <47745270+al-cheb@users.noreply.github.com>
This commit is contained in:
Maksim Petrov
2020-01-29 10:41:09 +03:00
committed by GitHub
parent e0f5ff2061
commit 0967620111
9 changed files with 187 additions and 110 deletions

View File

@@ -26,9 +26,9 @@
"install_password": null, "install_password": null,
"capture_name_prefix": "packer", "capture_name_prefix": "packer",
"image_version": "dev", "image_version": "dev",
"toolcache_registry": "https://buildcanary.pkgs.visualstudio.com/PipelineCanary/_packaging/hostedtoolcache/npm/registry/" "github_feed_token": "{{env `GITHUB_FEED_TOKEN`}}"
}, },
"sensitive-variables": ["install_password", "ssh_password", "client_secret"], "sensitive-variables": ["install_password", "ssh_password", "client_secret", "github_feed_token"],
"builders": [ "builders": [
{ {
"name": "vhd", "name": "vhd",
@@ -283,13 +283,13 @@
}, },
{ {
"type": "file", "type": "file",
"source": "{{template_dir}}/toolcache.json", "source": "{{template_dir}}/toolcache-2016.json",
"destination": "{{user `root_folder`}}/toolcache.json" "destination": "{{user `root_folder`}}/toolcache.json"
}, },
{ {
"type": "powershell", "type": "powershell",
"environment_vars":[ "environment_vars":[
"TOOLCACHE_REGISTRY={{ user `toolcache_registry` }}", "GITHUB_FEED_TOKEN={{ user `github_feed_token` }}",
"ROOT_FOLDER={{user `root_folder`}}" "ROOT_FOLDER={{user `root_folder`}}"
], ],
"scripts":[ "scripts":[
@@ -477,7 +477,7 @@
{ {
"type": "powershell", "type": "powershell",
"environment_vars": [ "environment_vars": [
"BOOST_VERSIONS=1.69.0", "BOOST_VERSIONS=1.69.0,1.72.0",
"BOOST_DEFAULT=1.69.0" "BOOST_DEFAULT=1.69.0"
], ],
"scripts":[ "scripts":[
@@ -612,7 +612,7 @@
{ {
"type": "powershell", "type": "powershell",
"environment_vars": [ "environment_vars": [
"BOOST_VERSIONS=1.69.0", "BOOST_VERSIONS=1.69.0,1.72.0",
"BOOST_DEFAULT=1.69.0" "BOOST_DEFAULT=1.69.0"
], ],
"scripts":[ "scripts":[

View File

@@ -26,9 +26,9 @@
"install_password": null, "install_password": null,
"capture_name_prefix": "packer", "capture_name_prefix": "packer",
"image_version": "dev", "image_version": "dev",
"toolcache_registry": "https://buildcanary.pkgs.visualstudio.com/PipelineCanary/_packaging/hostedtoolcache/npm/registry/" "github_feed_token": "{{env `GITHUB_FEED_TOKEN`}}"
}, },
"sensitive-variables": ["install_password", "ssh_password", "client_secret"], "sensitive-variables": ["install_password", "ssh_password", "client_secret", "github_feed_token"],
"builders": [ "builders": [
{ {
"name": "vhd", "name": "vhd",
@@ -252,13 +252,13 @@
}, },
{ {
"type": "file", "type": "file",
"source": "{{template_dir}}/toolcache.json", "source": "{{template_dir}}/toolcache-2019.json",
"destination": "{{user `root_folder`}}/toolcache.json" "destination": "{{user `root_folder`}}/toolcache.json"
}, },
{ {
"type": "powershell", "type": "powershell",
"environment_vars":[ "environment_vars":[
"TOOLCACHE_REGISTRY={{ user `toolcache_registry` }}", "GITHUB_FEED_TOKEN={{ user `github_feed_token` }}",
"ROOT_FOLDER={{user `root_folder`}}" "ROOT_FOLDER={{user `root_folder`}}"
], ],
"scripts":[ "scripts":[
@@ -446,8 +446,8 @@
{ {
"type": "powershell", "type": "powershell",
"environment_vars": [ "environment_vars": [
"BOOST_VERSIONS=1.69.0", "BOOST_VERSIONS=1.69.0,1.72.0",
"BOOST_DEFAULT=1.69.0" "BOOST_DEFAULT=1.72.0"
], ],
"scripts":[ "scripts":[
"{{ template_dir }}/scripts/Installers/Install-Boost.ps1" "{{ template_dir }}/scripts/Installers/Install-Boost.ps1"
@@ -581,8 +581,8 @@
{ {
"type": "powershell", "type": "powershell",
"environment_vars": [ "environment_vars": [
"BOOST_VERSIONS=1.69.0", "BOOST_VERSIONS=1.69.0,1.72.0",
"BOOST_DEFAULT=1.69.0" "BOOST_DEFAULT=1.72.0"
], ],
"scripts":[ "scripts":[
"{{ template_dir }}/scripts/Installers/Validate-Boost.ps1" "{{ template_dir }}/scripts/Installers/Validate-Boost.ps1"

View File

@@ -8,18 +8,45 @@ Function Install-NpmPackage {
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[System.String] [System.String] $PackageName,
$Name,
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[System.String] [System.Uri] $FeedPrefix
$NpmRegistry
) )
Write-Host "Installing npm '$Name' package from '$NpmRegistry'" Push-Location -Path $env:TEMP
npm install $Name --registry=$NpmRegistry $FeedUri = $FeedPrefix.AbsoluteUri
Write-Host "Installing npm $PackageName from ${FeedUri}"
npm install $PackageName --registry "${FeedUri}"
if($LASTEXITCODE) {
Write-Host "$PackageName installation failure; Error: ${LASTEXITCODE}"
exit 1
}
Pop-Location
} }
Function NPMFeed-AuthSetup {
param(
[Parameter(Mandatory=$true)]
[System.String] $AccessToken,
[Parameter(Mandatory=$true)]
[System.Uri] $FeedPrefix
)
$FeedHost = $FeedPrefix.Host
Write-Host "Configure auth for github package registry"
$npmrcContent = "//${FeedHost}/:_authToken=${AccessToken}"
$npmrcContent | Out-File -FilePath "$($env:TEMP)/.npmrc" -Encoding utf8
}
$FeedPrefix = "https://npm.pkg.github.com"
$AccessToken = $env:GITHUB_FEED_TOKEN
# HostedToolCache Path # HostedToolCache Path
$Dest = "C:/" $Dest = "C:/"
$Path = "hostedtoolcache/windows" $Path = "hostedtoolcache/windows"
@@ -33,12 +60,14 @@ setx AGENT_TOOLSDIRECTORY $ToolsDirectory /M
$ToolVersionsFileContent = Get-Content -Path "$env:ROOT_FOLDER/toolcache.json" -Raw $ToolVersionsFileContent = Get-Content -Path "$env:ROOT_FOLDER/toolcache.json" -Raw
$ToolVersions = ConvertFrom-Json -InputObject $ToolVersionsFileContent $ToolVersions = ConvertFrom-Json -InputObject $ToolVersionsFileContent
NPMFeed-AuthSetup -AccessToken $AccessToken -FeedPrefix $FeedPrefix
$ToolVersions.PSObject.Properties | ForEach-Object { $ToolVersions.PSObject.Properties | ForEach-Object {
$PackageName = $_.Name $PackageName = $_.Name
$PackageVersions = $_.Value $PackageVersions = $_.Value
$NpmPackages = $PackageVersions | ForEach-Object { "$PackageName@$_" } $NpmPackages = $PackageVersions | ForEach-Object { "$PackageName@$_" }
foreach($NpmPackage in $NpmPackages) { foreach($NpmPackage in $NpmPackages) {
Install-NpmPackage -Name $NpmPackage -NpmRegistry $env:TOOLCACHE_REGISTRY Install-NpmPackage -PackageName $NpmPackage -FeedPrefix $FeedPrefix
} }
} }

View File

@@ -4,7 +4,7 @@
## Desc: Install boost using tool cache ## Desc: Install boost using tool cache
################################################################################ ################################################################################
$BoostDirectory = Join-Path -Path $env:ProgramFiles -ChildPath "Boost" $BoostDirectory = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Boost"
$BoostVersions = $env:BOOST_VERSIONS.split(',') $BoostVersions = $env:BOOST_VERSIONS.split(',')
$BoostDefault = $env:BOOST_DEFAULT $BoostDefault = $env:BOOST_DEFAULT

View File

@@ -13,10 +13,10 @@ function Validate-BoostVersion
$ReleasePath = Join-Path -Path $BoostRootPath -ChildPath $BoostRelease $ReleasePath = Join-Path -Path $BoostRootPath -ChildPath $BoostRelease
if ((Test-Path "$ReleasePath\b2.exe") -and (Test-Path "$ReleasePath\bjam.exe")) if (Test-Path "$ReleasePath\b2.exe")
{ {
Write-Host "Boost.Build $BoostRelease is successfully installed" Write-Host "Boost.Build $BoostRelease is successfully installed"
Write-Host "Boost.Jam $BoostRelease is successfully installed"
return return
} }
@@ -25,7 +25,7 @@ function Validate-BoostVersion
} }
# Verify that Boost is on the path # Verify that Boost is on the path
if ((Get-Command -Name 'b2') -and (Get-Command -Name 'bjam')) if (Get-Command -Name 'b2')
{ {
Write-Host "Boost is on the path" Write-Host "Boost is on the path"
} }
@@ -54,15 +54,15 @@ $tmplMarkRoot = @"
$SoftwareName = 'Boost' $SoftwareName = 'Boost'
$Description = New-Object System.Text.StringBuilder $Description = New-Object System.Text.StringBuilder
$BoostRootDirectory = Join-Path -Path $env:ProgramFiles -ChildPath "Boost" $BoostRootDirectory = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Boost"
$BoostVersionsToInstall = $env:BOOST_VERSIONS.split(",") $BoostVersionsToInstall = $env:BOOST_VERSIONS.split(",")
foreach($Boost in $BoostVersionsToInstall) foreach($BoostVersion in $BoostVersionsToInstall)
{ {
Validate-BoostVersion -BoostRootPath $BoostRootDirectory -BoostRelease $Boost Validate-BoostVersion -BoostRootPath $BoostRootDirectory -BoostRelease $BoostVersion
$BoostVersionTag = "BOOST_ROOT_{0}" -f $Boost.Replace('.', '_') $BoostVersionTag = "BOOST_ROOT_{0}" -f $BoostVersion.Replace('.', '_')
if($boost -eq $env:BOOST_DEFAULT) if($BoostVersion -eq $env:BOOST_DEFAULT)
{ {
$null = $Description.AppendLine(($tmplMarkRoot -f $BoostVersion, $BoostVersionTag)) $null = $Description.AppendLine(($tmplMarkRoot -f $BoostVersion, $BoostVersionTag))
} }

View File

@@ -17,16 +17,62 @@ function Get-ToolcachePackages {
return Get-Content -Raw $toolcachePath | ConvertFrom-Json return Get-Content -Raw $toolcachePath | ConvertFrom-Json
} }
$packages = (Get-ToolcachePackages).PSObject.Properties | ForEach-Object { $toolcachePackages = (Get-ToolcachePackages).PSObject.Properties | ForEach-Object {
$packageNameParts = $_.Name.Split("-") $packageNameParts = $_.Name.Split("-")
$toolName = $packageNameParts[1]
return [PSCustomObject] @{ return [PSCustomObject] @{
ToolName = $packageNameParts[1] ToolName = $packageNameParts[1]
Versions = $_.Value Versions = $_.Value
Arch = $packageNameParts[3] Architecture = $packageNameParts[3]
} }
} }
function GetToolsByName {
param (
[Parameter(Mandatory = $True)]
[string]$SoftwareName
)
return $toolcachePackages | Where-Object { $_.ToolName -eq $SoftwareName }
}
function RunTestsByPath {
param (
[Parameter(Mandatory = $True)]
[string[]]$ExecTests,
[Parameter(Mandatory = $True)]
[string]$Path,
[Parameter(Mandatory = $True)]
[string]$SoftwareName,
[Parameter(Mandatory = $True)]
[string]$SoftwareVersion,
[Parameter(Mandatory = $True)]
[string]$SoftwareArchitecture
)
foreach ($test in $ExecTests)
{
if (Test-Path "$Path\$test")
{
Write-Host "$SoftwareName($test) $SoftwareVersion($SoftwareArchitecture) is successfully installed:"
Write-Host (& "$Path\$test" --version)
}
else
{
Write-Host "$SoftwareName($test) $SoftwareVersion($SoftwareArchitecture) is not installed"
exit 1
}
}
}
function GetMarkdownDescription {
param (
[Parameter(Mandatory = $True)]
[string]$SoftwareVersion,
[Parameter(Mandatory = $True)]
[string]$SoftwareArchitecture
)
return "_Version:_ $SoftwareVersion ($SoftwareArchitecture)<br/>"
}
function ToolcacheTest { function ToolcacheTest {
param ( param (
[Parameter(Mandatory = $True)] [Parameter(Mandatory = $True)]
@@ -34,68 +80,50 @@ function ToolcacheTest {
[Parameter(Mandatory = $True)] [Parameter(Mandatory = $True)]
[string[]]$ExecTests [string[]]$ExecTests
) )
if (Test-Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName")
$softwarePath = "$env:AGENT_TOOLSDIRECTORY\$SoftwareName"
if (-Not (Test-Path $softwarePath))
{ {
$description = "" Write-Host "$softwarePath does not exist"
[array]$installedVersions = GetChildFolders -Path "$env:AGENT_TOOLSDIRECTORY\$SoftwareName" exit 1
if ($installedVersions.count -gt 0){ }
$softwarePackages = $packages | Where-Object { $_.ToolName -eq $SoftwareName }
foreach($softwarePackage in $softwarePackages) [array]$installedVersions = GetChildFolders -Path $softwarePath
if ($installedVersions.count -eq 0)
{ {
foreach ($version in $softwarePackage.Versions) Write-Host "$softwarePath does not include any folders"
exit 1
}
$markdownDescription = ""
$tools = GetToolsByName -SoftwareName $SoftwareName
foreach($tool in $tools)
{
foreach ($version in $tool.Versions)
{ {
$foundVersion = $installedVersions | where { $_.StartsWith($version) } $foundVersion = $installedVersions | where { $_.StartsWith($version) }
if ($foundVersion -eq $null)
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 "$softwarePath\$version.* was not found"
{
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 exit 1
} }
}
$description += "_Version:_ $foundVersion ($softwareArch)<br/>" $installedArchitecture = GetChildFolders -Path "$softwarePath\$foundVersion"
} $requiredArchitecture = $tool.Architecture
else if (-Not ($installedArchitecture -Contains $requiredArchitecture))
{ {
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$foundVersion does not include required architecture" Write-Host "$softwarePath\$foundVersion does not include the $requiredArchitecture architecture"
exit 1 exit 1
} }
}
else
{
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName\$version.* was not found"
exit 1
}
}
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $description $path = "$softwarePath\$foundVersion\$requiredArchitecture"
RunTestsByPath -ExecTests $ExecTests -Path $path -SoftwareName $SoftwareName -SoftwareVersion $foundVersion -SoftwareArchitecture $requiredArchitecture
$markdownDescription += GetMarkdownDescription -SoftwareVersion $foundVersion -SoftwareArchitecture $requiredArchitecture
} }
} }
else Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $markdownDescription
{
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName does not include any folders"
exit 1
}
}
else
{
Write-Host "$env:AGENT_TOOLSDIRECTORY\$SoftwareName does not exist"
exit 1
}
} }
# Python test # Python test

View File

@@ -0,0 +1,17 @@
{
"@actions/toolcache-python-windows-x64": [
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"@actions/toolcache-python-windows-x86": [
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"@actions/toolcache-ruby-windows-x64": [
"2.4", "2.5", "2.6", "2.7"
],
"@actions/toolcache-pypy-windows-x86": [
"2", "3"
],
"@actions/toolcache-boost-windows-msvc-14.1-x32-x64": [
"1.69", "1.72"
]
}

View File

@@ -0,0 +1,20 @@
{
"@actions/toolcache-python-windows-x64": [
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"@actions/toolcache-python-windows-x86": [
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"@actions/toolcache-ruby-windows-x64": [
"2.4", "2.5", "2.6", "2.7"
],
"@actions/toolcache-pypy-windows-x86": [
"2", "3"
],
"@actions/toolcache-boost-windows-msvc-14.1-x32-x64": [
"1.69"
],
"@actions/toolcache-boost-windows-msvc-14.2-x32-x64": [
"1.72"
]
}

View File

@@ -1,17 +0,0 @@
{
"toolcache-python-windows-x64": [
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"toolcache-python-windows-x86": [
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"toolcache-ruby-windows-x64": [
"2.4", "2.5", "2.6", "2.7"
],
"toolcache-pypy-windows-x86": [
"2", "3"
],
"toolcache-boost-windows-x64": [
"1.69"
]
}