Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ If you specify `CodeCoverage_Enabled: true` here, it will enable coverage even i

1. **Prerequisite Setup**
- Installs required PowerShell modules if they're not present.
- Pester is locked to the `6.x` major version (`[6.0.0,7.0.0)`), so a future major release cannot be adopted silently.
- Imports the modules so the testing framework is ready to use.
Comment thread
MariusStorhaug marked this conversation as resolved.
2. **Loading Inputs and Configuration**
- Loads a default Pester configuration.
Expand Down
18 changes: 16 additions & 2 deletions src/Helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,11 @@ function Install-PSResourceWithRetry {
)]
[string] $Name,

# Version of the module to install. Accepts an exact version or a NuGet version range,
# e.g. '[6.0.0,7.0.0)' to lock to the 6.x major version. Defaults to the latest version.
[Parameter()]
[string] $Version,

# Number of times to retry installation, default is 5
[Parameter()]
[int] $RetryCount = 5,
Expand All @@ -1308,10 +1313,19 @@ function Install-PSResourceWithRetry {
)

process {
Write-Output "Installing module: $Name"
$installParams = @{
Name = $Name
Repository = 'PSGallery'
TrustRepository = $true
WarningAction = 'SilentlyContinue'
}
if (-not [string]::IsNullOrWhiteSpace($Version)) {
$installParams['Version'] = $Version
}
Comment on lines +1316 to +1324
Write-Output "Installing module: $Name $Version".Trim()
for ($i = 0; $i -lt $RetryCount; $i++) {
try {
Install-PSResource -Name $Name -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery
Install-PSResource @installParams
break
} catch {
Write-Warning "Installation of $Name failed with error: $_"
Expand Down
7 changes: 5 additions & 2 deletions src/exec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ $PSStyle.OutputRendering = 'Ansi'

'::group::Exec - Setup prerequisites'
Import-Module "$PSScriptRoot/Helpers.psm1"
'Pester' | Install-PSResourceWithRetry
# Lock Pester to the 6.x major version so a future major release cannot be adopted silently.
Install-PSResourceWithRetry -Name 'Pester' -Version '[6.0.0,7.0.0)'
'::endgroup::'

'::group::Exec - Get test kit versions'
Expand Down Expand Up @@ -59,7 +60,9 @@ $testResults = Invoke-Pester -Configuration $configuration
$PSStyle.OutputRendering = 'Ansi'

'::group::Eval - Setup prerequisites'
'Pester', 'Hashtable', 'TimeSpan', 'Markdown' | Install-PSResourceWithRetry
# Lock Pester to the 6.x major version so a future major release cannot be adopted silently.
Install-PSResourceWithRetry -Name 'Pester' -Version '[6.0.0,7.0.0)'
'Hashtable', 'TimeSpan', 'Markdown' | Install-PSResourceWithRetry
'::endgroup::'

'::group::Eval - Get test kit versions'
Expand Down
4 changes: 3 additions & 1 deletion src/init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ param()

LogGroup 'Init - Setup prerequisites' {
Import-Module "$PSScriptRoot/Helpers.psm1"
'Pester', 'Hashtable', 'TimeSpan', 'Markdown' | Install-PSResourceWithRetry
# Lock Pester to the 6.x major version so a future major release cannot be adopted silently.
Install-PSResourceWithRetry -Name 'Pester' -Version '[6.0.0,7.0.0)'
Comment on lines +6 to +7
'Hashtable', 'TimeSpan', 'Markdown' | Install-PSResourceWithRetry
Comment thread
MariusStorhaug marked this conversation as resolved.
}

LogGroup 'Init - Get test kit versions' {
Expand Down
Loading