Debian Codegraph @

test/lib/ansible_test/_data/requirements/sanity.pslint.ps1

raw
1 param (
2 [Switch]
3 $IsContainer
4 )
5
6 #Requires -Version 7
7
8 Set-StrictMode -Version 2.0
9 $ErrorActionPreference = "Stop"
10 $ProgressPreference = 'SilentlyContinue'
11
12 Function Install-PSModule {
13 [CmdletBinding()]
14 param(
15 [Parameter(Mandatory = $true)]
16 [String]
17 $Name,
18
19 [Parameter(Mandatory = $true)]
20 [Version]
21 $RequiredVersion
22 )
23
24 # In case PSGallery is down we check if the module is already installed.
25 $installedModule = Get-Module -Name $Name -ListAvailable | Where-Object Version -eq $RequiredVersion
26 if (-not $installedModule) {
27 Install-Module -Name $Name -RequiredVersion $RequiredVersion -Scope CurrentUser
28 }
29 }
30
31 # Versions changes should be made first in ansible-test which is then synced to
32 # the default-test-container over time
33 Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
34 Install-PSModule -Name PSScriptAnalyzer -RequiredVersion 1.21.0
35
36 if ($IsContainer) {
37 # PSScriptAnalyzer contain lots of json files for the UseCompatibleCommands check. We don't use this rule so by
38 # removing the contents we can save 200MB in the docker image (or more in the future).
39 # https://github.com/PowerShell/PSScriptAnalyzer/blob/master/docs/Rules/UseCompatibleCommands.md
40 $pssaPath = (Get-Module -ListAvailable -Name PSScriptAnalyzer).ModuleBase
41 $compatPath = Join-Path -Path $pssaPath -ChildPath compatibility_profiles -AdditionalChildPath '*'
42 Remove-Item -Path $compatPath -Recurse -Force
43 }
44
45 # Installed the PSCustomUseLiteralPath rule
46 Install-PSModule -Name PSSA-PSCustomUseLiteralPath -RequiredVersion 0.1.1