diff options
author | Sam Doran <sdoran@redhat.com> | 2020-12-07 12:36:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 11:36:53 -0600 |
commit | d12e82b94c517953b740395e8082c1ed007bc1d5 (patch) | |
tree | 607eb1a2e966be4d1167f4b50b249fec51043f0f | |
parent | 67108d86791af6b1d02d046a3335197a9062177e (diff) | |
download | ansible-d12e82b94c517953b740395e8082c1ed007bc1d5.tar.gz |
[stable-2.9] ansible-test - skip installing PowerShell sanity test reqs if they are already installed (#72423) (#72425)
(cherry picked from commit 809d5fc398)
Co-authored-by: Jordan Borean <jborean93@gmail.com>
-rw-r--r-- | changelogs/fragments/ps-sanity-requirements.yml | 2 | ||||
-rwxr-xr-x | test/lib/ansible_test/_data/requirements/sanity.ps1 | 23 |
2 files changed, 23 insertions, 2 deletions
diff --git a/changelogs/fragments/ps-sanity-requirements.yml b/changelogs/fragments/ps-sanity-requirements.yml new file mode 100644 index 0000000000..682a23f3aa --- /dev/null +++ b/changelogs/fragments/ps-sanity-requirements.yml @@ -0,0 +1,2 @@ +bugfixes: +- ansible-test - Skip installing requirements if they are already installed. diff --git a/test/lib/ansible_test/_data/requirements/sanity.ps1 b/test/lib/ansible_test/_data/requirements/sanity.ps1 index 53d14a3418..7a0abb59a3 100755 --- a/test/lib/ansible_test/_data/requirements/sanity.ps1 +++ b/test/lib/ansible_test/_data/requirements/sanity.ps1 @@ -4,8 +4,27 @@ Set-StrictMode -Version 2.0 $ErrorActionPreference = "Stop" +Function Install-PSModule { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [String] + $Name, + + [Parameter(Mandatory=$true)] + [Version] + $RequiredVersion + ) + + # In case PSGallery is down we check if the module is already installed. + $installedModule = Get-Module -Name $Name -ListAvailable | Where-Object Version -eq $RequiredVersion + if (-not $installedModule) { + Install-Module -Name $Name -RequiredVersion $RequiredVersion -Scope CurrentUser + } +} + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.18.0 -Scope CurrentUser +Install-PSModule -Name PSScriptAnalyzer -RequiredVersion 1.18.0 # Installed the PSCustomUseLiteralPath rule -Install-Module -Name PSSA-PSCustomUseLiteralPath -RequiredVersion 0.1.1 -Scope CurrentUser +Install-PSModule -Name PSSA-PSCustomUseLiteralPath -RequiredVersion 0.1.1 |