From 04cd29039bf6d0efc7ffd23696ed508820e30d28 Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Mon, 4 Apr 2022 13:12:16 -0700 Subject: [PATCH] Vcpkg Binary Cache Cleanup (#3482) * Expiration time, eliminate AzureRm warning, condition on Set-VcpkgWriteModeCache * Attempt uninstalling AzureRM and installing Az.Storage * Import PSModule-Helpers.ps1 * Unsintall-AzureRm if the function exists * Get-Command * Uninstall-Module Azure.Storage * Log * quotes * Get-Command some more * Format list * Alias fun * Naming * show PSModulePath * Attempt to handle module double backslash * do not observe * do not observe for real * Spelling * Empty commit to re-trigger CI with a full matrix --- eng/pipelines/templates/steps/vcpkg.yml | 2 +- eng/scripts/Set-VcpkgWriteModeCache.ps1 | 28 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/eng/pipelines/templates/steps/vcpkg.yml b/eng/pipelines/templates/steps/vcpkg.yml index 34e1dafb7..687bac23b 100644 --- a/eng/pipelines/templates/steps/vcpkg.yml +++ b/eng/pipelines/templates/steps/vcpkg.yml @@ -21,7 +21,7 @@ steps: filePath: eng/scripts/Set-VcpkgWriteModeCache.ps1 arguments: -StorageAccountKey '$(cpp-vcpkg-cache-storage-key)' displayName: Set Vcpkg Write-mode Cache - condition: eq(variables['System.TeamProject'], 'internal') + condition: and(succeeded(), eq(variables['System.TeamProject'], 'internal')) - task: PowerShell@2 inputs: diff --git a/eng/scripts/Set-VcpkgWriteModeCache.ps1 b/eng/scripts/Set-VcpkgWriteModeCache.ps1 index bf599c8bf..345d0edb2 100644 --- a/eng/scripts/Set-VcpkgWriteModeCache.ps1 +++ b/eng/scripts/Set-VcpkgWriteModeCache.ps1 @@ -1,7 +1,30 @@ param( [string] $StorageAccountKey ) -Install-Module "Az.Storage" -AllowClobber -Force + + +."$PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1" + +Write-Host "`$env:PSModulePath = $($env:PSModulePath)" + +# Work around double backslash +if ($IsWindows) { + $hostedAgentModulePath = $env:SystemDrive + "\\Modules" + $moduleSeperator = ";" +} else { + $hostedAgentModulePath = "/usr/share" + $moduleSeperator = ":" +} +$modulePaths = $env:PSModulePath -split $moduleSeperator +$modulePaths = $modulePaths.Where({ !$_.StartsWith($hostedAgentModulePath) }) +$AzModuleCachePath = (Get-ChildItem "$hostedAgentModulePath/az_*" -Attributes Directory) -join $moduleSeperator +if ($AzModuleCachePath -and $env.PSModulePath -notcontains $AzModuleCachePath) { + $modulePaths += $AzModuleCachePath +} + +$env:PSModulePath = $modulePaths -join $moduleSeperator + +Install-ModuleIfNotInstalled "Az.Storage" "4.3.0" | Import-Module $ctx = New-AzStorageContext ` -StorageAccountName 'cppvcpkgcache' ` @@ -10,7 +33,8 @@ $token = New-AzStorageAccountSASToken ` -Service Blob ` -ResourceType Object ` -Permission "rwc" ` - -Context $ctx + -Context $ctx ` + -ExpiryTime (Get-Date).AddDays(1) $vcpkgBinarySourceSas = $token.Substring(1) Write-Host "Setting vcpkg binary cache to read and write"