From b72891f13969cf30bd0ca1111b0e8898ad09857c Mon Sep 17 00:00:00 2001 From: David Dalcino Date: Tue, 7 Dec 2021 12:41:17 -0800 Subject: [PATCH] cache powershell modules This change saves PowerShell modules used in the Azure Pipelines to a cache, and loads them when required. This is intended to prevent random failures when the PowerShell Gallery fails to provide the requested modules. These failures occur at random, possibly as a result of a backpressure mechanism. This change will also speed up all Windows Azure Pipelines jobs, since downloads from the PowerShell Gallery will no longer be necessary. --- azure-pipelines.yml | 4 ++++ ci/steps.yml | 44 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 21d8a73..2dc108e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,6 +46,10 @@ jobs: vmImage: 'windows-2019' strategy: matrix: $[ dependencies.MatricesGenerator.outputs['mtrx.windows'] ] + variables: + MODULES_FOLDER: '$(System.DefaultWorkingDirectory)\CachedPowershellModules' + startYear: $[format('{0:yyyy}', pipeline.startTime)] + startMonth: $[format('{0:MM}', pipeline.startTime)] steps: - template: ci/steps.yml diff --git a/ci/steps.yml b/ci/steps.yml index 1b43472..bc85ab1 100644 --- a/ci/steps.yml +++ b/ci/steps.yml @@ -175,13 +175,35 @@ steps: displayName: Build accelbubble example application to test for android ##---------------------------------------------------- - # determine Windows build system + # Cache Powershell Modules in $MODULES_FOLDER + - task: Cache@2 + inputs: + key: '"pwsh modules" | "$(startYear)" | "$(startMonth)"' + restorekeys: | + "pwsh modules" | "$(startYear)" + "pwsh modules" + path: $(MODULES_FOLDER) + cacheHitVar: PSModules_IsCached + condition: | + and(eq(variables['Agent.OS'], 'Windows_NT'), + eq(variables['SUBCOMMAND'], 'install-qt')) + displayName: Cache Powershell Modules + # On cache miss: Download Powershell Modules to $MODULES_FOLDER - powershell: | Install-PackageProvider NuGet -Force Import-PackageProvider NuGet -Force Set-PSRepository -Name PSGallery -InstallationPolicy Trusted - Install-Module Pscx -AllowClobber -AllowPrerelease - Install-Module VSSetup -Scope CurrentUser + md -p $(MODULES_FOLDER) # mkdir + Save-Module -Name Pscx -AllowPrerelease -Path $(MODULES_FOLDER) + condition: | + and(eq(variables['Agent.OS'], 'Windows_NT'), + eq(variables['SUBCOMMAND'], 'install-qt'), + ne(variables.PSModules_IsCached, 'true')) + displayName: Download Powershell Modules for Windows on cache miss + + ##---------------------------------------------------- + # determine Windows build system + - powershell: | if ('$(ARCH)' -like '*msvc*') { Write-Host '##vso[task.setvariable variable=TOOLCHAIN]MSVC' } @@ -202,7 +224,9 @@ steps: } cd $(WIN_QT_BINDIR) unzip $(Build.SourcesDirectory)\ci\jom_1_1_3.zip - condition: and(eq( variables['Agent.OS'], 'Windows_NT'), eq(variables['SUBCOMMAND'], 'install-qt')) + condition: | + and(eq(variables['Agent.OS'], 'Windows_NT'), + eq(variables['SUBCOMMAND'], 'install-qt')) displayName: Detect toolchain for Windows and update PATH # When no modules @@ -217,6 +241,12 @@ steps: displayName: Build test with qmake for Linux and macOS w/o extra module - powershell: | if ( $env:TOOLCHAIN -eq 'MSVC' ) { + # Load modules from cache + $Env:PSModulePath = '$(MODULES_FOLDER)', $Env:PSModulePath -join [System.IO.Path]::PathSeparator + Write-Host $Env:PSModulePath + Import-Module "Pscx" + Import-Module "VSSetup" + Import-VisualStudioVars -VisualStudioVersion $(VSVER) -Architecture $(ARCHITECTURE) $env:Path += ";$(WIN_QT_BINDIR)" mkdir $(Build.BinariesDirectory)\tests @@ -244,6 +274,12 @@ steps: condition: and(eq( variables['Agent.OS'], 'Windows_NT'), eq(variables['MODULE'], ''), eq(variables['SUBCOMMAND'], 'install-qt')) displayName: build test with qmake w/o extra module - powershell: | + # Load modules from cache + $Env:PSModulePath = '$(MODULES_FOLDER)', $Env:PSModulePath -join [System.IO.Path]::PathSeparator + Write-Host $Env:PSModulePath + Import-Module "Pscx" + Import-Module "VSSetup" + Import-VisualStudioVars -VisualStudioVersion $(VSVER) -Architecture $(ARCHITECTURE) $env:Path += ";$(WIN_QT_BINDIR)" echo Add Qt to PATH: $env:PATH