2020-10-02 15:48:58 +02:00
|
|
|
$Global:ProgressPreference = 'SilentlyContinue'
|
2022-06-15 10:50:22 +02:00
|
|
|
$ErrorActionPreference = 'Stop'
|
2020-10-02 15:48:58 +02:00
|
|
|
|
2022-06-14 09:30:07 +02:00
|
|
|
function Invoke-ShowEnv {
|
2020-10-02 15:48:58 +02:00
|
|
|
[CmdletBinding()]
|
2022-06-15 10:50:22 +02:00
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
|
|
|
'PSProvideCommentHelp',
|
|
|
|
'',
|
|
|
|
Justification = 'internal function'
|
|
|
|
)]
|
2022-06-14 09:30:07 +02:00
|
|
|
param ()
|
2020-10-02 15:48:58 +02:00
|
|
|
|
|
|
|
process {
|
|
|
|
Get-ChildItem -Path 'Env:' | Format-Table | Out-String
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 09:30:07 +02:00
|
|
|
function Invoke-InstallDependencies {
|
2020-10-02 15:48:58 +02:00
|
|
|
[CmdletBinding()]
|
2022-06-15 10:50:22 +02:00
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
|
|
|
'PSProvideCommentHelp',
|
|
|
|
'',
|
|
|
|
Justification = 'internal function'
|
|
|
|
)]
|
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
|
|
|
'PSUseSingularNouns',
|
|
|
|
'',
|
|
|
|
Justification = 'internal function'
|
|
|
|
)]
|
2022-06-14 09:30:07 +02:00
|
|
|
param ()
|
2020-10-02 15:48:58 +02:00
|
|
|
|
|
|
|
process {
|
2022-06-27 16:26:45 +02:00
|
|
|
$ErrorActionPreference = 'Stop'
|
2020-10-02 15:48:58 +02:00
|
|
|
try {
|
2022-06-27 16:26:45 +02:00
|
|
|
$ParamsPSScript = @{
|
|
|
|
Name = 'PSScriptAnalyzer'
|
|
|
|
Scope = 'CurrentUser'
|
|
|
|
RequiredVersion = '1.20.0'
|
|
|
|
Force = $true
|
|
|
|
SkipPublisherCheck = $true
|
|
|
|
AllowClobber = $true
|
|
|
|
Verbose = $VerbosePreference
|
|
|
|
}
|
|
|
|
Install-Module @ParamsPSScript
|
|
|
|
|
|
|
|
$ParamsPester = @{
|
|
|
|
Name = 'Pester'
|
|
|
|
Scope = 'CurrentUser'
|
|
|
|
RequiredVersion = '5.3.3'
|
|
|
|
Force = $true
|
|
|
|
SkipPublisherCheck = $true
|
|
|
|
AllowClobber = $true
|
|
|
|
Verbose = $VerbosePreference
|
|
|
|
}
|
|
|
|
Install-Module @ParamsPester
|
|
|
|
|
|
|
|
$ParamsPosh = @{
|
|
|
|
Name = 'posh-git'
|
|
|
|
Scope = 'CurrentUser'
|
|
|
|
RequiredVersion = '1.1.0'
|
|
|
|
Force = $true
|
|
|
|
SkipPublisherCheck = $true
|
|
|
|
AllowClobber = $true
|
|
|
|
Verbose = $VerbosePreference
|
|
|
|
#ErrorAction = 'Stop'
|
|
|
|
}
|
|
|
|
Install-Module @ParamsPosh
|
2020-10-02 15:48:58 +02:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$ExceParams = @{
|
|
|
|
Exception = [System.Exception]::new(
|
|
|
|
'Could not install required build dependencies!',
|
|
|
|
$PSItem.Exception
|
|
|
|
)
|
|
|
|
ErrorAction = 'Stop'
|
|
|
|
}
|
|
|
|
Write-Error @ExceParams
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 09:30:07 +02:00
|
|
|
function Invoke-Linter {
|
2020-10-02 15:48:58 +02:00
|
|
|
[CmdletBinding()]
|
2022-06-15 10:50:22 +02:00
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
|
|
|
'PSProvideCommentHelp',
|
|
|
|
'',
|
|
|
|
Justification = 'internal function'
|
|
|
|
)]
|
2022-06-14 09:30:07 +02:00
|
|
|
param ()
|
2020-10-02 15:48:58 +02:00
|
|
|
|
|
|
|
process {
|
2022-06-15 10:50:22 +02:00
|
|
|
Import-Module -Name PSScriptAnalyzer
|
|
|
|
$AnalyzerSettings = @{
|
|
|
|
Path = './src/'
|
|
|
|
Recurse = $true
|
|
|
|
Settings = './tools/PSScriptAnalyzerSettings.psd1'
|
|
|
|
ReportSummary = $true
|
|
|
|
}
|
|
|
|
Invoke-ScriptAnalyzer @AnalyzerSettings
|
2020-10-02 15:48:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 10:50:22 +02:00
|
|
|
function Invoke-UnitTest {
|
2020-10-02 15:48:58 +02:00
|
|
|
[CmdletBinding()]
|
2022-06-15 10:50:22 +02:00
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
|
|
|
'PSProvideCommentHelp',
|
|
|
|
'',
|
|
|
|
Justification = 'internal function'
|
|
|
|
)]
|
2020-10-02 15:48:58 +02:00
|
|
|
|
2022-06-15 10:50:22 +02:00
|
|
|
param (
|
|
|
|
[Parameter( Mandatory = $false )]
|
|
|
|
[ValidateSet('JaCoCo', 'CoverageGutters')]
|
|
|
|
[string]$CoverageFormat = 'JaCoCo',
|
2020-10-02 15:48:58 +02:00
|
|
|
|
2022-06-15 10:50:22 +02:00
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[ValidateSet('None', 'Normal', 'Detailed', 'Diagnostic')]
|
|
|
|
[string]$Verbosity = 'Normal',
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[switch]$PassThru,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[string[]]$Tag,
|
2020-10-02 15:48:58 +02:00
|
|
|
|
2022-06-15 10:50:22 +02:00
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[string[]]$ExcludeTag
|
|
|
|
)
|
2020-10-02 15:48:58 +02:00
|
|
|
|
2022-06-15 10:50:22 +02:00
|
|
|
process {
|
|
|
|
Write-Verbose -Message '===== Running Pester =====' -Verbose:$VerbosePreference
|
|
|
|
$PesterConf = New-PesterConfiguration
|
|
|
|
$PesterConf.Run.Path = (Resolve-Path -Path './src').Path
|
|
|
|
$PesterConf.Run.Exit = $false
|
|
|
|
$PesterConf.Run.PassThru = $true
|
|
|
|
$PesterConf.CodeCoverage.Enabled = $true
|
|
|
|
$PesterConf.CodeCoverage.OutputFormat = $CoverageFormat
|
|
|
|
$PesterConf.TestResult.Enabled = $true
|
|
|
|
$CovFiles = Get-ChildItem -Path "./src/*.ps1" -Recurse | Where-Object {
|
|
|
|
$_.BaseName -notmatch '.Tests'
|
|
|
|
} | Select-Object -ExpandProperty 'FullName'
|
|
|
|
$PesterConf.CodeCoverage.Path = $CovFiles
|
|
|
|
$PesterConf.Output.Verbosity = $Verbosity
|
|
|
|
# Set Tags if given
|
|
|
|
if ($Tag) {
|
|
|
|
$PesterConf.Filter.Tag = $Tag
|
|
|
|
}
|
|
|
|
if ($ExcludeTag) {
|
|
|
|
$PesterConf.Filter.ExcludeTag = $ExcludeTag
|
|
|
|
}
|
|
|
|
$TestResults = Invoke-Pester -Configuration $PesterConf -ErrorAction 'Stop'
|
|
|
|
if ($PassThru.IsPresent) {
|
|
|
|
Write-Output -InputObject $TestResults
|
2020-10-02 15:48:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|