From c293172a732a094b4087d3763a399fd38f000393 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 14:46:33 +0100 Subject: [PATCH 001/172] =?UTF-8?q?=F0=9F=A9=B9=20[Add]:=20Introduce=20new?= =?UTF-8?q?=20test=20configuration=20and=20container=20scripts=20for=20mod?= =?UTF-8?q?ule=20and=20source=20code=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 73 +++-------- scripts/helpers/Test-PSModule.ps1 | 122 +----------------- scripts/tests/Module/Module.Configuration.ps1 | 21 +++ .../Module/PSModule/Module.Container.ps1 | 8 ++ .../{ => Module}/PSModule/Module.Tests.ps1 | 0 .../PSScriptAnalyzer.Container.ps1 | 9 ++ .../PSScriptAnalyzer.Settings.psd1} | 1 - .../PSScriptAnalyzer.Tests.ps1 | 0 scripts/tests/PSModule/Common.Tests.ps1 | 42 ------ .../PSModule/SourceCode.Container.ps1 | 9 ++ .../PSModule/SourceCode.Tests.ps1 | 0 .../PSScriptAnalyzer.Container.ps1 | 9 ++ .../PSScriptAnalyzer.Settings.psd1} | 13 +- .../PSScriptAnalyzer.Tests.ps1 | 55 ++++++++ .../SourceCode/SourceCode.Configuration.ps1 | 21 +++ 15 files changed, 163 insertions(+), 220 deletions(-) create mode 100644 scripts/tests/Module/Module.Configuration.ps1 create mode 100644 scripts/tests/Module/PSModule/Module.Container.ps1 rename scripts/tests/{ => Module}/PSModule/Module.Tests.ps1 (100%) create mode 100644 scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 rename scripts/tests/{PSScriptAnalyzer/Settings.SourceCode.psd1 => Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1} (98%) rename scripts/tests/{ => Module}/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 (100%) delete mode 100644 scripts/tests/PSModule/Common.Tests.ps1 create mode 100644 scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 rename scripts/tests/{ => SourceCode}/PSModule/SourceCode.Tests.ps1 (100%) create mode 100644 scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 rename scripts/tests/{PSScriptAnalyzer/Settings.Module.psd1 => SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1} (67%) create mode 100644 scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 create mode 100644 scripts/tests/SourceCode/SourceCode.Configuration.ps1 diff --git a/action.yml b/action.yml index 03e4bdd5..bb1d7ca0 100644 --- a/action.yml +++ b/action.yml @@ -19,29 +19,21 @@ inputs: description: The path to the tests to run. required: false default: tests - StackTraceVerbosity: - description: "Verbosity level of the stack trace. Allowed values: 'None', 'FirstLine', 'Filtered', 'Full'." - required: false - default: 'Filtered' - Verbosity: - description: "Verbosity level of the test output. Allowed values: 'None', 'Normal', 'Detailed', 'Diagnostic'." - required: false - default: 'Detailed' - Debug: - description: Enable debug output. - required: false - default: 'false' - Verbose: - description: Enable verbose output. - required: false - default: 'false' - Version: - description: Specifies the version of the GitHub module to be installed. The value must be an exact version. - required: false - Prerelease: - description: Allow prerelease versions if available. - required: false - default: 'false' + # Debug: + # description: Enable debug output. + # required: false + # default: 'false' + # Verbose: + # description: Enable verbose output. + # required: false + # default: 'false' + # Version: + # description: Specifies the version of the GitHub module to be installed. The value must be an exact version. + # required: false + # Prerelease: + # description: Allow prerelease versions if available. + # required: false + # default: 'false' outputs: passed: @@ -51,36 +43,9 @@ outputs: runs: using: composite steps: - - name: Run Test-PSModule - uses: PSModule/GitHub-Script@v1 + - name: Invoke-Pester + uses: PSModule/Invoke-Pester@v1 id: test - env: - GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} - GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }} - GITHUB_ACTION_INPUT_TestType: ${{ inputs.TestType }} - GITHUB_ACTION_INPUT_TestsPath: ${{ inputs.TestsPath }} - GITHUB_ACTION_INPUT_StackTraceVerbosity: ${{ inputs.StackTraceVerbosity }} - GITHUB_ACTION_INPUT_Verbosity: ${{ inputs.Verbosity }} - with: - Debug: ${{ inputs.Debug }} - Prerelease: ${{ inputs.Prerelease }} - Verbose: ${{ inputs.Verbose }} - Version: ${{ inputs.Version }} - ShowOutput: true - Script: | - # Test-PSModule - ${{ github.action_path }}/scripts/main.ps1 - - - name: Upload test results - uses: actions/upload-artifact@v4 - if: ${{ inputs.TestType == 'Module' && (success() || failure()) }} - with: - name: ${{ runner.os }}-Test-Report - path: ${{ github.workspace }}/outputs/Test-Report.xml - - - name: Upload code coverage report - uses: actions/upload-artifact@v4 - if: ${{ inputs.TestType == 'Module' && (success() || failure()) }} with: - name: ${{ runner.os }}-CodeCoverage-Report - path: ${{ github.workspace }}/outputs/CodeCoverage-Report.xml + Path: ${{ inputs.TestsPath }}/${{ inputs.TestType }} + Run_Path: ${{ inputs.Path }}/${{ inputs.Name }} diff --git a/scripts/helpers/Test-PSModule.ps1 b/scripts/helpers/Test-PSModule.ps1 index bed29ef6..81ce1524 100644 --- a/scripts/helpers/Test-PSModule.ps1 +++ b/scripts/helpers/Test-PSModule.ps1 @@ -18,24 +18,9 @@ [Parameter(Mandatory)] [string] $Path, - # Run module tests. - [Parameter()] - [ValidateSet('SourceCode', 'Module')] - [string] $TestType = 'SourceCode', - # Path to the folder where the tests are located. [Parameter()] - [string] $TestsPath = 'tests', - - # Verbosity level of the stack trace. - [Parameter()] - [ValidateSet('None', 'FirstLine', 'Filtered', 'Full')] - [string] $StackTraceVerbosity = 'Filtered', - - # Verbosity level of the test output. - [Parameter()] - [ValidateSet('None', 'Normal', 'Detailed', 'Diagnostic')] - [string] $Verbosity = 'Detailed' + [string] $TestsPath = 'tests' ) $moduleName = Split-Path -Path $Path -Leaf @@ -43,79 +28,6 @@ $testModule = $TestType -eq 'Module' $moduleTestsPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $TestsPath - LogGroup 'Get test kit versions' { - $PSSAModule = Get-PSResource -Name PSScriptAnalyzer -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1 - $pesterModule = Get-PSResource -Name Pester -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1 - - [PSCustomObject]@{ - PowerShell = $PSVersionTable.PSVersion.ToString() - Pester = $pesterModule.version - PSScriptAnalyzer = $PSSAModule.version - } | Format-List - } - - LogGroup 'Add test - Common - PSScriptAnalyzer' { - $containers = @() - $PSSATestsPath = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSScriptAnalyzer' - $settingsFileName = if ($testModule) { 'Settings.Module.psd1' } else { 'Settings.SourceCode.psd1' } - $settingsFilePath = Join-Path -Path $PSSATestsPath -ChildPath $settingsFileName - $containerParams = @{ - Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1' - Data = @{ - Path = $Path - SettingsFilePath = $settingsFilePath - Debug = $false - Verbose = $false - } - } - Write-Host ($containerParams | ConvertTo-Json) - $containers += New-PesterContainer @containerParams - } - - LogGroup 'Add test - Common - PSModule' { - $containerParams = @{ - Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Common.Tests.ps1' - Data = @{ - Path = $Path - Debug = $false - Verbose = $false - } - } - Write-Host ($containerParams | ConvertTo-Json) - $containers += New-PesterContainer @containerParams - } - - if ($testModule) { - LogGroup 'Add test - Module - PSModule' { - $containerParams = @{ - Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Module.Tests.ps1' - Data = @{ - Path = $Path - Debug = $false - Verbose = $false - } - } - Write-Host ($containerParams | ConvertTo-Json) - $containers += New-PesterContainer @containerParams - } - } - - if ($testSourceCode) { - LogGroup 'Add test - SourceCode - PSModule' { - $containerParams = @{ - Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\SourceCode.Tests.ps1' - Data = @{ - Path = $Path - TestsPath = $moduleTestsPath - Debug = $false - Verbose = $false - } - } - Write-Host ($containerParams | ConvertTo-Json) - $containers += New-PesterContainer @containerParams - } - } - if ($testModule) { if (Test-Path -Path $moduleTestsPath) { LogGroup "Add test - Module - $moduleName" { @@ -146,36 +58,4 @@ } } - LogGroup 'Pester config' { - $pesterParams = @{ - Configuration = @{ - Run = @{ - Path = $Path - Container = $containers - PassThru = $true - } - TestResult = @{ - Enabled = $testModule - OutputFormat = 'NUnitXml' - OutputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'outputs\Test-Report.xml' - TestSuiteName = 'Unit tests' - } - CodeCoverage = @{ - Enabled = $testModule - OutputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'outputs\CodeCoverage-Report.xml' - OutputFormat = 'JaCoCo' - OutputEncoding = 'UTF8' - CoveragePercentTarget = 75 - } - Output = @{ - CIFormat = 'Auto' - StackTraceVerbosity = $StackTraceVerbosity - Verbosity = $Verbosity - } - } - } - Write-Host ($pesterParams | ConvertTo-Json -Depth 5 -WarningAction SilentlyContinue) - } - - Invoke-Pester @pesterParams } diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 new file mode 100644 index 00000000..1d0f798d --- /dev/null +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -0,0 +1,21 @@ +@{ + Configuration = @{ + Run = @{ + Path = $Path + Container = $containers + PassThru = $true + } + TestResult = @{ + Enabled = $true + } + CodeCoverage = @{ + Enabled = $true + OutputFormat = 'JaCoCo' + OutputEncoding = 'UTF8' + CoveragePercentTarget = 75 + } + Output = @{ + Verbosity = 'Detailed' + } + } +} diff --git a/scripts/tests/Module/PSModule/Module.Container.ps1 b/scripts/tests/Module/PSModule/Module.Container.ps1 new file mode 100644 index 00000000..650f1ce4 --- /dev/null +++ b/scripts/tests/Module/PSModule/Module.Container.ps1 @@ -0,0 +1,8 @@ +@{ + Path = Join-Path -Path $PSScriptRoot -ChildPath 'Module.Tests.ps1' + Data = @{ + Path = $Path + Debug = $false + Verbose = $false + } +} diff --git a/scripts/tests/PSModule/Module.Tests.ps1 b/scripts/tests/Module/PSModule/Module.Tests.ps1 similarity index 100% rename from scripts/tests/PSModule/Module.Tests.ps1 rename to scripts/tests/Module/PSModule/Module.Tests.ps1 diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 new file mode 100644 index 00000000..55725f0d --- /dev/null +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -0,0 +1,9 @@ +@{ + Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1' + Data = @{ + Path = $Path + SettingsFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'PSScriptAnalyzer.Settings.psd1' + Debug = $false + Verbose = $false + } +} diff --git a/scripts/tests/PSScriptAnalyzer/Settings.SourceCode.psd1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 similarity index 98% rename from scripts/tests/PSScriptAnalyzer/Settings.SourceCode.psd1 rename to scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 index e9081f9a..09cc3d0c 100644 --- a/scripts/tests/PSScriptAnalyzer/Settings.SourceCode.psd1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 @@ -51,7 +51,6 @@ } ExcludeRules = @( 'PSMissingModuleManifestField', # This rule is not applicable until the module is built. - 'PSAvoidUsingCmdletAliases', 'PSUseToExportFieldsInManifest' ) } diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 similarity index 100% rename from scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 rename to scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 diff --git a/scripts/tests/PSModule/Common.Tests.ps1 b/scripts/tests/PSModule/Common.Tests.ps1 deleted file mode 100644 index 843e8b17..00000000 --- a/scripts/tests/PSModule/Common.Tests.ps1 +++ /dev/null @@ -1,42 +0,0 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSReviewUnusedParameter', 'Path', - Justification = 'Path is used to specify the path to the module to test.' -)] -[CmdLetBinding()] -Param( - [Parameter(Mandatory)] - [string] $Path -) - -# These tests are for the whole module and its parts. The scope of these tests are on the src folder and the specific module folder within it. -Describe 'Script files' { - Context 'Module design tests' { - # It 'Script file should only contain one function or filter' {} - # It 'All script files have tests' {} # Look for the folder name in tests called the same as section/folder name of functions - } - - Describe 'Function/filter design' { - # It 'comment based doc block start is indented with 4 spaces' {} - # It 'comment based doc is indented with 8 spaces' {} - # It 'has synopsis for all functions' {} - # It 'has description for all functions' {} - # It 'has examples for all functions' {} - # It 'has output documentation for all functions' {} - # It 'has [CmdletBinding()] attribute' {} - # It 'boolean parameters in CmdletBinding() attribute are written without assignments' {} - # I.e. [CmdletBinding(ShouldProcess)] instead of [CmdletBinding(ShouldProcess = $true)] - # It 'has [OutputType()] attribute' {} - # It 'has verb 'New','Set','Disable','Enable' etc. and uses "ShoudProcess" in the [CmdletBinding()] attribute' {} - } - - Describe 'Parameter design' { - # It 'has parameter description for all functions' {} - # It 'has parameter validation for all functions' {} - # It 'parameters have [Parameters()] attribute' {} - # It 'boolean parameters to the [Parameter()] attribute are written without assignments' {} - # I.e. [Parameter(Mandatory)] instead of [Parameter(Mandatory = $true)] - # It 'datatype for parameters are written on the same line as the parameter name' {} - # It 'datatype for parameters and parameter name are separated by a single space' {} - # It 'parameters are separated by a blank line' {} - } -} diff --git a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 new file mode 100644 index 00000000..bbb6e9b4 --- /dev/null +++ b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 @@ -0,0 +1,9 @@ +@{ + Path = Join-Path -Path $PSScriptRoot -ChildPath 'SourceCode.Tests.ps1' + Data = @{ + Path = $Path + TestsPath = $moduleTestsPath + Debug = $false + Verbose = $false + } +} diff --git a/scripts/tests/PSModule/SourceCode.Tests.ps1 b/scripts/tests/SourceCode/PSModule/SourceCode.Tests.ps1 similarity index 100% rename from scripts/tests/PSModule/SourceCode.Tests.ps1 rename to scripts/tests/SourceCode/PSModule/SourceCode.Tests.ps1 diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 new file mode 100644 index 00000000..55725f0d --- /dev/null +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -0,0 +1,9 @@ +@{ + Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1' + Data = @{ + Path = $Path + SettingsFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'PSScriptAnalyzer.Settings.psd1' + Debug = $false + Verbose = $false + } +} diff --git a/scripts/tests/PSScriptAnalyzer/Settings.Module.psd1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 similarity index 67% rename from scripts/tests/PSScriptAnalyzer/Settings.Module.psd1 rename to scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 index 7c3a739c..09cc3d0c 100644 --- a/scripts/tests/PSScriptAnalyzer/Settings.Module.psd1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 @@ -37,11 +37,20 @@ Kind = 'space' } PSUseConsistentWhitespace = @{ - Enable = $false + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $true + CheckOpenParen = $true + CheckOperator = $true + CheckPipe = $true + CheckPipeForRedundantWhitespace = $true + CheckSeparator = $true + CheckParameter = $true + IgnoreAssignmentOperatorInsideHashTable = $true } } ExcludeRules = @( - 'PSAvoidUsingCmdletAliases', + 'PSMissingModuleManifestField', # This rule is not applicable until the module is built. 'PSUseToExportFieldsInManifest' ) } diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 new file mode 100644 index 00000000..2a6039b8 --- /dev/null +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -0,0 +1,55 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSReviewUnusedParameter', 'Path', + Justification = 'Path is being used.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSReviewUnusedParameter', 'SettingsFilePath', + Justification = 'SettingsFilePath is being used.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'relativeSettingsFilePath', + Justification = 'relativeSettingsFilePath is being used.' +)] +[CmdLetBinding()] +Param( + [Parameter(Mandatory)] + [string] $Path, + + [Parameter(Mandatory)] + [string] $SettingsFilePath +) + +BeforeDiscovery { + $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() + $ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName + foreach ($ruleObject in $ruleObjects) { + $rules.Add( + [ordered]@{ + RuleName = $ruleObject.RuleName + CommonName = $ruleObject.CommonName + Severity = $ruleObject.Severity + Description = $ruleObject.Description + } + ) + } + Write-Warning "Discovered [$($rules.Count)] rules" + $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/') +} + +Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath]" { + BeforeAll { + $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose:$false + Write-Warning "Found [$($testResults.Count)] issues" + } + + Context 'Severity: <_>' -ForEach 'Error', 'Warning', 'Information' { + It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $_) { + $issues = [Collections.Generic.List[string]]::new() + $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { + $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') + $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) + } + $issues -join '' | Should -BeNullOrEmpty -Because $Description + } + } +} diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 new file mode 100644 index 00000000..1d0f798d --- /dev/null +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -0,0 +1,21 @@ +@{ + Configuration = @{ + Run = @{ + Path = $Path + Container = $containers + PassThru = $true + } + TestResult = @{ + Enabled = $true + } + CodeCoverage = @{ + Enabled = $true + OutputFormat = 'JaCoCo' + OutputEncoding = 'UTF8' + CoveragePercentTarget = 75 + } + Output = @{ + Verbosity = 'Detailed' + } + } +} From 39dc11a3158c441d1f4f2ae9a3694689c4f18699 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 14:52:00 +0100 Subject: [PATCH 002/172] =?UTF-8?q?=F0=9F=A9=B9=20[Enhance]:=20Add=20dynam?= =?UTF-8?q?ic=20test=20path=20resolution=20based=20on=20test=20type=20in?= =?UTF-8?q?=20action.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index bb1d7ca0..4758f36f 100644 --- a/action.yml +++ b/action.yml @@ -43,9 +43,22 @@ outputs: runs: using: composite steps: + - name: Get test paths + uses: PSModule/Github-Script@v1 + id: paths + with: + Script: | + # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. + if (${{ inputs.TestType }} -eq 'Module') { + $path = "${{ inputs.Path }}/${{ inputs.Name }}" + } else { + $path = ${{ inputs.Path }} + } + Set-GitHubOutput -Name Path -Value $path + - name: Invoke-Pester uses: PSModule/Invoke-Pester@v1 id: test with: Path: ${{ inputs.TestsPath }}/${{ inputs.TestType }} - Run_Path: ${{ inputs.Path }}/${{ inputs.Name }} + Run_Path: ${{ fromJson(steps.paths.outputs.result).Path }} From 14eb49690b35df356037ba274058cd7c323ce469 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 14:54:47 +0100 Subject: [PATCH 003/172] =?UTF-8?q?=F0=9F=A9=B9=20[Enhance]:=20Improve=20t?= =?UTF-8?q?est=20path=20resolution=20logic=20in=20action.yml=20to=20use=20?= =?UTF-8?q?environment=20variable=20for=20test=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 4758f36f..1585405d 100644 --- a/action.yml +++ b/action.yml @@ -46,14 +46,20 @@ runs: - name: Get test paths uses: PSModule/Github-Script@v1 id: paths + env: + TestType: ${{ inputs.TestType }} with: Script: | # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. - if (${{ inputs.TestType }} -eq 'Module') { - $path = "${{ inputs.Path }}/${{ inputs.Name }}" - } else { - $path = ${{ inputs.Path }} + $path = switch($env:TestType) { + 'Module' { + Resolve-Path -Path "${{ inputs.Path }}/${{ inputs.Name }}" + } + default { + Resolve-Path -Path '${{ inputs.Path }}' + } } + Set-GitHubOutput -Name Path -Value $path - name: Invoke-Pester From e118976eb440c27e69de383877e584dfb0d48d1a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 14:59:58 +0100 Subject: [PATCH 004/172] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Add=20error=20h?= =?UTF-8?q?andling=20for=20invalid=20test=20types=20in=20action.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 1585405d..2c22f208 100644 --- a/action.yml +++ b/action.yml @@ -55,9 +55,12 @@ runs: 'Module' { Resolve-Path -Path "${{ inputs.Path }}/${{ inputs.Name }}" } - default { + 'SourceCode' { Resolve-Path -Path '${{ inputs.Path }}' } + default { + throw "Invalid test type: $env:TestType" + } } Set-GitHubOutput -Name Path -Value $path From 284a0c01e1d003aec6ecace5dd6ba52bd72e6c90 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:00:06 +0100 Subject: [PATCH 005/172] =?UTF-8?q?=F0=9F=A9=B9=20[Enhance]:=20Add=20verbo?= =?UTF-8?q?se=20output=20for=20path=20resolution=20and=20improve=20error?= =?UTF-8?q?=20handling=20for=20test=20types=20in=20action.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 2c22f208..a55bd6de 100644 --- a/action.yml +++ b/action.yml @@ -51,19 +51,21 @@ runs: with: Script: | # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. + Write-Host "Test type: $env:TestType" $path = switch($env:TestType) { 'Module' { - Resolve-Path -Path "${{ inputs.Path }}/${{ inputs.Name }}" + '${{ inputs.Path }}/${{ inputs.Name }}' } 'SourceCode' { - Resolve-Path -Path '${{ inputs.Path }}' + '${{ inputs.Path }}' } default { throw "Invalid test type: $env:TestType" } } + Write-Host "Path: $path" - Set-GitHubOutput -Name Path -Value $path + Set-GitHubOutput -Name Path -Value $path -Verbose -Debug - name: Invoke-Pester uses: PSModule/Invoke-Pester@v1 From 5aef70d969954c5a3404fa4f79815132b7e8444f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:05:19 +0100 Subject: [PATCH 006/172] [Enhance]: Add confirmation flag to Set-GitHubOutput for improved output handling in action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a55bd6de..d65a7f94 100644 --- a/action.yml +++ b/action.yml @@ -65,7 +65,7 @@ runs: } Write-Host "Path: $path" - Set-GitHubOutput -Name Path -Value $path -Verbose -Debug + Set-GitHubOutput -Name Path -Value $path -Verbose -Debug -Confirm:$false - name: Invoke-Pester uses: PSModule/Invoke-Pester@v1 From cb1c1a6b7676f9c9879e3e4984e5b16dcd4ba13d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:08:52 +0100 Subject: [PATCH 007/172] =?UTF-8?q?=F0=9F=A9=B9=20[Enhance]:=20Update=20pa?= =?UTF-8?q?th=20resolution=20to=20use=20github.action=5Fpath=20and=20githu?= =?UTF-8?q?b.workspace=20for=20improved=20compatibility=20in=20action.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index d65a7f94..a0174f33 100644 --- a/action.yml +++ b/action.yml @@ -71,5 +71,5 @@ runs: uses: PSModule/Invoke-Pester@v1 id: test with: - Path: ${{ inputs.TestsPath }}/${{ inputs.TestType }} - Run_Path: ${{ fromJson(steps.paths.outputs.result).Path }} + Path: ${{ github.action_path }}/${{ inputs.TestsPath }}/${{ inputs.TestType }} + Run_Path: ${{ github.workspace }}/${{ fromJson(steps.paths.outputs.result).Path }} From 9336588b2da0df5bbfd2c0f2a9b3825920d3d999 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:13:50 +0100 Subject: [PATCH 008/172] [Enhance]: Remove unnecessary flags from Set-GitHubOutput and fix path concatenation in action.yml --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index a0174f33..de80ba9a 100644 --- a/action.yml +++ b/action.yml @@ -65,11 +65,11 @@ runs: } Write-Host "Path: $path" - Set-GitHubOutput -Name Path -Value $path -Verbose -Debug -Confirm:$false + Set-GitHubOutput -Name Path -Value $path - name: Invoke-Pester uses: PSModule/Invoke-Pester@v1 id: test with: - Path: ${{ github.action_path }}/${{ inputs.TestsPath }}/${{ inputs.TestType }} + Path: ${{ github.action_path }}${{ inputs.TestsPath }}/${{ inputs.TestType }} Run_Path: ${{ github.workspace }}/${{ fromJson(steps.paths.outputs.result).Path }} From e29c26436ade32c13556fc479ff81b26477fb649 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:18:13 +0100 Subject: [PATCH 009/172] [Enhance]: Update default TestsPath to 'scripts/tests' and fix path concatenation in action.yml --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index de80ba9a..ae5cf20f 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ inputs: TestsPath: description: The path to the tests to run. required: false - default: tests + default: scripts/tests # Debug: # description: Enable debug output. # required: false @@ -71,5 +71,5 @@ runs: uses: PSModule/Invoke-Pester@v1 id: test with: - Path: ${{ github.action_path }}${{ inputs.TestsPath }}/${{ inputs.TestType }} + Path: ${{ github.action_path }}/${{ inputs.TestsPath }}/${{ inputs.TestType }} Run_Path: ${{ github.workspace }}/${{ fromJson(steps.paths.outputs.result).Path }} From a524f248aa89de44901462681ceded0566a8a5a4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:26:12 +0100 Subject: [PATCH 010/172] [Enhance]: Improve output formatting for test type and path in action.yml; streamline configuration in Module and SourceCode scripts --- action.yml | 6 +++--- scripts/tests/Module/Module.Configuration.ps1 | 15 +++------------ .../SourceCode/SourceCode.Configuration.ps1 | 16 +--------------- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/action.yml b/action.yml index ae5cf20f..2f8f6f86 100644 --- a/action.yml +++ b/action.yml @@ -51,7 +51,7 @@ runs: with: Script: | # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. - Write-Host "Test type: $env:TestType" + Write-Host "Test type: [$env:TestType]" $path = switch($env:TestType) { 'Module' { '${{ inputs.Path }}/${{ inputs.Name }}' @@ -60,10 +60,10 @@ runs: '${{ inputs.Path }}' } default { - throw "Invalid test type: $env:TestType" + throw "Invalid test type: [$env:TestType]" } } - Write-Host "Path: $path" + Write-Host "Path: [$path]" Set-GitHubOutput -Name Path -Value $path diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index 1d0f798d..31c6e351 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,18 +1,9 @@ @{ Configuration = @{ - Run = @{ - Path = $Path - Container = $containers - PassThru = $true - } - TestResult = @{ - Enabled = $true - } CodeCoverage = @{ - Enabled = $true - OutputFormat = 'JaCoCo' - OutputEncoding = 'UTF8' - CoveragePercentTarget = 75 + Enabled = $true + OutputFormat = 'JaCoCo' + OutputEncoding = 'UTF8' } Output = @{ Verbosity = 'Detailed' diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 index 1d0f798d..fdacba22 100644 --- a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -1,20 +1,6 @@ @{ Configuration = @{ - Run = @{ - Path = $Path - Container = $containers - PassThru = $true - } - TestResult = @{ - Enabled = $true - } - CodeCoverage = @{ - Enabled = $true - OutputFormat = 'JaCoCo' - OutputEncoding = 'UTF8' - CoveragePercentTarget = 75 - } - Output = @{ + Output = @{ Verbosity = 'Detailed' } } From 0deea16f6dbf53b98e152e877916e79d7ca95e18 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:32:30 +0100 Subject: [PATCH 011/172] [Enhance]: Update Invoke-Pester action to version 1.1.1-preview for improved functionality in action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2f8f6f86..14bac954 100644 --- a/action.yml +++ b/action.yml @@ -68,7 +68,7 @@ runs: Set-GitHubOutput -Name Path -Value $path - name: Invoke-Pester - uses: PSModule/Invoke-Pester@v1 + uses: PSModule/Invoke-Pester@v1.1.1-preview id: test with: Path: ${{ github.action_path }}/${{ inputs.TestsPath }}/${{ inputs.TestType }} From 83311e0b4d4d92a7211ebdf607a6ec99a1a67fa6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:43:19 +0100 Subject: [PATCH 012/172] [Enhance]: Refactor TestsPath handling and improve path resolution for test execution in action.yml --- action.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index 14bac954..a46abc74 100644 --- a/action.yml +++ b/action.yml @@ -15,10 +15,6 @@ inputs: TestType: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true - TestsPath: - description: The path to the tests to run. - required: false - default: scripts/tests # Debug: # description: Enable debug output. # required: false @@ -47,6 +43,8 @@ runs: uses: PSModule/Github-Script@v1 id: paths env: + Name: ${{ inputs.Name }} + Path: ${{ inputs.Path }} TestType: ${{ inputs.TestType }} with: Script: | @@ -54,10 +52,10 @@ runs: Write-Host "Test type: [$env:TestType]" $path = switch($env:TestType) { 'Module' { - '${{ inputs.Path }}/${{ inputs.Name }}' + Resolve-Path -Path "$env:Path/$env:Name" } 'SourceCode' { - '${{ inputs.Path }}' + Resolve-Path -Path $env:Path } default { throw "Invalid test type: [$env:TestType]" @@ -71,5 +69,5 @@ runs: uses: PSModule/Invoke-Pester@v1.1.1-preview id: test with: - Path: ${{ github.action_path }}/${{ inputs.TestsPath }}/${{ inputs.TestType }} + Path: ${{ github.action_path }}/scripts/tests/${{ inputs.TestType }} Run_Path: ${{ github.workspace }}/${{ fromJson(steps.paths.outputs.result).Path }} From 306f6c5290a71e63cdcb446b07195dde2864aaec Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 15:45:44 +0100 Subject: [PATCH 013/172] Enhance: Expand resolved path output for Module and SourceCode test types in action.yml --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index a46abc74..e845124c 100644 --- a/action.yml +++ b/action.yml @@ -52,10 +52,10 @@ runs: Write-Host "Test type: [$env:TestType]" $path = switch($env:TestType) { 'Module' { - Resolve-Path -Path "$env:Path/$env:Name" + Resolve-Path -Path "$env:Path/$env:Name" | Select-Object -ExpandProperty Path } 'SourceCode' { - Resolve-Path -Path $env:Path + Resolve-Path -Path $env:Path | Select-Object -ExpandProperty Path } default { throw "Invalid test type: [$env:TestType]" From b625e135724374f19524dea98a774563b7757395 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 16:03:57 +0100 Subject: [PATCH 014/172] Refactor: Remove redundant Name parameter and streamline Run_Path in action.yml and workflow configuration --- .github/workflows/Action-Test-Src-Default.yml | 1 - action.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/Action-Test-Src-Default.yml b/.github/workflows/Action-Test-Src-Default.yml index 0fa6911e..52f0b494 100644 --- a/.github/workflows/Action-Test-Src-Default.yml +++ b/.github/workflows/Action-Test-Src-Default.yml @@ -35,7 +35,6 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} with: - Name: PSModuleTest Path: tests/src TestType: SourceCode diff --git a/action.yml b/action.yml index e845124c..1ad59f23 100644 --- a/action.yml +++ b/action.yml @@ -70,4 +70,4 @@ runs: id: test with: Path: ${{ github.action_path }}/scripts/tests/${{ inputs.TestType }} - Run_Path: ${{ github.workspace }}/${{ fromJson(steps.paths.outputs.result).Path }} + Run_Path: ${{ fromJson(steps.paths.outputs.result).Path }} From 70b61b2bfacc07df65d0bfa7319b54df223541c2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 16:20:38 +0100 Subject: [PATCH 015/172] Refactor: Remove unnecessary blank line before setting GitHub output in action.yml --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index 1ad59f23..f4563b83 100644 --- a/action.yml +++ b/action.yml @@ -62,7 +62,6 @@ runs: } } Write-Host "Path: [$path]" - Set-GitHubOutput -Name Path -Value $path - name: Invoke-Pester From 1b47698f33677b2221a38dbb35b2d67a1fa916ad Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 19 Feb 2025 16:24:05 +0100 Subject: [PATCH 016/172] Enhance: Add TestPath resolution and update Invoke-Pester action to use resolved path in action.yml --- action.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f4563b83..9b00a3d9 100644 --- a/action.yml +++ b/action.yml @@ -64,9 +64,13 @@ runs: Write-Host "Path: [$path]" Set-GitHubOutput -Name Path -Value $path + $testPath = Resolve-Path -Path "${{ github.action_path }}/scripts/tests/${{ inputs.TestType }}" | Select-Object -ExpandProperty Path + Write-Host "Test path: [$testPath]" + Set-GitHubOutput -Name TestPath -Value $testPath + - name: Invoke-Pester uses: PSModule/Invoke-Pester@v1.1.1-preview id: test with: - Path: ${{ github.action_path }}/scripts/tests/${{ inputs.TestType }} + Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).Path }} From 4c15dd9ad89204273f7f864c87f3ebc4216f2225 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 10:12:29 +0100 Subject: [PATCH 017/172] Refactor: Remove main.ps1 script as part of codebase cleanup --- scripts/main.ps1 | 66 ------------------------------------------------ 1 file changed, 66 deletions(-) delete mode 100644 scripts/main.ps1 diff --git a/scripts/main.ps1 b/scripts/main.ps1 deleted file mode 100644 index 575a4ef4..00000000 --- a/scripts/main.ps1 +++ /dev/null @@ -1,66 +0,0 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', - Justification = 'Want to just write to the console, not the pipeline.' -)] -[CmdletBinding()] -param() - -$path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') -LogGroup "Loading helper scripts from [$path]" { - Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | ForEach-Object { - Write-Host " - $($_.FullName)" - . $_.FullName - } -} - -LogGroup 'Loading inputs' { - $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name - $codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath "$env:GITHUB_ACTION_INPUT_Path\$moduleName" - if (-not (Test-Path -Path $codeToTest)) { - $codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path - } - if (-not (Test-Path -Path $codeToTest)) { - throw "Path [$codeToTest] does not exist." - } - - if (-not (Test-Path -Path $env:GITHUB_ACTION_INPUT_TestsPath)) { - throw "Path [$env:GITHUB_ACTION_INPUT_TestsPath] does not exist." - } - - [pscustomobject]@{ - ModuleName = $moduleName - CodeToTest = $codeToTest - TestType = $env:GITHUB_ACTION_INPUT_TestType - TestsPath = $env:GITHUB_ACTION_INPUT_TestsPath - StackTraceVerbosity = $env:GITHUB_ACTION_INPUT_StackTraceVerbosity - Verbosity = $env:GITHUB_ACTION_INPUT_Verbosity - } | Format-List -} - -$params = @{ - Path = $codeToTest - TestType = $env:GITHUB_ACTION_INPUT_TestType - TestsPath = $env:GITHUB_ACTION_INPUT_TestsPath - StackTraceVerbosity = $env:GITHUB_ACTION_INPUT_StackTraceVerbosity - Verbosity = $env:GITHUB_ACTION_INPUT_Verbosity -} -$testResults = Test-PSModule @params - -LogGroup 'Test results' { - $testResults | Format-List -} - -$failedTests = [int]$testResults.FailedCount - -if (($failedTests -gt 0) -or ($testResults.Result -ne 'Passed')) { - Write-GitHubError "❌ Some [$failedTests] tests failed." - Set-GitHubOutput -Name 'passed' -Value $false - $return = 1 -} elseif ($failedTests -eq 0) { - Write-GitHubNotice '✅ All tests passed.' - Set-GitHubOutput -Name 'passed' -Value $true - $return = 0 -} - -Write-Host '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━' -exit $return From 2d994737cf021771e47ceff1feec6778a3cd28cc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 14:16:42 +0100 Subject: [PATCH 018/172] Fix: Update Invoke-Pester action to use stable version v1 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9b00a3d9..b6ab156b 100644 --- a/action.yml +++ b/action.yml @@ -69,7 +69,7 @@ runs: Set-GitHubOutput -Name TestPath -Value $testPath - name: Invoke-Pester - uses: PSModule/Invoke-Pester@v1.1.1-preview + uses: PSModule/Invoke-Pester@v1 id: test with: Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} From 5dda7186b72d7ba04a219fccd73ea9097a1fb97f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 14:18:23 +0100 Subject: [PATCH 019/172] Refactor: Simplify configuration structure in Module.Configuration.ps1 and SourceCode.Configuration.ps1 --- scripts/tests/Module/Module.Configuration.ps1 | 16 +++++++--------- .../SourceCode/SourceCode.Configuration.ps1 | 6 ++---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index 31c6e351..3b6e185e 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,12 +1,10 @@ @{ - Configuration = @{ - CodeCoverage = @{ - Enabled = $true - OutputFormat = 'JaCoCo' - OutputEncoding = 'UTF8' - } - Output = @{ - Verbosity = 'Detailed' - } + CodeCoverage = @{ + Enabled = $true + OutputFormat = 'JaCoCo' + OutputEncoding = 'UTF8' + } + Output = @{ + Verbosity = 'Detailed' } } diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 index fdacba22..e4950855 100644 --- a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -1,7 +1,5 @@ @{ - Configuration = @{ - Output = @{ - Verbosity = 'Detailed' - } + Output = @{ + Verbosity = 'Detailed' } } From 607ab73a92efae881c9d306318f0a2eb16bb2841 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 14:44:42 +0100 Subject: [PATCH 020/172] Enhance: Update action.yml and test scripts to use environment variables for input parameters and improve path resolution --- action.yml | 20 +++++++++---------- scripts/tests/Module/Module.Configuration.ps1 | 4 ++++ .../Module/PSModule/Module.Container.ps1 | 4 ++-- .../PSScriptAnalyzer.Container.ps1 | 4 ++-- .../PSModule/SourceCode.Container.ps1 | 4 ++-- .../PSScriptAnalyzer.Container.ps1 | 4 ++-- .../SourceCode/SourceCode.Configuration.ps1 | 6 +++++- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/action.yml b/action.yml index b6ab156b..d54ca755 100644 --- a/action.yml +++ b/action.yml @@ -43,26 +43,26 @@ runs: uses: PSModule/Github-Script@v1 id: paths env: - Name: ${{ inputs.Name }} - Path: ${{ inputs.Path }} - TestType: ${{ inputs.TestType }} + GITHUB_ACTION_INPUT_TEST-PSMODULE_Name: ${{ inputs.Name }} + GITHUB_ACTION_INPUT_TEST-PSMODULE_Path: ${{ inputs.Path }} + GITHUB_ACTION_INPUT_TEST-PSMODULE_TestType: ${{ inputs.TestType }} with: Script: | # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. - Write-Host "Test type: [$env:TestType]" - $path = switch($env:TestType) { + Write-Host "Test type: [$env:GITHUB_ACTION_INPUT_TEST-PSMODULE_TestType]" + $codePath = switch($env:GITHUB_ACTION_INPUT_TEST-PSMODULE_TestType) { 'Module' { - Resolve-Path -Path "$env:Path/$env:Name" | Select-Object -ExpandProperty Path + Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST-PSMODULE_Path/$env:GITHUB_ACTION_INPUT_TEST-PSMODULE_Name" | Select-Object -ExpandProperty Path } 'SourceCode' { - Resolve-Path -Path $env:Path | Select-Object -ExpandProperty Path + Resolve-Path -Path $env:GITHUB_ACTION_INPUT_TEST-PSMODULE_Path | Select-Object -ExpandProperty Path } default { - throw "Invalid test type: [$env:TestType]" + throw "Invalid test type: [$env:GITHUB_ACTION_INPUT_TEST-PSMODULE_TestType]" } } Write-Host "Path: [$path]" - Set-GitHubOutput -Name Path -Value $path + Set-GitHubOutput -Name CodePath -Value $codePath $testPath = Resolve-Path -Path "${{ github.action_path }}/scripts/tests/${{ inputs.TestType }}" | Select-Object -ExpandProperty Path Write-Host "Test path: [$testPath]" @@ -73,4 +73,4 @@ runs: id: test with: Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} - Run_Path: ${{ fromJson(steps.paths.outputs.result).Path }} + Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index 3b6e185e..2d7a1804 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,4 +1,8 @@ @{ + TestResult = @{ + Enabled = $true + TestSuiteName = 'Module' + } CodeCoverage = @{ Enabled = $true OutputFormat = 'JaCoCo' diff --git a/scripts/tests/Module/PSModule/Module.Container.ps1 b/scripts/tests/Module/PSModule/Module.Container.ps1 index 650f1ce4..9fdb7570 100644 --- a/scripts/tests/Module/PSModule/Module.Container.ps1 +++ b/scripts/tests/Module/PSModule/Module.Container.ps1 @@ -1,7 +1,7 @@ @{ - Path = Join-Path -Path $PSScriptRoot -ChildPath 'Module.Tests.ps1' + Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $Path + Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path Debug = $false Verbose = $false } diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 55725f0d..8861b5ac 100644 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ - Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1' + Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $Path + Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path SettingsFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'PSScriptAnalyzer.Settings.psd1' Debug = $false Verbose = $false diff --git a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 index bbb6e9b4..d2cf9f50 100644 --- a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 @@ -1,7 +1,7 @@ @{ - Path = Join-Path -Path $PSScriptRoot -ChildPath 'SourceCode.Tests.ps1' + Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $Path + Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path TestsPath = $moduleTestsPath Debug = $false Verbose = $false diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 55725f0d..8861b5ac 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ - Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1' + Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $Path + Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path SettingsFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'PSScriptAnalyzer.Settings.psd1' Debug = $false Verbose = $false diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 index e4950855..4c4ca3dd 100644 --- a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -1,5 +1,9 @@ @{ - Output = @{ + TestResult = @{ + Enabled = $true + TestSuiteName = 'SourceCode' + } + Output = @{ Verbosity = 'Detailed' } } From c11a47e03e74e9f5b495df77115907267b9a18d6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 14:49:41 +0100 Subject: [PATCH 021/172] Enhance: Update action.yml to use underscores in environment variable names for consistency --- action.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index d54ca755..993eda15 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: Test-PSModule (by PSModule) +name: Test_PSModule (by PSModule) description: Test a PowerShell module before publishing the module to the PowerShell Gallery. author: PSModule branding: @@ -43,22 +43,22 @@ runs: uses: PSModule/Github-Script@v1 id: paths env: - GITHUB_ACTION_INPUT_TEST-PSMODULE_Name: ${{ inputs.Name }} - GITHUB_ACTION_INPUT_TEST-PSMODULE_Path: ${{ inputs.Path }} - GITHUB_ACTION_INPUT_TEST-PSMODULE_TestType: ${{ inputs.TestType }} + GITHUB_ACTION_INPUT_TEST_PSMODULE_Name: ${{ inputs.Name }} + GITHUB_ACTION_INPUT_TEST_PSMODULE_Path: ${{ inputs.Path }} + GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType: ${{ inputs.TestType }} with: Script: | # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. - Write-Host "Test type: [$env:GITHUB_ACTION_INPUT_TEST-PSMODULE_TestType]" - $codePath = switch($env:GITHUB_ACTION_INPUT_TEST-PSMODULE_TestType) { + Write-Host "Test type: [$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType]" + $codePath = switch($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType) { 'Module' { - Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST-PSMODULE_Path/$env:GITHUB_ACTION_INPUT_TEST-PSMODULE_Name" | Select-Object -ExpandProperty Path + Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name" | Select-Object -ExpandProperty Path } 'SourceCode' { - Resolve-Path -Path $env:GITHUB_ACTION_INPUT_TEST-PSMODULE_Path | Select-Object -ExpandProperty Path + Resolve-Path -Path $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path } default { - throw "Invalid test type: [$env:GITHUB_ACTION_INPUT_TEST-PSMODULE_TestType]" + throw "Invalid test type: [$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType]" } } Write-Host "Path: [$path]" From e7d5b0a36c37b16d9b9d86a43c5ec31a60c54ad5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 14:56:09 +0100 Subject: [PATCH 022/172] Enhance: Update action.yml to rename the module and use a fixed version for Invoke-Pester --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 993eda15..db97f8fa 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: Test_PSModule (by PSModule) +name: Test-PSModule (by PSModule) description: Test a PowerShell module before publishing the module to the PowerShell Gallery. author: PSModule branding: @@ -69,7 +69,7 @@ runs: Set-GitHubOutput -Name TestPath -Value $testPath - name: Invoke-Pester - uses: PSModule/Invoke-Pester@v1 + uses: PSModule/Invoke-Pester@fix id: test with: Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} From c74b8b5790e46aeb7a8921158868ab62b069693c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 15:33:08 +0100 Subject: [PATCH 023/172] Enhance: Update path resolution in test scripts for consistency and reliability --- .../Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 | 4 ++-- .../PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 8861b5ac..2eb70a41 100644 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -2,7 +2,7 @@ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path - SettingsFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'PSScriptAnalyzer.Settings.psd1' + SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 index d2cf9f50..3070a764 100644 --- a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path - TestsPath = $moduleTestsPath + Path = Resolve-Path -Path "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" | Select-Object -ExpandProperty Path + TestsPath = Resolve-Path -Path "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 8861b5ac..2eb70a41 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -2,7 +2,7 @@ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path - SettingsFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'PSScriptAnalyzer.Settings.psd1' + SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false } From 70bc40eaa6e2b06958eef62e46767c0a0f99ed86 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 16:22:54 +0100 Subject: [PATCH 024/172] Enhance: Update path resolution in test scripts to improve consistency and reliability --- scripts/tests/Module/PSModule/Module.Container.ps1 | 2 +- scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 | 4 ++-- .../PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tests/Module/PSModule/Module.Container.ps1 b/scripts/tests/Module/PSModule/Module.Container.ps1 index 9fdb7570..a7266b47 100644 --- a/scripts/tests/Module/PSModule/Module.Container.ps1 +++ b/scripts/tests/Module/PSModule/Module.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path + Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" | Select-Object -ExpandProperty Path Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 index 3070a764..4ece8583 100644 --- a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" | Select-Object -ExpandProperty Path - TestsPath = Resolve-Path -Path "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path + Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" | Select-Object -ExpandProperty Path + TestsPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 2eb70a41..941fa72e 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path + Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" | Select-Object -ExpandProperty Path SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false From 4fbe6d0db05e9cbd269d9fd920a47512b642fca5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 16:54:27 +0100 Subject: [PATCH 025/172] Enhance: Simplify path resolution in test scripts for improved clarity and consistency --- scripts/tests/Module/PSModule/Module.Container.ps1 | 2 +- .../Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 | 4 ++-- .../PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/tests/Module/PSModule/Module.Container.ps1 b/scripts/tests/Module/PSModule/Module.Container.ps1 index a7266b47..d4b9ba1a 100644 --- a/scripts/tests/Module/PSModule/Module.Container.ps1 +++ b/scripts/tests/Module/PSModule/Module.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" | Select-Object -ExpandProperty Path + Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" Debug = $false Verbose = $false } diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 2eb70a41..58c9ad9c 100644 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path $env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path + Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false diff --git a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 index 4ece8583..5b16fe0e 100644 --- a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" | Select-Object -ExpandProperty Path - TestsPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path + Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" + TestsPath = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 941fa72e..58c9ad9c 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" | Select-Object -ExpandProperty Path + Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false From 51baa1424ed33514f4eac7c4182b2f90b24902fd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 16:58:36 +0100 Subject: [PATCH 026/172] Enhance: Refactor test scripts by consolidating and updating PSModule.Container.ps1 and related files for improved structure and clarity --- .../PSModule/{Module.Container.ps1 => PSModule.Container.ps1} | 0 .../Module/PSModule/{Module.Tests.ps1 => PSModule.Tests.ps1} | 0 .../Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- .../{SourceCode.Container.ps1 => PSModule.Container.ps1} | 0 .../PSModule/{SourceCode.Tests.ps1 => PSModule.Tests.ps1} | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename scripts/tests/Module/PSModule/{Module.Container.ps1 => PSModule.Container.ps1} (100%) rename scripts/tests/Module/PSModule/{Module.Tests.ps1 => PSModule.Tests.ps1} (100%) rename scripts/tests/SourceCode/PSModule/{SourceCode.Container.ps1 => PSModule.Container.ps1} (100%) rename scripts/tests/SourceCode/PSModule/{SourceCode.Tests.ps1 => PSModule.Tests.ps1} (100%) diff --git a/scripts/tests/Module/PSModule/Module.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 similarity index 100% rename from scripts/tests/Module/PSModule/Module.Container.ps1 rename to scripts/tests/Module/PSModule/PSModule.Container.ps1 diff --git a/scripts/tests/Module/PSModule/Module.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 similarity index 100% rename from scripts/tests/Module/PSModule/Module.Tests.ps1 rename to scripts/tests/Module/PSModule/PSModule.Tests.ps1 diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 58c9ad9c..d26fa860 100644 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -2,7 +2,7 @@ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" - SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" + SettingsFilePath = "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 similarity index 100% rename from scripts/tests/SourceCode/PSModule/SourceCode.Container.ps1 rename to scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 diff --git a/scripts/tests/SourceCode/PSModule/SourceCode.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 similarity index 100% rename from scripts/tests/SourceCode/PSModule/SourceCode.Tests.ps1 rename to scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 From ce4451e86c641f12a9c4d6fdd903bfc8551d59b6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 17:01:00 +0100 Subject: [PATCH 027/172] Enhance: Update output messages in action.yml for clarity in path reporting --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index db97f8fa..bcb0554b 100644 --- a/action.yml +++ b/action.yml @@ -61,11 +61,11 @@ runs: throw "Invalid test type: [$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType]" } } - Write-Host "Path: [$path]" + Write-Host "Path to code: [$codePath]" Set-GitHubOutput -Name CodePath -Value $codePath $testPath = Resolve-Path -Path "${{ github.action_path }}/scripts/tests/${{ inputs.TestType }}" | Select-Object -ExpandProperty Path - Write-Host "Test path: [$testPath]" + Write-Host "Path to tests: [$testPath]" Set-GitHubOutput -Name TestPath -Value $testPath - name: Invoke-Pester From ff37be836d77101d2632bf522fc2658c62b6e95c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 17:06:29 +0100 Subject: [PATCH 028/172] Enhance: Update path variables in container scripts for consistency in test execution --- scripts/tests/Module/PSModule/PSModule.Container.ps1 | 2 +- .../Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 | 4 ++-- .../PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 index d4b9ba1a..9c2fb3b2 100644 --- a/scripts/tests/Module/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" + Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path" Debug = $false Verbose = $false } diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index d26fa860..10433343 100644 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" + Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path" SettingsFilePath = "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index 5b16fe0e..7b560ad4 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" - TestsPath = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" + Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path" + TestsPath = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path/tests" Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 58c9ad9c..cdf9d2ed 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" + Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path" SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false From 44aa2d151ea71492057d87ee0856713d9627cdfa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 17:10:16 +0100 Subject: [PATCH 029/172] Enhance: Simplify path assignment in container scripts for improved clarity and consistency --- scripts/tests/Module/PSModule/PSModule.Container.ps1 | 2 +- .../Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 | 4 ++-- .../PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 index 9c2fb3b2..37c6bb30 100644 --- a/scripts/tests/Module/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path" + Path = $env:GITHUB_ACTION_INPUT_Run_Path Debug = $false Verbose = $false } diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 10433343..d1c53dba 100644 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path" + Path = $env:GITHUB_ACTION_INPUT_Run_Path SettingsFilePath = "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index 7b560ad4..28716fce 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path" - TestsPath = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path/tests" + Path = $env:GITHUB_ACTION_INPUT_Run_Path + TestsPath = "$env:GITHUB_ACTION_INPUT_Run_Path/tests" Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index cdf9d2ed..15c6c3f8 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_Run_Path" + Path = $env:GITHUB_ACTION_INPUT_Run_Path SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false From 9138351bda525ad4af6263e7b2c5022e6692ac37 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 17:55:52 +0100 Subject: [PATCH 030/172] Refactor: Remove Test-PSModule function and introduce helper functions for module management --- scripts/helpers/Test-PSModule.ps1 | 61 ------------------- .../tests/Module/PSModule/PSModule.Tests.ps1 | 13 +++- .../PSModule/helpers/Import-PSModule.ps1 | 49 +++++++++++++++ .../PSModule/helpers/Remove-PSModule.ps1 | 28 +++++++++ .../helpers/Resolve-PSModuleDependency.ps1 | 7 ++- 5 files changed, 93 insertions(+), 65 deletions(-) delete mode 100644 scripts/helpers/Test-PSModule.ps1 create mode 100644 scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 create mode 100644 scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 rename scripts/{ => tests/Module/PSModule}/helpers/Resolve-PSModuleDependency.ps1 (94%) diff --git a/scripts/helpers/Test-PSModule.ps1 b/scripts/helpers/Test-PSModule.ps1 deleted file mode 100644 index 81ce1524..00000000 --- a/scripts/helpers/Test-PSModule.ps1 +++ /dev/null @@ -1,61 +0,0 @@ -function Test-PSModule { - <# - .SYNOPSIS - Performs tests on a module. - #> - [OutputType([int])] - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSReviewUnusedParameter', '', Scope = 'Function', - Justification = 'Parameters are used in nested ScriptBlocks' - )] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - param( - # Path to the folder where the code to test is located. - [Parameter(Mandatory)] - [string] $Path, - - # Path to the folder where the tests are located. - [Parameter()] - [string] $TestsPath = 'tests' - ) - - $moduleName = Split-Path -Path $Path -Leaf - $testSourceCode = $TestType -eq 'SourceCode' - $testModule = $TestType -eq 'Module' - $moduleTestsPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $TestsPath - - if ($testModule) { - if (Test-Path -Path $moduleTestsPath) { - LogGroup "Add test - Module - $moduleName" { - $containerParams = @{ - Path = $moduleTestsPath - } - Write-Host ($containerParams | ConvertTo-Json) - $containers += New-PesterContainer @containerParams - } - } else { - Write-GitHubWarning "⚠️ No tests found - [$moduleTestsPath]" - } - } - - if ((Test-Path -Path $moduleTestsPath) -and $testModule) { - LogGroup 'Install module dependencies' { - $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" - Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath - } - - LogGroup "Importing module: $moduleName" { - Add-PSModulePath -Path (Split-Path $Path -Parent) - $existingModule = Get-Module -Name $ModuleName -ListAvailable - $existingModule | Remove-Module -Force - $existingModule.RequiredModules | ForEach-Object { $_ | Remove-Module -Force -ErrorAction SilentlyContinue } - $existingModule.NestedModules | ForEach-Object { $_ | Remove-Module -Force -ErrorAction SilentlyContinue } - Import-Module -Name $moduleName -Force -RequiredVersion '999.0.0' -Global - } - } - -} diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index 772f2a5b..e2f133d5 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -13,7 +13,18 @@ BeforeAll { 'PSUseDeclaredVarsMoreThanAssignments', 'moduleName', Justification = 'moduleName is used in the test.' )] + + $helperPath = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') + Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { + . $_.FullName + } + $moduleName = Split-Path -Path $Path -Leaf + Write-Verbose "Module Name: [$moduleName]" + $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" + Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath + Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) + Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName } Describe 'PSModule - Module tests' { @@ -27,7 +38,7 @@ Describe 'PSModule - Module tests' { } } - Context "Module Manifest" { + Context 'Module Manifest' { BeforeAll { $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" Write-Verbose "Module Manifest Path: [$moduleManifestPath]" diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 new file mode 100644 index 00000000..75c049aa --- /dev/null +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -0,0 +1,49 @@ +function Import-PSModule { + <# + .SYNOPSIS + Imports a build PS module. + + .DESCRIPTION + Imports a build PS module. + + .EXAMPLE + Import-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $ModuleName + + Imports a module located at $ModuleFolderPath with the name $ModuleName. + #> + [CmdletBinding()] + #Requires -Modules Utilities + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', Scope = 'Function', + Justification = 'Want to just write to the console, not the pipeline.' + )] + param( + # Path to the folder where the module source code is located. + [Parameter(Mandatory)] + [string] $Path, + + # Name of the module. + [Parameter(Mandatory)] + [string] $ModuleName + ) + + $moduleName = Split-Path -Path $Path -Leaf + $manifestFileName = "$moduleName.psd1" + $manifestFilePath = Join-Path -Path $Path $manifestFileName + $manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose + + Write-Host "Manifest file path: [$($manifestFile.FullName)]" -Verbose + Remove-PSModule -Name $ModuleName + Resolve-PSModuleDependency -ManifestFilePath $manifestFile + Import-Module -Name $ModuleName -RequiredVersion '999.0.0' + + Write-Host 'List loaded modules' + $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false + $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize + Write-Host 'List commands' + Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) + + if ($ModuleName -notin $availableModules.Name) { + throw 'Module not found' + } +} diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 new file mode 100644 index 00000000..91e62a34 --- /dev/null +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -0,0 +1,28 @@ +filter Remove-PSModule { + <# + .SYNOPSIS + Removes and uninstalls a PowerShell module. + + + .EXAMPLE + Remove-PSModule -ModuleName 'Utilities' + + Removes a module 'Utilities' from the session then from the system. + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', Scope = 'Function', + Justification = 'Want to just write to the console, not the pipeline.' + )] + [CmdletBinding(SupportsShouldProcess)] + param( + # Name of the module. + [Parameter(Mandatory, ValueFromPipeline)] + [string] $Name + ) + + if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { + Write-Host "Removing module [$Name]" + Get-Module -Name $Name -ListAvailable | Remove-Module -Force + Get-InstalledPSResource -Name $Name | Uninstall-PSResource -SkipDependencyCheck + } +} diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 similarity index 94% rename from scripts/helpers/Resolve-PSModuleDependency.ps1 rename to scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 index 3e0cea8e..7062478f 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 @@ -1,5 +1,4 @@ - -function Resolve-PSModuleDependency { +function Resolve-PSModuleDependency { <# .SYNOPSIS Resolve dependencies for a module based on the manifest file. @@ -50,9 +49,11 @@ function Resolve-PSModuleDependency { $installParams.Force = $true $installParams.Verbose = $false - Write-Host "[$($installParams.Name)] - Installing module" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' + Write-Host "[$($installParams.Name)] - Uninstalling module" + Remove-PSModule -Name $installParams.Name + Write-Host "[$($installParams.Name)] - Installing module" Retry -Count 5 -Delay 10 { Install-Module @installParams -AllowPrerelease:$false } From db42cf8aeed356b2e83608fd77ea7674a451ff66 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 18:01:44 +0100 Subject: [PATCH 031/172] Enhance: Update PSModule.Tests.ps1 to improve module path handling for better clarity and functionality --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index e2f133d5..a433c867 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -21,10 +21,11 @@ BeforeAll { $moduleName = Split-Path -Path $Path -Leaf Write-Verbose "Module Name: [$moduleName]" + $outputFolder = (Split-Path -Path $Path -Parent) $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath - Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) - Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName + Add-PSModulePath -Path $outputFolder + Import-PSModule -Path $outputFolder -ModuleName $ModuleName } Describe 'PSModule - Module tests' { From 4e85d46cb49a257002410a6d013067e95945bbcb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 18:07:22 +0100 Subject: [PATCH 032/172] Enhance: Add verbose flag to Write-Verbose for improved module name logging in tests --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index a433c867..fbca86d0 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -20,7 +20,7 @@ BeforeAll { } $moduleName = Split-Path -Path $Path -Leaf - Write-Verbose "Module Name: [$moduleName]" + Write-Verbose "Module Name: [$moduleName]" -Verbose $outputFolder = (Split-Path -Path $Path -Parent) $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath From 18145d5976325350fca281a7d3811cc2a7fff4ef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 18:12:15 +0100 Subject: [PATCH 033/172] Enhance: Simplify output folder assignment and module import in PSModule.Tests.ps1 for improved clarity --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index fbca86d0..43c19090 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -21,11 +21,11 @@ BeforeAll { $moduleName = Split-Path -Path $Path -Leaf Write-Verbose "Module Name: [$moduleName]" -Verbose - $outputFolder = (Split-Path -Path $Path -Parent) + $outputFolder = Split-Path -Path $Path -Parent $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath Add-PSModulePath -Path $outputFolder - Import-PSModule -Path $outputFolder -ModuleName $ModuleName + Import-PSModule -Path $Path } Describe 'PSModule - Module tests' { From ed2972baa359598ba9a1319e55fef86b9f5b6120 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 20:26:57 +0100 Subject: [PATCH 034/172] Refactor: Simplify parameters in Import-PSModule.ps1 by removing mandatory ModuleName parameter --- scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 index 75c049aa..d8acc4d8 100644 --- a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -20,11 +20,7 @@ param( # Path to the folder where the module source code is located. [Parameter(Mandatory)] - [string] $Path, - - # Name of the module. - [Parameter(Mandatory)] - [string] $ModuleName + [string] $Path ) $moduleName = Split-Path -Path $Path -Leaf From 34ed345fe876183b8730b4afc6bea732fcdba124 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 20:32:45 +0100 Subject: [PATCH 035/172] Refactor: Remove unnecessary module manifest resolution in PSModule.Tests.ps1 for improved clarity --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index 43c19090..c15a1488 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -22,8 +22,6 @@ BeforeAll { $moduleName = Split-Path -Path $Path -Leaf Write-Verbose "Module Name: [$moduleName]" -Verbose $outputFolder = Split-Path -Path $Path -Parent - $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" - Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath Add-PSModulePath -Path $outputFolder Import-PSModule -Path $Path } From cb59b450600c7a8e1a80d10ab9550d38e15a1e0d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 20:40:10 +0100 Subject: [PATCH 036/172] Refactor: Remove verbose flag from Write-Host in Import-PSModule.ps1 for consistency; streamline module removal logic in Remove-PSModule.ps1; simplify Install-Module call in Resolve-PSModuleDependency.ps1 --- .../tests/Module/PSModule/helpers/Import-PSModule.ps1 | 2 +- .../tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 10 ++++++++-- .../PSModule/helpers/Resolve-PSModuleDependency.ps1 | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 index d8acc4d8..f8a80687 100644 --- a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -28,7 +28,7 @@ $manifestFilePath = Join-Path -Path $Path $manifestFileName $manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose - Write-Host "Manifest file path: [$($manifestFile.FullName)]" -Verbose + Write-Host "Manifest file path: [$($manifestFile.FullName)]" Remove-PSModule -Name $ModuleName Resolve-PSModuleDependency -ManifestFilePath $manifestFile Import-Module -Name $ModuleName -RequiredVersion '999.0.0' diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 91e62a34..61b82973 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -22,7 +22,13 @@ if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { Write-Host "Removing module [$Name]" - Get-Module -Name $Name -ListAvailable | Remove-Module -Force - Get-InstalledPSResource -Name $Name | Uninstall-PSResource -SkipDependencyCheck + $importedModule = Get-Module -Name $Name -ListAvailable + if ($importedModule) { + Remove-Module -Force -Name $Name + } + $installedModule = Get-InstalledPSResource -Name $Name + if ($installedModule) { + Uninstall-PSResource -Name $Name -SkipDependencyCheck + } } } diff --git a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 index 7062478f..6d56d946 100644 --- a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 @@ -55,7 +55,7 @@ Remove-PSModule -Name $installParams.Name Write-Host "[$($installParams.Name)] - Installing module" Retry -Count 5 -Delay 10 { - Install-Module @installParams -AllowPrerelease:$false + Install-Module @installParams } $VerbosePreference = $VerbosePreferenceOriginal Write-Host "[$($installParams.Name)] - Importing module" From 73a66da2a6d92d6f2b4334a961e7078438b74376 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 20:43:41 +0100 Subject: [PATCH 037/172] Refactor: Streamline module removal logic in Remove-PSModule.ps1 to handle multiple modules more efficiently --- scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 61b82973..3bcf6878 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -23,12 +23,12 @@ if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { Write-Host "Removing module [$Name]" $importedModule = Get-Module -Name $Name -ListAvailable - if ($importedModule) { - Remove-Module -Force -Name $Name + foreach ($module in $importedModule) { + $module | Remove-Module -Force } $installedModule = Get-InstalledPSResource -Name $Name - if ($installedModule) { - Uninstall-PSResource -Name $Name -SkipDependencyCheck + foreach ($module in $installedModule) { + $module | Uninstall-PSResource -SkipDependencyCheck } } } From b1737cb144548936eed35c7604a09814bb0afda5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 20:46:52 +0100 Subject: [PATCH 038/172] Refactor: Optimize module retrieval in Remove-PSModule.ps1 to enhance performance and clarity --- scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 3bcf6878..65618323 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -22,11 +22,11 @@ if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { Write-Host "Removing module [$Name]" - $importedModule = Get-Module -Name $Name -ListAvailable + $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } foreach ($module in $importedModule) { $module | Remove-Module -Force } - $installedModule = Get-InstalledPSResource -Name $Name + $installedModule = Get-InstalledPSResource | Where-Object { $_.Name -eq $Name } foreach ($module in $installedModule) { $module | Uninstall-PSResource -SkipDependencyCheck } From d31a21ca7661f45cfaae05376f339f3ca05e143a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 20:51:53 +0100 Subject: [PATCH 039/172] Refactor: Enhance Remove-PSModule.ps1 to remove commands associated with the module before removal --- scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 65618323..0553dd0d 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -23,6 +23,10 @@ if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { Write-Host "Removing module [$Name]" $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } + $commands = Get-Command -Module $Name + foreach ($command in $commands) { + $command | Remove-Item -Force + } foreach ($module in $importedModule) { $module | Remove-Module -Force } From f808a898117817f97fa49f5d3ccc306ed2f400ca Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 21:04:58 +0100 Subject: [PATCH 040/172] Refactor: Add OS input to workflows and update Remove-PSModule output message for clarity --- .github/workflows/Action-Test-Src-Default.yml | 2 ++ .github/workflows/Action-Test-Src-WithManifest.yml | 1 + .github/workflows/Action-Test-outputs.yml | 1 + action.yml | 5 +++++ scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 2 +- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test-Src-Default.yml b/.github/workflows/Action-Test-Src-Default.yml index 52f0b494..c16dfe4d 100644 --- a/.github/workflows/Action-Test-Src-Default.yml +++ b/.github/workflows/Action-Test-Src-Default.yml @@ -35,8 +35,10 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} with: + Name: PSModuleTest Path: tests/src TestType: SourceCode + OS: ${{ matrix.os }} - name: Status shell: pwsh diff --git a/.github/workflows/Action-Test-Src-WithManifest.yml b/.github/workflows/Action-Test-Src-WithManifest.yml index b14f85b8..e9f6b6be 100644 --- a/.github/workflows/Action-Test-Src-WithManifest.yml +++ b/.github/workflows/Action-Test-Src-WithManifest.yml @@ -38,6 +38,7 @@ jobs: Name: PSModuleTest Path: tests/srcWithManifest TestType: SourceCode + OS: ${{ matrix.os }} - name: Status shell: pwsh diff --git a/.github/workflows/Action-Test-outputs.yml b/.github/workflows/Action-Test-outputs.yml index 84749eca..8d116b68 100644 --- a/.github/workflows/Action-Test-outputs.yml +++ b/.github/workflows/Action-Test-outputs.yml @@ -38,6 +38,7 @@ jobs: Name: PSModuleTest Path: tests/outputs/modules TestType: Module + OS: ${{ matrix.os }} - name: Status shell: pwsh diff --git a/action.yml b/action.yml index bcb0554b..e037004f 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ inputs: TestType: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true + OS: + description: The operating system to run the tests on. + required: true # Debug: # description: Enable debug output. # required: false @@ -46,6 +49,7 @@ runs: GITHUB_ACTION_INPUT_TEST_PSMODULE_Name: ${{ inputs.Name }} GITHUB_ACTION_INPUT_TEST_PSMODULE_Path: ${{ inputs.Path }} GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType: ${{ inputs.TestType }} + GITHUB_ACTION_INPUT_TEST_PSMODULE_OS: ${{ inputs.OS }} with: Script: | # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. @@ -72,5 +76,6 @@ runs: uses: PSModule/Invoke-Pester@fix id: test with: + TestResult_TestSuiteName: ${{ inputs.OS }}-${{ inputs.TestType }} Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 0553dd0d..975b161f 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -21,7 +21,7 @@ ) if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { - Write-Host "Removing module [$Name]" + Write-Host "[$Name] - Remove module" $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } $commands = Get-Command -Module $Name foreach ($command in $commands) { From a1f0b51663b9f297f66fc5c0894a0915e86a7230 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 21:14:04 +0100 Subject: [PATCH 041/172] Refactor: Update command retrieval in Remove-PSModule.ps1 to use Get-ChildItem for improved accuracy --- scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 975b161f..1ed2d6df 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -23,7 +23,7 @@ if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { Write-Host "[$Name] - Remove module" $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } - $commands = Get-Command -Module $Name + $commands = Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } foreach ($command in $commands) { $command | Remove-Item -Force } From 769c8e038c77534cc53a37bf12f041b1d03e1b79 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 21:21:27 +0100 Subject: [PATCH 042/172] Refactor: Improve logging in Remove-PSModule.ps1 to enhance visibility of command and module removal processes --- scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 1ed2d6df..9dc4014e 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -24,14 +24,20 @@ Write-Host "[$Name] - Remove module" $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } $commands = Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } + Write-Host "Found [$($commands.Count)] commands to remove" foreach ($command in $commands) { + Write-Host "Removing command [$($command.Name)]" $command | Remove-Item -Force } + Write-Host "Found [$($importedModule.Count)] modules to remove" foreach ($module in $importedModule) { + Write-Host "Removing module [$($module.Name)]" $module | Remove-Module -Force } $installedModule = Get-InstalledPSResource | Where-Object { $_.Name -eq $Name } + Write-Host "Found [$($installedModule.Count)] installed modules to remove" foreach ($module in $installedModule) { + Write-Host "Uninstalling module [$($module.Name)]" $module | Uninstall-PSResource -SkipDependencyCheck } } From f2c5d7ba8836a7ea2257f75568a884e234c03fbe Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 21:37:01 +0100 Subject: [PATCH 043/172] Refactor: Enhance logging in PSModule tests for improved clarity and visibility --- .../tests/Module/PSModule/PSModule.Tests.ps1 | 23 ++++++++----------- .../PSModule/helpers/Import-PSModule.ps1 | 6 ++--- .../PSModule/helpers/Remove-PSModule.ps1 | 12 +++++----- .../helpers/Resolve-PSModuleDependency.ps1 | 14 +++++------ 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index c15a1488..83812ea0 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -9,21 +9,18 @@ Param( ) BeforeAll { - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseDeclaredVarsMoreThanAssignments', 'moduleName', - Justification = 'moduleName is used in the test.' - )] + LogGroup "Load module from path [$Path]" { + $helperPath = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') + Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { + . $_.FullName + } - $helperPath = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') - Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { - . $_.FullName + $moduleName = Split-Path -Path $Path -Leaf + Write-Verbose "[$moduleName] - Processing" -Verbose + $outputFolder = Split-Path -Path $Path -Parent + Add-PSModulePath -Path $outputFolder + Import-PSModule -Path $Path } - - $moduleName = Split-Path -Path $Path -Leaf - Write-Verbose "Module Name: [$moduleName]" -Verbose - $outputFolder = Split-Path -Path $Path -Parent - Add-PSModulePath -Path $outputFolder - Import-PSModule -Path $Path } Describe 'PSModule - Module tests' { diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 index f8a80687..65e653d6 100644 --- a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -28,15 +28,15 @@ $manifestFilePath = Join-Path -Path $Path $manifestFileName $manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose - Write-Host "Manifest file path: [$($manifestFile.FullName)]" + Write-Host " - Manifest file path: [$($manifestFile.FullName)]" Remove-PSModule -Name $ModuleName Resolve-PSModuleDependency -ManifestFilePath $manifestFile Import-Module -Name $ModuleName -RequiredVersion '999.0.0' - Write-Host 'List loaded modules' + Write-Host ' - List loaded modules' $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize - Write-Host 'List commands' + Write-Host ' - List commands' Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) if ($ModuleName -notin $availableModules.Name) { diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 9dc4014e..cc300d97 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -24,20 +24,20 @@ Write-Host "[$Name] - Remove module" $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } $commands = Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } - Write-Host "Found [$($commands.Count)] commands to remove" + Write-Host " - Found [$($commands.Count)] commands to remove" foreach ($command in $commands) { - Write-Host "Removing command [$($command.Name)]" + Write-Host " - Removing command [$($command.Name)]" $command | Remove-Item -Force } - Write-Host "Found [$($importedModule.Count)] modules to remove" + Write-Host " - Found [$($importedModule.Count)] modules to remove" foreach ($module in $importedModule) { - Write-Host "Removing module [$($module.Name)]" + Write-Host " - Removing module [$($module.Name)]" $module | Remove-Module -Force } $installedModule = Get-InstalledPSResource | Where-Object { $_.Name -eq $Name } - Write-Host "Found [$($installedModule.Count)] installed modules to remove" + Write-Host " - Found [$($installedModule.Count)] installed modules to remove" foreach ($module in $installedModule) { - Write-Host "Uninstalling module [$($module.Name)]" + Write-Host " - Uninstalling module [$($module.Name)]" $module | Uninstall-PSResource -SkipDependencyCheck } } diff --git a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 index 6d56d946..2496e8e4 100644 --- a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 @@ -32,8 +32,8 @@ Write-Host 'Resolving dependencies' $manifest = Import-PowerShellDataFile -Path $ManifestFilePath - Write-Host "Reading [$ManifestFilePath]" - Write-Host "Found [$($manifest.RequiredModules.Count)] modules to install" + Write-Host " - Reading [$ManifestFilePath]" + Write-Host " - Found [$($manifest.RequiredModules.Count)] modules to install" foreach ($requiredModule in $manifest.RequiredModules) { $installParams = @{} @@ -51,19 +51,19 @@ $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Write-Host "[$($installParams.Name)] - Uninstalling module" + Write-Host " - [$($installParams.Name)] - Uninstalling module" Remove-PSModule -Name $installParams.Name - Write-Host "[$($installParams.Name)] - Installing module" + Write-Host " - [$($installParams.Name)] - Installing module" Retry -Count 5 -Delay 10 { Install-Module @installParams } $VerbosePreference = $VerbosePreferenceOriginal - Write-Host "[$($installParams.Name)] - Importing module" + Write-Host " - [$($installParams.Name)] - Importing module" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' Import-Module @installParams $VerbosePreference = $VerbosePreferenceOriginal - Write-Host "[$($installParams.Name)] - Done" + Write-Host " - [$($installParams.Name)] - Done" } - Write-Host 'Resolving dependencies - Done' + Write-Host ' - Resolving dependencies - Done' } From 65994c0682f581de20a5646346eb352393264d48 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 21:53:28 +0100 Subject: [PATCH 044/172] Refactor: Update output value in action.yml to use standardized output naming --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index e037004f..2a6acb89 100644 --- a/action.yml +++ b/action.yml @@ -37,7 +37,7 @@ inputs: outputs: passed: description: If the tests passed. - value: ${{ fromJSON(steps.test.outputs.result).passed }} + value: ${{ steps.test.outputs.Passed }} runs: using: composite From 0b186b0b98a0897a08de1e712f0f94cc2cd76e31 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 22:24:13 +0100 Subject: [PATCH 045/172] Refactor: Update TestResult_TestSuiteName format in action.yml and enhance logging in Remove-PSModule.ps1 --- action.yml | 2 +- .../tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 2a6acb89..16de54d0 100644 --- a/action.yml +++ b/action.yml @@ -76,6 +76,6 @@ runs: uses: PSModule/Invoke-Pester@fix id: test with: - TestResult_TestSuiteName: ${{ inputs.OS }}-${{ inputs.TestType }} + TestResult_TestSuiteName: ${{ inputs.TestType }}-${{ inputs.OS }} Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index cc300d97..6af275b7 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -23,22 +23,23 @@ if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { Write-Host "[$Name] - Remove module" $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } + Write-Host " - Found [$($importedModule.Count)] modules to remove" + foreach ($module in $importedModule) { + Write-Host " - Removing module [$($module.Name)]" + $module | Remove-Module -Force + } $commands = Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } Write-Host " - Found [$($commands.Count)] commands to remove" foreach ($command in $commands) { Write-Host " - Removing command [$($command.Name)]" $command | Remove-Item -Force } - Write-Host " - Found [$($importedModule.Count)] modules to remove" - foreach ($module in $importedModule) { - Write-Host " - Removing module [$($module.Name)]" - $module | Remove-Module -Force - } $installedModule = Get-InstalledPSResource | Where-Object { $_.Name -eq $Name } Write-Host " - Found [$($installedModule.Count)] installed modules to remove" foreach ($module in $installedModule) { Write-Host " - Uninstalling module [$($module.Name)]" $module | Uninstall-PSResource -SkipDependencyCheck } + Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } | Format-Table -AutoSize } } From 499d4b2dbf98095b23502f6419fe8e3951746890 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 22:33:42 +0100 Subject: [PATCH 046/172] Refactor: Update command retrieval in Remove-PSModule.ps1 to use Get-Command for improved accuracy --- scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 6af275b7..749765e4 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -40,6 +40,6 @@ Write-Host " - Uninstalling module [$($module.Name)]" $module | Uninstall-PSResource -SkipDependencyCheck } - Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } | Format-Table -AutoSize + Get-Command -Module $Name | Format-Table -AutoSize } } From 660f7cc794481ded9c2d83f8abc5e8e9b08d3cf0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 22:38:24 +0100 Subject: [PATCH 047/172] Refactor: Update Install-Module call in Resolve-PSModuleDependency.ps1 to include -AllowClobber for better module installation handling --- .../Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 index 2496e8e4..4a144233 100644 --- a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 @@ -55,7 +55,7 @@ Remove-PSModule -Name $installParams.Name Write-Host " - [$($installParams.Name)] - Installing module" Retry -Count 5 -Delay 10 { - Install-Module @installParams + Install-Module @installParams -AllowClobber } $VerbosePreference = $VerbosePreferenceOriginal Write-Host " - [$($installParams.Name)] - Importing module" From 255b46c29cf2b86f6ea831625e29df1906dcfb84 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 22:48:59 +0100 Subject: [PATCH 048/172] Refactor: Replace Write-Verbose with Write-Host for improved output visibility in PSModule.Tests.ps1 --- .../SourceCode/PSModule/PSModule.Tests.ps1 | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index bbed2449..ef7de1f1 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -25,7 +25,7 @@ BeforeAll { $scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File LogGroup "Found $($scriptFiles.Count) script files in [$Path]" { $scriptFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $functionsPath = Join-Path -Path $Path -ChildPath 'functions' @@ -33,7 +33,7 @@ BeforeAll { LogGroup "Found $($functionFiles.Count) function files in [$functionsPath]" { $functionFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private' @@ -41,21 +41,21 @@ BeforeAll { (Get-ChildItem -Path $privateFunctionsPath -File -Filter '*.ps1' -Recurse) : $null LogGroup "Found $($privateFunctionFiles.Count) private function files in [$privateFunctionsPath]" { $privateFunctionFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public' $publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null LogGroup "Found $($publicFunctionFiles.Count) public function files in [$publicFunctionsPath]" { $publicFunctionFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $variablesPath = Join-Path -Path $Path -ChildPath 'variables' $variableFiles = (Test-Path -Path $variablesPath) ? (Get-ChildItem -Path $variablesPath -File -Filter '*.ps1' -Recurse) : $null LogGroup "Found $($variableFiles.Count) variable files in [$variablesPath]" { $variableFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $privateVariablesPath = Join-Path -Path $variablesPath -ChildPath 'private' @@ -63,7 +63,7 @@ BeforeAll { (Get-ChildItem -Path $privateVariablesPath -File -Filter '*.ps1' -Recurse) : $null LogGroup "Found $($privateVariableFiles.Count) private variable files in [$privateVariablesPath]" { $privateVariableFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $publicVariablesPath = Join-Path -Path $variablesPath -ChildPath 'public' @@ -71,14 +71,14 @@ BeforeAll { (Get-ChildItem -Path $publicVariablesPath -File -Filter '*.ps1' -Recurse) : $null LogGroup "Found $($publicVariableFiles.Count) public variable files in [$publicVariablesPath]" { $publicVariableFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $classPath = Join-Path -Path $Path -ChildPath 'classes' $classFiles = (Test-Path -Path $classPath) ? (Get-ChildItem -Path $classPath -File -Filter '*.ps1' -Recurse) : $null LogGroup "Found $($classFiles.Count) class files in [$classPath]" { $classFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $privateClassPath = Join-Path -Path $classPath -ChildPath 'private' @@ -86,7 +86,7 @@ BeforeAll { (Get-ChildItem -Path $privateClassPath -File -Filter '*.ps1' -Recurse) : $null LogGroup "Found $($privateClassFiles.Count) private class files in [$privateClassPath]" { $privateClassFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" } } $publicClassPath = Join-Path -Path $classPath -ChildPath 'public' @@ -94,7 +94,13 @@ BeforeAll { (Get-ChildItem -Path $publicClassPath -File -Filter '*.ps1' -Recurse) : $null LogGroup "Found $($publicClassFiles.Count) public class files in [$publicClassPath]" { $publicClassFiles | ForEach-Object { - Write-Verbose " - $($_.FullName)" -Verbose + Write-Host " - $($_.FullName)" + } + } + $testFiles = Get-ChildItem -Path $TestsPath -Include *.Tests.ps1 -Recurse -File + LogGroup "Found $($testFiles.Count) test files in [$TestsPath]" { + $testFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } } } From 378f649b6baa49716113a0ed690ee9759ca541ce Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 23:05:20 +0100 Subject: [PATCH 049/172] Add initial test module structure and resources --- .github/workflows/Action-Test-outputs.yml | 2 +- action.yml | 24 +----- scripts/main.ps1 | 25 ++++++ .../docs/PSModuleTest/Get-PSModuleTest.md | 0 .../docs/PSModuleTest/New-PSModuleTest.md | 0 .../docs/PSModuleTest/Set-PSModuleTest.md | 0 .../docs/PSModuleTest/Test-PSModuleTest.md | 0 .../modules/PSModuleTest/PSModuleTest.psd1 | 0 .../modules/PSModuleTest/PSModuleTest.psm1 | 0 .../PSModuleTest/assemblies/LsonLib.dll | Bin .../modules/PSModuleTest/data/Config.psd1 | 0 .../modules/PSModuleTest/data/Settings.psd1 | 0 .../formats/CultureInfo.Format.ps1xml | 0 .../formats/Mygciview.Format.ps1xml | 0 .../PSModuleTest/modules/OtherPSModule.psm1 | 0 .../modules/PSModuleTest/scripts/loader.ps1 | 0 .../types/DirectoryInfo.Types.ps1xml | 0 .../PSModuleTest/types/FileInfo.Types.ps1xml | 0 tests/srcTestRepo/README.md | 3 + tests/srcTestRepo/icon/icon.png | Bin 0 -> 5882 bytes tests/srcTestRepo/mkdocs.yml | 75 ++++++++++++++++++ .../src/assemblies/LsonLib.dll | Bin .../src/classes/private/SecretWriter.ps1 | 0 .../src/classes/public/Book.ps1 | 0 tests/{ => srcTestRepo}/src/data/Config.psd1 | 0 .../{ => srcTestRepo}/src/data/Settings.psd1 | 0 tests/{ => srcTestRepo}/src/finally.ps1 | 0 .../src/formats/CultureInfo.Format.ps1xml | 0 .../src/formats/Mygciview.Format.ps1xml | 0 .../private/Get-InternalPSModule.ps1 | 0 .../private/Set-InternalPSModule.ps1 | 0 .../public/PSModule/Get-PSModuleTest.ps1} | 9 ++- .../public/PSModule}/New-PSModuleTest.ps1 | 9 +-- .../src/functions/public/PSModule/PSModule.md | 1 + .../SomethingElse}/Set-PSModuleTest.ps1 | 0 .../public/SomethingElse/SomethingElse.md | 1 + .../functions/public/Test-PSModuleTest.ps1} | 4 +- .../src/functions/public/completers.ps1 | 0 tests/{ => srcTestRepo}/src/header.ps1 | 0 .../src/init/initializer.ps1 | 0 .../src/modules/OtherPSModule.psm1 | 0 .../{ => srcTestRepo}/src/scripts/loader.ps1 | 0 .../src/types/DirectoryInfo.Types.ps1xml | 0 .../src/types/FileInfo.Types.ps1xml | 0 .../variables/private/PrivateVariables.ps1 | 0 .../src/variables/public/Moons.ps1 | 0 .../src/variables/public/Planets.ps1 | 0 .../src/variables/public/SolarSystems.ps1 | 0 tests/srcTestRepo/tests/Environment.Tests.ps1 | 15 ++++ .../srcTestRepo/tests/PSModuleTest.Tests.ps1 | 44 ++++++++++ tests/srcWithManifestTestRepo/README.md | 3 + tests/srcWithManifestTestRepo/icon/icon.png | Bin 0 -> 5882 bytes tests/srcWithManifestTestRepo/mkdocs.yml | 75 ++++++++++++++++++ .../src}/assemblies/LsonLib.dll | Bin .../src}/classes/private/SecretWriter.ps1 | 0 .../src}/classes/public/Book.ps1 | 0 .../src}/data/Config.psd1 | 0 .../src}/data/Settings.psd1 | 0 .../src}/finally.ps1 | 0 .../src}/formats/CultureInfo.Format.ps1xml | 0 .../src}/formats/Mygciview.Format.ps1xml | 0 .../private/Get-InternalPSModule.ps1 | 0 .../private/Set-InternalPSModule.ps1 | 0 .../public/PSModule/Get-PSModuleTest.ps1} | 9 ++- .../public/PSModule}/New-PSModuleTest.ps1 | 9 +-- .../src/functions/public/PSModule/PSModule.md | 1 + .../SomethingElse}/Set-PSModuleTest.ps1 | 0 .../public/SomethingElse/SomethingElse.md | 1 + .../functions/public/Test-PSModuleTest.ps1} | 4 +- .../src/functions/public/completers.ps1 | 8 ++ .../src}/header.ps1 | 0 .../src}/init/initializer.ps1 | 0 .../src}/manifest.psd1 | 0 .../src}/modules/OtherPSModule.psm1 | 0 .../src}/scripts/loader.ps1 | 0 .../src}/types/DirectoryInfo.Types.ps1xml | 0 .../src}/types/FileInfo.Types.ps1xml | 0 .../variables/private/PrivateVariables.ps1 | 0 .../src}/variables/public/Moons.ps1 | 0 .../src}/variables/public/Planets.ps1 | 0 .../src}/variables/public/SolarSystems.ps1 | 0 .../tests/Environments/Environment.Tests.ps1 | 15 ++++ .../tests/MyTests/PSModuleTest.Tests.ps1 | 44 ++++++++++ .../srcWithManifestTestRepo/tools/1-build.ps1 | 1 + .../srcWithManifestTestRepo/tools/2-build.ps1 | 1 + tests/tests/PSModuleTest.Tests.ps1 | 11 --- 86 files changed, 339 insertions(+), 55 deletions(-) create mode 100644 scripts/main.ps1 rename tests/{ => outputTestRepo}/outputs/docs/PSModuleTest/Get-PSModuleTest.md (100%) rename tests/{ => outputTestRepo}/outputs/docs/PSModuleTest/New-PSModuleTest.md (100%) rename tests/{ => outputTestRepo}/outputs/docs/PSModuleTest/Set-PSModuleTest.md (100%) rename tests/{ => outputTestRepo}/outputs/docs/PSModuleTest/Test-PSModuleTest.md (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/PSModuleTest.psd1 (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/PSModuleTest.psm1 (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/assemblies/LsonLib.dll (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/data/Config.psd1 (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/data/Settings.psd1 (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/scripts/loader.ps1 (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml (100%) rename tests/{ => outputTestRepo}/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml (100%) create mode 100644 tests/srcTestRepo/README.md create mode 100644 tests/srcTestRepo/icon/icon.png create mode 100644 tests/srcTestRepo/mkdocs.yml rename tests/{ => srcTestRepo}/src/assemblies/LsonLib.dll (100%) rename tests/{ => srcTestRepo}/src/classes/private/SecretWriter.ps1 (100%) rename tests/{ => srcTestRepo}/src/classes/public/Book.ps1 (100%) rename tests/{ => srcTestRepo}/src/data/Config.psd1 (100%) rename tests/{ => srcTestRepo}/src/data/Settings.psd1 (100%) rename tests/{ => srcTestRepo}/src/finally.ps1 (100%) rename tests/{ => srcTestRepo}/src/formats/CultureInfo.Format.ps1xml (100%) rename tests/{ => srcTestRepo}/src/formats/Mygciview.Format.ps1xml (100%) rename tests/{ => srcTestRepo}/src/functions/private/Get-InternalPSModule.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/private/Set-InternalPSModule.ps1 (100%) rename tests/{srcWithManifest/functions/public/Test-PSModuleTest.ps1 => srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1} (52%) rename tests/{srcWithManifest/functions/public => srcTestRepo/src/functions/public/PSModule}/New-PSModuleTest.ps1 (81%) create mode 100644 tests/srcTestRepo/src/functions/public/PSModule/PSModule.md rename tests/{src/functions/public => srcTestRepo/src/functions/public/SomethingElse}/Set-PSModuleTest.ps1 (100%) create mode 100644 tests/srcTestRepo/src/functions/public/SomethingElse/SomethingElse.md rename tests/{src/functions/public/Get-PSModuleTest.ps1 => srcTestRepo/src/functions/public/Test-PSModuleTest.ps1} (83%) rename tests/{ => srcTestRepo}/src/functions/public/completers.ps1 (100%) rename tests/{ => srcTestRepo}/src/header.ps1 (100%) rename tests/{ => srcTestRepo}/src/init/initializer.ps1 (100%) rename tests/{ => srcTestRepo}/src/modules/OtherPSModule.psm1 (100%) rename tests/{ => srcTestRepo}/src/scripts/loader.ps1 (100%) rename tests/{ => srcTestRepo}/src/types/DirectoryInfo.Types.ps1xml (100%) rename tests/{ => srcTestRepo}/src/types/FileInfo.Types.ps1xml (100%) rename tests/{ => srcTestRepo}/src/variables/private/PrivateVariables.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/Moons.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/Planets.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/SolarSystems.ps1 (100%) create mode 100644 tests/srcTestRepo/tests/Environment.Tests.ps1 create mode 100644 tests/srcTestRepo/tests/PSModuleTest.Tests.ps1 create mode 100644 tests/srcWithManifestTestRepo/README.md create mode 100644 tests/srcWithManifestTestRepo/icon/icon.png create mode 100644 tests/srcWithManifestTestRepo/mkdocs.yml rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/assemblies/LsonLib.dll (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/classes/private/SecretWriter.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/classes/public/Book.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/data/Config.psd1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/data/Settings.psd1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/finally.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/formats/CultureInfo.Format.ps1xml (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/formats/Mygciview.Format.ps1xml (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/private/Get-InternalPSModule.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/functions/private/Set-InternalPSModule.ps1 (100%) rename tests/{src/functions/public/Test-PSModuleTest.ps1 => srcWithManifestTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1} (52%) rename tests/{src/functions/public => srcWithManifestTestRepo/src/functions/public/PSModule}/New-PSModuleTest.ps1 (81%) create mode 100644 tests/srcWithManifestTestRepo/src/functions/public/PSModule/PSModule.md rename tests/{srcWithManifest/functions/public => srcWithManifestTestRepo/src/functions/public/SomethingElse}/Set-PSModuleTest.ps1 (100%) create mode 100644 tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/SomethingElse.md rename tests/{srcWithManifest/functions/public/Get-PSModuleTest.ps1 => srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1} (83%) create mode 100644 tests/srcWithManifestTestRepo/src/functions/public/completers.ps1 rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/header.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/init/initializer.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/manifest.psd1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/modules/OtherPSModule.psm1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/scripts/loader.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/types/DirectoryInfo.Types.ps1xml (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/types/FileInfo.Types.ps1xml (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/variables/private/PrivateVariables.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/variables/public/Moons.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/variables/public/Planets.ps1 (100%) rename tests/{srcWithManifest => srcWithManifestTestRepo/src}/variables/public/SolarSystems.ps1 (100%) create mode 100644 tests/srcWithManifestTestRepo/tests/Environments/Environment.Tests.ps1 create mode 100644 tests/srcWithManifestTestRepo/tests/MyTests/PSModuleTest.Tests.ps1 create mode 100644 tests/srcWithManifestTestRepo/tools/1-build.ps1 create mode 100644 tests/srcWithManifestTestRepo/tools/2-build.ps1 delete mode 100644 tests/tests/PSModuleTest.Tests.ps1 diff --git a/.github/workflows/Action-Test-outputs.yml b/.github/workflows/Action-Test-outputs.yml index 8d116b68..0406a4c7 100644 --- a/.github/workflows/Action-Test-outputs.yml +++ b/.github/workflows/Action-Test-outputs.yml @@ -36,7 +36,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} with: Name: PSModuleTest - Path: tests/outputs/modules + Path: tests/outputTestRepo TestType: Module OS: ${{ matrix.os }} diff --git a/action.yml b/action.yml index 16de54d0..6c92df17 100644 --- a/action.yml +++ b/action.yml @@ -10,8 +10,9 @@ inputs: description: The name of the module to test. The name of the repository is used if not specified. required: false Path: - description: The path to the code to test. + description: The path to the repo. required: true + default: ${{ github.workspace }} TestType: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true @@ -51,26 +52,7 @@ runs: GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType: ${{ inputs.TestType }} GITHUB_ACTION_INPUT_TEST_PSMODULE_OS: ${{ inputs.OS }} with: - Script: | - # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. - Write-Host "Test type: [$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType]" - $codePath = switch($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType) { - 'Module' { - Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name" | Select-Object -ExpandProperty Path - } - 'SourceCode' { - Resolve-Path -Path $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path - } - default { - throw "Invalid test type: [$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType]" - } - } - Write-Host "Path to code: [$codePath]" - Set-GitHubOutput -Name CodePath -Value $codePath - - $testPath = Resolve-Path -Path "${{ github.action_path }}/scripts/tests/${{ inputs.TestType }}" | Select-Object -ExpandProperty Path - Write-Host "Path to tests: [$testPath]" - Set-GitHubOutput -Name TestPath -Value $testPath + Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester uses: PSModule/Invoke-Pester@fix diff --git a/scripts/main.ps1 b/scripts/main.ps1 new file mode 100644 index 00000000..ff171b11 --- /dev/null +++ b/scripts/main.ps1 @@ -0,0 +1,25 @@ +# If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. +$moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name +$testType = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType +$testPath = Resolve-Path -Path "$PSScriptRoot/tests/$testType" | Select-Object -ExpandProperty Path +$codePath = switch ($testType) { + 'Module' { + Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path + } + 'SourceCode' { + Resolve-Path -Path $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src | Select-Object -ExpandProperty Path + } + default { + throw "Invalid test type: [$testType]" + } +} + +[pscustomobject]@{ + ModuleName = $moduleName + TestType = $testType + CodePath = $codePath + TestPath = $testPath +} | Format-List -AutoSize + +Set-GitHubOutput -Name CodePath -Value $codePath +Set-GitHubOutput -Name TestPath -Value $testPath diff --git a/tests/outputs/docs/PSModuleTest/Get-PSModuleTest.md b/tests/outputTestRepo/outputs/docs/PSModuleTest/Get-PSModuleTest.md similarity index 100% rename from tests/outputs/docs/PSModuleTest/Get-PSModuleTest.md rename to tests/outputTestRepo/outputs/docs/PSModuleTest/Get-PSModuleTest.md diff --git a/tests/outputs/docs/PSModuleTest/New-PSModuleTest.md b/tests/outputTestRepo/outputs/docs/PSModuleTest/New-PSModuleTest.md similarity index 100% rename from tests/outputs/docs/PSModuleTest/New-PSModuleTest.md rename to tests/outputTestRepo/outputs/docs/PSModuleTest/New-PSModuleTest.md diff --git a/tests/outputs/docs/PSModuleTest/Set-PSModuleTest.md b/tests/outputTestRepo/outputs/docs/PSModuleTest/Set-PSModuleTest.md similarity index 100% rename from tests/outputs/docs/PSModuleTest/Set-PSModuleTest.md rename to tests/outputTestRepo/outputs/docs/PSModuleTest/Set-PSModuleTest.md diff --git a/tests/outputs/docs/PSModuleTest/Test-PSModuleTest.md b/tests/outputTestRepo/outputs/docs/PSModuleTest/Test-PSModuleTest.md similarity index 100% rename from tests/outputs/docs/PSModuleTest/Test-PSModuleTest.md rename to tests/outputTestRepo/outputs/docs/PSModuleTest/Test-PSModuleTest.md diff --git a/tests/outputs/modules/PSModuleTest/PSModuleTest.psd1 b/tests/outputTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psd1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/PSModuleTest.psd1 rename to tests/outputTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psd1 diff --git a/tests/outputs/modules/PSModuleTest/PSModuleTest.psm1 b/tests/outputTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psm1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/PSModuleTest.psm1 rename to tests/outputTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psm1 diff --git a/tests/outputs/modules/PSModuleTest/assemblies/LsonLib.dll b/tests/outputTestRepo/outputs/modules/PSModuleTest/assemblies/LsonLib.dll similarity index 100% rename from tests/outputs/modules/PSModuleTest/assemblies/LsonLib.dll rename to tests/outputTestRepo/outputs/modules/PSModuleTest/assemblies/LsonLib.dll diff --git a/tests/outputs/modules/PSModuleTest/data/Config.psd1 b/tests/outputTestRepo/outputs/modules/PSModuleTest/data/Config.psd1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/data/Config.psd1 rename to tests/outputTestRepo/outputs/modules/PSModuleTest/data/Config.psd1 diff --git a/tests/outputs/modules/PSModuleTest/data/Settings.psd1 b/tests/outputTestRepo/outputs/modules/PSModuleTest/data/Settings.psd1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/data/Settings.psd1 rename to tests/outputTestRepo/outputs/modules/PSModuleTest/data/Settings.psd1 diff --git a/tests/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml b/tests/outputTestRepo/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml rename to tests/outputTestRepo/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml diff --git a/tests/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml b/tests/outputTestRepo/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml rename to tests/outputTestRepo/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml diff --git a/tests/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 b/tests/outputTestRepo/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 rename to tests/outputTestRepo/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 diff --git a/tests/outputs/modules/PSModuleTest/scripts/loader.ps1 b/tests/outputTestRepo/outputs/modules/PSModuleTest/scripts/loader.ps1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/scripts/loader.ps1 rename to tests/outputTestRepo/outputs/modules/PSModuleTest/scripts/loader.ps1 diff --git a/tests/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml b/tests/outputTestRepo/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml rename to tests/outputTestRepo/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml diff --git a/tests/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml b/tests/outputTestRepo/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml rename to tests/outputTestRepo/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml diff --git a/tests/srcTestRepo/README.md b/tests/srcTestRepo/README.md new file mode 100644 index 00000000..b459e352 --- /dev/null +++ b/tests/srcTestRepo/README.md @@ -0,0 +1,3 @@ +# Test module + +This is a test readme. diff --git a/tests/srcTestRepo/icon/icon.png b/tests/srcTestRepo/icon/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..be83fd5fd3914846c735d44415569b86c254ccad GIT binary patch literal 5882 zcmX9?dpy(c7oQBnHlr{aVJ<}&ks^v^LfrW&q;8wvw#Um3V=W$n3W~Y5d`9b?L81) zU`A8~0|8!KA&wTNpch|JQvd<>H?cJVfhyAk|DNXoXnvBVTL=gQXYM^*Emul?K_Ia- zE1ZebO|RLXVWCbJ9<(f$+?~;P`-E$RiMrEfL2^Mp>!nfVJpRSoLfK6*Mb}kIEx;!3 zV&V<~CO?Xf(oWk`M!60Q8b@Tky@skO)^r=&VJo{odrPC&CrYl>wToj|-e6B3mgJY^+ zADmA!fLi@l*gJuSUE^t#jV%kaecbD^8_T9?0TDXXZAagx{{`+u=NhI%a= z1j+DBhlPC#zuCPd`SaZs@0#fsAIQ^{iMo=1gDEEiB@ReR$n=51lck3SPQU)D<((pa@K+~(`cxB1`iZ%soHe0=%^S)3N>y}KBI5$QwUuNAAhy~5e(vjemgZ6DyYwYAmVnZq;} zkgC$lJb>v5}Q=o!(uED{p@13vWGw&xt9Q5JQ; z+@DbF(@m|9^l!|0RS`4J>YnZ=F6bsp>0hr6H1JZq3o;II!Q3n|UR_-^&Qq#J$J+Om1Cm=kVumR7Fzop!i@W#d+dJB%Zl~m#; zu%@fCOPibY?zaDfzfD6dvgn#HQB%oBR)oHNLk8m0^Sm>@kU0zWa|f355bAeSCSd5mFFU!%GRX zK6Q$l0BxCK74fZ3_odm*tsng3mTrFAtt~5a{PFiKzh|XE#q(d%y6QV#cC(**Of7Jj zqc8V$Poa{Fi;ER;=;Wcgi0&)qKTRoiox&5l9pWmifFS;^=qrO}4_(>?sNi;b1O{orJ)sphI!dV7-nAgW zd6&0OXzjkr)0)c*V}N3HZ6H(_t0F5at80AQuj>d;0O9c^HLOb7T<$L9*YDqnqFoaC zOpF4ueS_%h=l3lx;mna^z3MKbV?7O8H9JEC5ZdohLtul(iZuSPjaY3z9h;8Uhr4mA zeFPc`RrXUD$*Ij@6OSyIonQCAZX7X_p24p8T*TaGu{PdKTQ?o9tQhM`YGdG=&Bv0D zeJ!Y0$RXUlSvzKo?eP!C+^=M{9*nF*>hf_M4w8ilfm&))-L}cO7ieg8^~woHnfeVq zC>Y(?Ph3gt)|RM*JVHIXEk%>FsUfL|n46=uwX?sS8LaaV)rV`#AeA&VB?AKHW;MUR zx`BewauLZ3$;nikmM8y>*CZrTnwy(PA_%SfIO&39mWGdg++2UOQ}Q@MuO*gL4P#8^ zzGrRx_0-6;=!~4f4#wee&Hco{fmbJ!$H`JOeMEAr#K9EL57$}#`ejWvYI|1XQt-Hz zeqzNtS3|VF{1z zRE-&?2F^mP%?y|cN@we%)(Qn0gb#wzhKQ8o2zZn%a*;wr(U^;kC*F5nl|ivgFr$Jj zh|l~`9Xpkq)5S#=j*d6icM`C;b!+C3!qa15v<4ytet3UsgufiB#RMb5$C`{2;2bu= zrpDss#puFZab{8w^HEtzVN>il4Ugq!#qVp7RR=S5lN z&d$ydY7!y^3;2`Cz=k`$=q%TO(S?ZmIFy(2Fw(i{!WP%DaJHp%YFo6U8VW)^ z0RYBG3)fJZv@!Xn28NP>Ff>d?l0SyjDCDJ(AwhFSLe*9f>ExlkI%Q~&~NGhm&=emY0)3{w~aMnG@NN~#@G zMWLXBr|8FVX8W#Vm7lG``N)NQI5QDcD$jBc#NzbnjI#+Sa-k5;Ozv46MO`;d5iraP z0c)ESgM-bC;;C^xx=vGAU@{K@vwDh1oztBK^mK{SWi{X}`$PP{?J{A6lZKpzSo|c6 zm3}TPER57rXo{`5F`tS@f>;hQ%D_=wf?C_#TVS+k#KWf9B%6nunCz^qc+oCldLcrz zfmP(8*b(k)*ifi}Gt+n$=d(6wgho9u)jCkzSZM9VYp~EYmi6$Vii@#$Je58}$~uKg z9VH)q5c;oZe0{q~U=mP+r1=z%bC8jC8YxoxF73vA@zhZ#NXtj>Yqm~0)vIZ0aZWB*ELrXn?c95VK%EDV3!j^6q`JaA^+ymIQA>s8Sf<1t^WaeVp4R%7#wq|!` z6U2#1BnGyo%ZAQI|1G)yejcwKl+(vWFFXP_pW5IbUk-0f++K6-O%N`Hvbwsu3e5s) zeHr-d;pn601)4asW2oeZ)-88jU*Rj#jLfw{V~E7@zssE^jw;AkvzW6ddxf{=KFkAl z0BXpTtKGJb9p^Cpmo9k;)K6hbg;-rNGmOJVP8OH?UWguZkfIl2fmD^}@mKs}VAi@> zzKmWxwZRF}{LHzGIM$p(;MFtMI`G&OGqf4Xr|R+6rhU)dWPssA{%moH-*Cd6d`VzW zimWkW?YTHxTU!E8D4BTJx4+^%gtr>basc!B3|2oJH>6cg<*#&&^Fye=5ip)okz}{^ zK~ta@b8@8}><*<8E$7IBY7UCXwKqthdV-N`Z^^7%1R51XAR zF$rd+XDKu88*H+#zg!C>5{?U9G# zsq#Ji%?U~d=-Z@8E>`*{AOU9co4cwHnqq-ns!pb8__d!!lh2!Bd#J=}%iH+!e+yr# zd6`sFsUVA#0B8)Ef6o8m9+7R9KLMFj)oBt1#ZQ4T3& zm!Y&L$}8TSOv0F_NvGgLxf*1ZaA+&VFzQ0jmE$#cX!2}?-`s+BjT*G@h48K3Vr7TEW`=| z;g>9{9=8{M2RE=yh4ZPIM&@@JnAayZ$+65@k^dV@Fg~n_gZ-DuaD~Hg{6=lY#28aQ)?UcDJU5lQC)^ z{{}19U6WhYJK|kFIX%KbuPh}_OaVS4T~kszh#SK~%x`XPZmxW)Eg>$vwA-)pd*l4D zYsYXqfL#gES~_ zxAF%JHbQ(feTo?3JLhh7%s1K?2Jui*>My_QpkUUX%+zQ;i6Wc&E2 zA7*K3X)@EqKS?4k^Ov~ZBaQEd}_4@VovVUt&vlw`z%iBg871r0X_J!L#k?iwT~^a6A;v#2if7!4o$v{&av(2Ncec1(5wFk zOnH9pedb!0YobJz^Np%lF;(}yJ1(K=MDs}|ocH6owXrm#Z_AxVO7(Y;sN@#^(*00& zf4`;u*ZibTD8J9tsQ=UmgTnAepJ8$iVo4+1gz~z#jEc)cwK?HyQr7-!GiolQ7ESp6 z>$BfQYYm3BHW4ZdOH_Lzt09aawiPz|GV6fu{9QY6erMmsc02Sr4Dw%)-i-|mFWiM{r|Upj+M}eSyTvhe?%J?0@si~5DHX-6;z?cWa`<)4eS7N*QM48KTy6&+jRokq4 zinG|8C52I1dVW@`4`u$W4C|Emk9 z7Rvetc1lYh>grVOoOQ8E>xhc?y2-h17tM`PK%rpIjgB7qhDWIb)x3F%c^v&KBJkU)l075{`8g= z?GA7r%5E-SzV>)ksk})tdF)Z}=Oc_80i$VpmPh{B4oEx=t$21?%aDS6?D%-m{rRLT>RI8|(v^VW`Y6V~{J;I8dNi{iK;xp} z(F&N9_=3~5rUHDm@k-(;g~FTVfew zjCuYpKmC$jWNiU_&0c6bE!9vMsD*$!WWYHNnvy7JJxP!O5*^?;tPaWlqBC@0O=H&f zAf17}tEEWzV>*K|VkQFS4lTHd%}U@UbLly1psaBeN~KQ=9L!x+?2au?qe?+@SHO>+ z9)LeB0#pNOiB<)u{)AJGGy4oI5U)AFl=alYBCEgcw^0hg7AFFTT^?@CqjFBVqU2hg zJcRd?x-XP=fK@TCV1fbJ$$MbWr2*QybaNUw7lGx*w6=-B`vAj0ID0CoS_B5>mbo4T zTsQ#nAkPUuEGh+HM;Ha&W>)S^El!wYv68lh=SLT^^B}y&goWkLjCB+YXfxQG4ogbh zqjJl8ojG#{&8Y}y&Ai!_?IlRxfbhnIpad+q59Q4Wq>KS>A>~P>;ugc}Xd4UT9vW!} zf##4w0+iO9^eFP?k~cwG96)SuY~G6}ZS3rJ*0B#YR!svPh%k9M6kBmDNGM-R!su4y zdu??A)fQd`DE&-uuqIHkC%DZ-8hSHpu1z~`=JFmYsg+~X6IbInkmARWeqyNSw@h$8~HkN zGgw1VS5dP4+2=PvBT-3XN8%s%!Ykz%uZ^&d32eh{=KQ*jpRaE&=|wkMI!)tz1Nh?Q z%a`9$4fB35Ml3*G_KuE@3;QtjK}lhCL&n#yzg^$(c?PQO1A$QuTfx{0mnZNv@zN zUG}`%B%1Hy>2>wC zwMdixdD_F{hYA8RLgFz#ABoM(&VHkcMvvvXdL{fdU%#KX(dT(X%Gt%mrMI{Dg2$Og zZe!We-i*&PGc)AgGS{Tu)@xJz(Y?;D8KSArwzjrrfTkb7Lx}X!)Ye{g2nq_iRZNrP zH2zBXI-y@qD!)P`BK@K+$jN|$NA~BowY6!p`y!^MrqFaOU?+8~*R!=U*H&({)9+C?VdMIMm`4{L{ OgRD;4;a-^H$^Qd{UB>JH literal 0 HcmV?d00001 diff --git a/tests/srcTestRepo/mkdocs.yml b/tests/srcTestRepo/mkdocs.yml new file mode 100644 index 00000000..df5e17ad --- /dev/null +++ b/tests/srcTestRepo/mkdocs.yml @@ -0,0 +1,75 @@ +site_name: -{{ REPO_NAME }}- +theme: + name: material + language: en + font: + text: Roboto + code: Sono + logo: Assets/icon.png + favicon: Assets/icon.png + palette: + # Palette toggle for automatic mode + - media: "(prefers-color-scheme)" + toggle: + icon: material/link + name: Switch to dark mode + # Palette toggle for dark mode + - media: '(prefers-color-scheme: dark)' + scheme: slate + toggle: + primary: black + accent: green + icon: material/toggle-switch-off-outline + name: Switch to light mode + # Palette toggle for light mode + - media: '(prefers-color-scheme: light)' + scheme: default + toggle: + primary: indigo + accent: green + icon: material/toggle-switch + name: Switch to system preference + icon: + repo: material/github + features: + - navigation.instant + - navigation.instant.progress + - navigation.indexes + - navigation.top + - navigation.tracking + - navigation.expand + - search.suggest + - search.highlight + +repo_name: -{{ REPO_OWNER }}-/-{{ REPO_NAME }}- +repo_url: https://github.com/-{{ REPO_OWNER }}-/-{{ REPO_NAME }}- + +plugins: + - search + +markdown_extensions: + - toc: + permalink: true # Adds a link icon to headings + - attr_list + - admonition + - md_in_html + - pymdownx.details # Enables collapsible admonitions + +extra: + social: + - icon: fontawesome/brands/discord + link: https://discord.gg/jedJWCPAhD + name: -{{ REPO_OWNER }}- on Discord + - icon: fontawesome/brands/github + link: https://github.com/-{{ REPO_OWNER }}-/ + name: -{{ REPO_OWNER }}- on GitHub + consent: + title: Cookie consent + description: >- + We use cookies to recognize your repeated visits and preferences, as well + as to measure the effectiveness of our documentation and whether users + find what they're searching for. With your consent, you're helping us to + make our documentation better. + actions: + - accept + - reject diff --git a/tests/src/assemblies/LsonLib.dll b/tests/srcTestRepo/src/assemblies/LsonLib.dll similarity index 100% rename from tests/src/assemblies/LsonLib.dll rename to tests/srcTestRepo/src/assemblies/LsonLib.dll diff --git a/tests/src/classes/private/SecretWriter.ps1 b/tests/srcTestRepo/src/classes/private/SecretWriter.ps1 similarity index 100% rename from tests/src/classes/private/SecretWriter.ps1 rename to tests/srcTestRepo/src/classes/private/SecretWriter.ps1 diff --git a/tests/src/classes/public/Book.ps1 b/tests/srcTestRepo/src/classes/public/Book.ps1 similarity index 100% rename from tests/src/classes/public/Book.ps1 rename to tests/srcTestRepo/src/classes/public/Book.ps1 diff --git a/tests/src/data/Config.psd1 b/tests/srcTestRepo/src/data/Config.psd1 similarity index 100% rename from tests/src/data/Config.psd1 rename to tests/srcTestRepo/src/data/Config.psd1 diff --git a/tests/src/data/Settings.psd1 b/tests/srcTestRepo/src/data/Settings.psd1 similarity index 100% rename from tests/src/data/Settings.psd1 rename to tests/srcTestRepo/src/data/Settings.psd1 diff --git a/tests/src/finally.ps1 b/tests/srcTestRepo/src/finally.ps1 similarity index 100% rename from tests/src/finally.ps1 rename to tests/srcTestRepo/src/finally.ps1 diff --git a/tests/src/formats/CultureInfo.Format.ps1xml b/tests/srcTestRepo/src/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/src/formats/CultureInfo.Format.ps1xml rename to tests/srcTestRepo/src/formats/CultureInfo.Format.ps1xml diff --git a/tests/src/formats/Mygciview.Format.ps1xml b/tests/srcTestRepo/src/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/src/formats/Mygciview.Format.ps1xml rename to tests/srcTestRepo/src/formats/Mygciview.Format.ps1xml diff --git a/tests/src/functions/private/Get-InternalPSModule.ps1 b/tests/srcTestRepo/src/functions/private/Get-InternalPSModule.ps1 similarity index 100% rename from tests/src/functions/private/Get-InternalPSModule.ps1 rename to tests/srcTestRepo/src/functions/private/Get-InternalPSModule.ps1 diff --git a/tests/src/functions/private/Set-InternalPSModule.ps1 b/tests/srcTestRepo/src/functions/private/Set-InternalPSModule.ps1 similarity index 100% rename from tests/src/functions/private/Set-InternalPSModule.ps1 rename to tests/srcTestRepo/src/functions/private/Set-InternalPSModule.ps1 diff --git a/tests/srcWithManifest/functions/public/Test-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 similarity index 52% rename from tests/srcWithManifest/functions/public/Test-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 index 4056e2f6..57257f1d 100644 --- a/tests/srcWithManifest/functions/public/Test-PSModuleTest.ps1 +++ b/tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 @@ -1,5 +1,9 @@ -#SkipTest:Verbose:Just want to test that a function can have multiple skips. -function Test-PSModuleTest { +#Requires -Modules Utilities +#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.1.4' } +#Requires -Modules @{ ModuleName = 'DynamicParams'; ModuleVersion = '1.1.8' } +#Requires -Modules @{ ModuleName = 'Store'; ModuleVersion = '0.3.1' } + +function Get-PSModuleTest { <# .SYNOPSIS Performs tests on a module. @@ -16,5 +20,4 @@ function Test-PSModuleTest { [string] $Name ) Write-Output "Hello, $Name!" - Write-Verbose 'Verbose message' -Verbose } diff --git a/tests/srcWithManifest/functions/public/New-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 similarity index 81% rename from tests/srcWithManifest/functions/public/New-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 index 8fc0641f..5fa16bc3 100644 --- a/tests/srcWithManifest/functions/public/New-PSModuleTest.ps1 +++ b/tests/srcTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 @@ -1,6 +1,5 @@ -#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'} -#SkipTest:FunctionTest:Difficult to test due to the nature of the function. -#SkipTest:Verbose:Just want to test that a function can have multiple skips. +#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.1.4'} + function New-PSModuleTest { <# .SYNOPSIS @@ -28,11 +27,11 @@ function New-PSModuleTest { [Parameter(Mandatory)] [string] $Name ) - Write-Debug "Debug message" - Write-Verbose "Verbose message" -Verbose Write-Output "Hello, $Name!" } New-Alias New-PSModuleTestAlias3 New-PSModuleTest New-Alias -Name New-PSModuleTestAlias4 -Value New-PSModuleTest + + Set-Alias New-PSModuleTestAlias5 New-PSModuleTest diff --git a/tests/srcTestRepo/src/functions/public/PSModule/PSModule.md b/tests/srcTestRepo/src/functions/public/PSModule/PSModule.md new file mode 100644 index 00000000..79741cf4 --- /dev/null +++ b/tests/srcTestRepo/src/functions/public/PSModule/PSModule.md @@ -0,0 +1 @@ +# This is PSModule diff --git a/tests/src/functions/public/Set-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 similarity index 100% rename from tests/src/functions/public/Set-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 diff --git a/tests/srcTestRepo/src/functions/public/SomethingElse/SomethingElse.md b/tests/srcTestRepo/src/functions/public/SomethingElse/SomethingElse.md new file mode 100644 index 00000000..d9f7e9ee --- /dev/null +++ b/tests/srcTestRepo/src/functions/public/SomethingElse/SomethingElse.md @@ -0,0 +1 @@ +# This is SomethingElse diff --git a/tests/src/functions/public/Get-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/Test-PSModuleTest.ps1 similarity index 83% rename from tests/src/functions/public/Get-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/Test-PSModuleTest.ps1 index 0e9aacfe..26be2b9b 100644 --- a/tests/src/functions/public/Get-PSModuleTest.ps1 +++ b/tests/srcTestRepo/src/functions/public/Test-PSModuleTest.ps1 @@ -1,6 +1,4 @@ -#Requires -Modules Utilities - -function Get-PSModuleTest { +function Test-PSModuleTest { <# .SYNOPSIS Performs tests on a module. diff --git a/tests/src/functions/public/completers.ps1 b/tests/srcTestRepo/src/functions/public/completers.ps1 similarity index 100% rename from tests/src/functions/public/completers.ps1 rename to tests/srcTestRepo/src/functions/public/completers.ps1 diff --git a/tests/src/header.ps1 b/tests/srcTestRepo/src/header.ps1 similarity index 100% rename from tests/src/header.ps1 rename to tests/srcTestRepo/src/header.ps1 diff --git a/tests/src/init/initializer.ps1 b/tests/srcTestRepo/src/init/initializer.ps1 similarity index 100% rename from tests/src/init/initializer.ps1 rename to tests/srcTestRepo/src/init/initializer.ps1 diff --git a/tests/src/modules/OtherPSModule.psm1 b/tests/srcTestRepo/src/modules/OtherPSModule.psm1 similarity index 100% rename from tests/src/modules/OtherPSModule.psm1 rename to tests/srcTestRepo/src/modules/OtherPSModule.psm1 diff --git a/tests/src/scripts/loader.ps1 b/tests/srcTestRepo/src/scripts/loader.ps1 similarity index 100% rename from tests/src/scripts/loader.ps1 rename to tests/srcTestRepo/src/scripts/loader.ps1 diff --git a/tests/src/types/DirectoryInfo.Types.ps1xml b/tests/srcTestRepo/src/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/src/types/DirectoryInfo.Types.ps1xml rename to tests/srcTestRepo/src/types/DirectoryInfo.Types.ps1xml diff --git a/tests/src/types/FileInfo.Types.ps1xml b/tests/srcTestRepo/src/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/src/types/FileInfo.Types.ps1xml rename to tests/srcTestRepo/src/types/FileInfo.Types.ps1xml diff --git a/tests/src/variables/private/PrivateVariables.ps1 b/tests/srcTestRepo/src/variables/private/PrivateVariables.ps1 similarity index 100% rename from tests/src/variables/private/PrivateVariables.ps1 rename to tests/srcTestRepo/src/variables/private/PrivateVariables.ps1 diff --git a/tests/src/variables/public/Moons.ps1 b/tests/srcTestRepo/src/variables/public/Moons.ps1 similarity index 100% rename from tests/src/variables/public/Moons.ps1 rename to tests/srcTestRepo/src/variables/public/Moons.ps1 diff --git a/tests/src/variables/public/Planets.ps1 b/tests/srcTestRepo/src/variables/public/Planets.ps1 similarity index 100% rename from tests/src/variables/public/Planets.ps1 rename to tests/srcTestRepo/src/variables/public/Planets.ps1 diff --git a/tests/src/variables/public/SolarSystems.ps1 b/tests/srcTestRepo/src/variables/public/SolarSystems.ps1 similarity index 100% rename from tests/src/variables/public/SolarSystems.ps1 rename to tests/srcTestRepo/src/variables/public/SolarSystems.ps1 diff --git a/tests/srcTestRepo/tests/Environment.Tests.ps1 b/tests/srcTestRepo/tests/Environment.Tests.ps1 new file mode 100644 index 00000000..211be946 --- /dev/null +++ b/tests/srcTestRepo/tests/Environment.Tests.ps1 @@ -0,0 +1,15 @@ +Describe 'Environment Variables are available' { + It 'Should be available [<_>]' -ForEach @( + 'TEST_APP_ENT_CLIENT_ID', + 'TEST_APP_ENT_PRIVATE_KEY', + 'TEST_APP_ORG_CLIENT_ID', + 'TEST_APP_ORG_PRIVATE_KEY', + 'TEST_USER_ORG_FG_PAT', + 'TEST_USER_USER_FG_PAT', + 'TEST_USER_PAT' + ) { + $name = $_ + Write-Verbose "Environment variable: [$name]" -Verbose + Get-ChildItem env: | Where-Object { $_.Name -eq $name } | Should -Not -BeNullOrEmpty + } +} diff --git a/tests/srcTestRepo/tests/PSModuleTest.Tests.ps1 b/tests/srcTestRepo/tests/PSModuleTest.Tests.ps1 new file mode 100644 index 00000000..9bf1bb64 --- /dev/null +++ b/tests/srcTestRepo/tests/PSModuleTest.Tests.ps1 @@ -0,0 +1,44 @@ +[CmdletBinding()] +Param( + # Path to the module to test. + [Parameter()] + [string] $Path +) + +Write-Verbose "Path to the module: [$Path]" -Verbose +Describe 'PSModuleTest.Tests.ps1' { + Context 'Function: Test-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Test-PSModuleTest -Name 'World' | Out-String) -Verbose + Test-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: Get-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Get-PSModuleTest -Name 'World' | Out-String) -Verbose + Get-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: New-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (New-PSModuleTest -Name 'World' | Out-String) -Verbose + New-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: Set-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Set-PSModuleTest -Name 'World' | Out-String) -Verbose + Set-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Variables' { + It "Exports a variable for SolarSystems that contains 'Solar System'" { + Write-Verbose ($SolarSystems | Out-String) -Verbose + $SolarSystems[0].Name | Should -Be 'Solar System' + } + } +} diff --git a/tests/srcWithManifestTestRepo/README.md b/tests/srcWithManifestTestRepo/README.md new file mode 100644 index 00000000..b459e352 --- /dev/null +++ b/tests/srcWithManifestTestRepo/README.md @@ -0,0 +1,3 @@ +# Test module + +This is a test readme. diff --git a/tests/srcWithManifestTestRepo/icon/icon.png b/tests/srcWithManifestTestRepo/icon/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..be83fd5fd3914846c735d44415569b86c254ccad GIT binary patch literal 5882 zcmX9?dpy(c7oQBnHlr{aVJ<}&ks^v^LfrW&q;8wvw#Um3V=W$n3W~Y5d`9b?L81) zU`A8~0|8!KA&wTNpch|JQvd<>H?cJVfhyAk|DNXoXnvBVTL=gQXYM^*Emul?K_Ia- zE1ZebO|RLXVWCbJ9<(f$+?~;P`-E$RiMrEfL2^Mp>!nfVJpRSoLfK6*Mb}kIEx;!3 zV&V<~CO?Xf(oWk`M!60Q8b@Tky@skO)^r=&VJo{odrPC&CrYl>wToj|-e6B3mgJY^+ zADmA!fLi@l*gJuSUE^t#jV%kaecbD^8_T9?0TDXXZAagx{{`+u=NhI%a= z1j+DBhlPC#zuCPd`SaZs@0#fsAIQ^{iMo=1gDEEiB@ReR$n=51lck3SPQU)D<((pa@K+~(`cxB1`iZ%soHe0=%^S)3N>y}KBI5$QwUuNAAhy~5e(vjemgZ6DyYwYAmVnZq;} zkgC$lJb>v5}Q=o!(uED{p@13vWGw&xt9Q5JQ; z+@DbF(@m|9^l!|0RS`4J>YnZ=F6bsp>0hr6H1JZq3o;II!Q3n|UR_-^&Qq#J$J+Om1Cm=kVumR7Fzop!i@W#d+dJB%Zl~m#; zu%@fCOPibY?zaDfzfD6dvgn#HQB%oBR)oHNLk8m0^Sm>@kU0zWa|f355bAeSCSd5mFFU!%GRX zK6Q$l0BxCK74fZ3_odm*tsng3mTrFAtt~5a{PFiKzh|XE#q(d%y6QV#cC(**Of7Jj zqc8V$Poa{Fi;ER;=;Wcgi0&)qKTRoiox&5l9pWmifFS;^=qrO}4_(>?sNi;b1O{orJ)sphI!dV7-nAgW zd6&0OXzjkr)0)c*V}N3HZ6H(_t0F5at80AQuj>d;0O9c^HLOb7T<$L9*YDqnqFoaC zOpF4ueS_%h=l3lx;mna^z3MKbV?7O8H9JEC5ZdohLtul(iZuSPjaY3z9h;8Uhr4mA zeFPc`RrXUD$*Ij@6OSyIonQCAZX7X_p24p8T*TaGu{PdKTQ?o9tQhM`YGdG=&Bv0D zeJ!Y0$RXUlSvzKo?eP!C+^=M{9*nF*>hf_M4w8ilfm&))-L}cO7ieg8^~woHnfeVq zC>Y(?Ph3gt)|RM*JVHIXEk%>FsUfL|n46=uwX?sS8LaaV)rV`#AeA&VB?AKHW;MUR zx`BewauLZ3$;nikmM8y>*CZrTnwy(PA_%SfIO&39mWGdg++2UOQ}Q@MuO*gL4P#8^ zzGrRx_0-6;=!~4f4#wee&Hco{fmbJ!$H`JOeMEAr#K9EL57$}#`ejWvYI|1XQt-Hz zeqzNtS3|VF{1z zRE-&?2F^mP%?y|cN@we%)(Qn0gb#wzhKQ8o2zZn%a*;wr(U^;kC*F5nl|ivgFr$Jj zh|l~`9Xpkq)5S#=j*d6icM`C;b!+C3!qa15v<4ytet3UsgufiB#RMb5$C`{2;2bu= zrpDss#puFZab{8w^HEtzVN>il4Ugq!#qVp7RR=S5lN z&d$ydY7!y^3;2`Cz=k`$=q%TO(S?ZmIFy(2Fw(i{!WP%DaJHp%YFo6U8VW)^ z0RYBG3)fJZv@!Xn28NP>Ff>d?l0SyjDCDJ(AwhFSLe*9f>ExlkI%Q~&~NGhm&=emY0)3{w~aMnG@NN~#@G zMWLXBr|8FVX8W#Vm7lG``N)NQI5QDcD$jBc#NzbnjI#+Sa-k5;Ozv46MO`;d5iraP z0c)ESgM-bC;;C^xx=vGAU@{K@vwDh1oztBK^mK{SWi{X}`$PP{?J{A6lZKpzSo|c6 zm3}TPER57rXo{`5F`tS@f>;hQ%D_=wf?C_#TVS+k#KWf9B%6nunCz^qc+oCldLcrz zfmP(8*b(k)*ifi}Gt+n$=d(6wgho9u)jCkzSZM9VYp~EYmi6$Vii@#$Je58}$~uKg z9VH)q5c;oZe0{q~U=mP+r1=z%bC8jC8YxoxF73vA@zhZ#NXtj>Yqm~0)vIZ0aZWB*ELrXn?c95VK%EDV3!j^6q`JaA^+ymIQA>s8Sf<1t^WaeVp4R%7#wq|!` z6U2#1BnGyo%ZAQI|1G)yejcwKl+(vWFFXP_pW5IbUk-0f++K6-O%N`Hvbwsu3e5s) zeHr-d;pn601)4asW2oeZ)-88jU*Rj#jLfw{V~E7@zssE^jw;AkvzW6ddxf{=KFkAl z0BXpTtKGJb9p^Cpmo9k;)K6hbg;-rNGmOJVP8OH?UWguZkfIl2fmD^}@mKs}VAi@> zzKmWxwZRF}{LHzGIM$p(;MFtMI`G&OGqf4Xr|R+6rhU)dWPssA{%moH-*Cd6d`VzW zimWkW?YTHxTU!E8D4BTJx4+^%gtr>basc!B3|2oJH>6cg<*#&&^Fye=5ip)okz}{^ zK~ta@b8@8}><*<8E$7IBY7UCXwKqthdV-N`Z^^7%1R51XAR zF$rd+XDKu88*H+#zg!C>5{?U9G# zsq#Ji%?U~d=-Z@8E>`*{AOU9co4cwHnqq-ns!pb8__d!!lh2!Bd#J=}%iH+!e+yr# zd6`sFsUVA#0B8)Ef6o8m9+7R9KLMFj)oBt1#ZQ4T3& zm!Y&L$}8TSOv0F_NvGgLxf*1ZaA+&VFzQ0jmE$#cX!2}?-`s+BjT*G@h48K3Vr7TEW`=| z;g>9{9=8{M2RE=yh4ZPIM&@@JnAayZ$+65@k^dV@Fg~n_gZ-DuaD~Hg{6=lY#28aQ)?UcDJU5lQC)^ z{{}19U6WhYJK|kFIX%KbuPh}_OaVS4T~kszh#SK~%x`XPZmxW)Eg>$vwA-)pd*l4D zYsYXqfL#gES~_ zxAF%JHbQ(feTo?3JLhh7%s1K?2Jui*>My_QpkUUX%+zQ;i6Wc&E2 zA7*K3X)@EqKS?4k^Ov~ZBaQEd}_4@VovVUt&vlw`z%iBg871r0X_J!L#k?iwT~^a6A;v#2if7!4o$v{&av(2Ncec1(5wFk zOnH9pedb!0YobJz^Np%lF;(}yJ1(K=MDs}|ocH6owXrm#Z_AxVO7(Y;sN@#^(*00& zf4`;u*ZibTD8J9tsQ=UmgTnAepJ8$iVo4+1gz~z#jEc)cwK?HyQr7-!GiolQ7ESp6 z>$BfQYYm3BHW4ZdOH_Lzt09aawiPz|GV6fu{9QY6erMmsc02Sr4Dw%)-i-|mFWiM{r|Upj+M}eSyTvhe?%J?0@si~5DHX-6;z?cWa`<)4eS7N*QM48KTy6&+jRokq4 zinG|8C52I1dVW@`4`u$W4C|Emk9 z7Rvetc1lYh>grVOoOQ8E>xhc?y2-h17tM`PK%rpIjgB7qhDWIb)x3F%c^v&KBJkU)l075{`8g= z?GA7r%5E-SzV>)ksk})tdF)Z}=Oc_80i$VpmPh{B4oEx=t$21?%aDS6?D%-m{rRLT>RI8|(v^VW`Y6V~{J;I8dNi{iK;xp} z(F&N9_=3~5rUHDm@k-(;g~FTVfew zjCuYpKmC$jWNiU_&0c6bE!9vMsD*$!WWYHNnvy7JJxP!O5*^?;tPaWlqBC@0O=H&f zAf17}tEEWzV>*K|VkQFS4lTHd%}U@UbLly1psaBeN~KQ=9L!x+?2au?qe?+@SHO>+ z9)LeB0#pNOiB<)u{)AJGGy4oI5U)AFl=alYBCEgcw^0hg7AFFTT^?@CqjFBVqU2hg zJcRd?x-XP=fK@TCV1fbJ$$MbWr2*QybaNUw7lGx*w6=-B`vAj0ID0CoS_B5>mbo4T zTsQ#nAkPUuEGh+HM;Ha&W>)S^El!wYv68lh=SLT^^B}y&goWkLjCB+YXfxQG4ogbh zqjJl8ojG#{&8Y}y&Ai!_?IlRxfbhnIpad+q59Q4Wq>KS>A>~P>;ugc}Xd4UT9vW!} zf##4w0+iO9^eFP?k~cwG96)SuY~G6}ZS3rJ*0B#YR!svPh%k9M6kBmDNGM-R!su4y zdu??A)fQd`DE&-uuqIHkC%DZ-8hSHpu1z~`=JFmYsg+~X6IbInkmARWeqyNSw@h$8~HkN zGgw1VS5dP4+2=PvBT-3XN8%s%!Ykz%uZ^&d32eh{=KQ*jpRaE&=|wkMI!)tz1Nh?Q z%a`9$4fB35Ml3*G_KuE@3;QtjK}lhCL&n#yzg^$(c?PQO1A$QuTfx{0mnZNv@zN zUG}`%B%1Hy>2>wC zwMdixdD_F{hYA8RLgFz#ABoM(&VHkcMvvvXdL{fdU%#KX(dT(X%Gt%mrMI{Dg2$Og zZe!We-i*&PGc)AgGS{Tu)@xJz(Y?;D8KSArwzjrrfTkb7Lx}X!)Ye{g2nq_iRZNrP zH2zBXI-y@qD!)P`BK@K+$jN|$NA~BowY6!p`y!^MrqFaOU?+8~*R!=U*H&({)9+C?VdMIMm`4{L{ OgRD;4;a-^H$^Qd{UB>JH literal 0 HcmV?d00001 diff --git a/tests/srcWithManifestTestRepo/mkdocs.yml b/tests/srcWithManifestTestRepo/mkdocs.yml new file mode 100644 index 00000000..df5e17ad --- /dev/null +++ b/tests/srcWithManifestTestRepo/mkdocs.yml @@ -0,0 +1,75 @@ +site_name: -{{ REPO_NAME }}- +theme: + name: material + language: en + font: + text: Roboto + code: Sono + logo: Assets/icon.png + favicon: Assets/icon.png + palette: + # Palette toggle for automatic mode + - media: "(prefers-color-scheme)" + toggle: + icon: material/link + name: Switch to dark mode + # Palette toggle for dark mode + - media: '(prefers-color-scheme: dark)' + scheme: slate + toggle: + primary: black + accent: green + icon: material/toggle-switch-off-outline + name: Switch to light mode + # Palette toggle for light mode + - media: '(prefers-color-scheme: light)' + scheme: default + toggle: + primary: indigo + accent: green + icon: material/toggle-switch + name: Switch to system preference + icon: + repo: material/github + features: + - navigation.instant + - navigation.instant.progress + - navigation.indexes + - navigation.top + - navigation.tracking + - navigation.expand + - search.suggest + - search.highlight + +repo_name: -{{ REPO_OWNER }}-/-{{ REPO_NAME }}- +repo_url: https://github.com/-{{ REPO_OWNER }}-/-{{ REPO_NAME }}- + +plugins: + - search + +markdown_extensions: + - toc: + permalink: true # Adds a link icon to headings + - attr_list + - admonition + - md_in_html + - pymdownx.details # Enables collapsible admonitions + +extra: + social: + - icon: fontawesome/brands/discord + link: https://discord.gg/jedJWCPAhD + name: -{{ REPO_OWNER }}- on Discord + - icon: fontawesome/brands/github + link: https://github.com/-{{ REPO_OWNER }}-/ + name: -{{ REPO_OWNER }}- on GitHub + consent: + title: Cookie consent + description: >- + We use cookies to recognize your repeated visits and preferences, as well + as to measure the effectiveness of our documentation and whether users + find what they're searching for. With your consent, you're helping us to + make our documentation better. + actions: + - accept + - reject diff --git a/tests/srcWithManifest/assemblies/LsonLib.dll b/tests/srcWithManifestTestRepo/src/assemblies/LsonLib.dll similarity index 100% rename from tests/srcWithManifest/assemblies/LsonLib.dll rename to tests/srcWithManifestTestRepo/src/assemblies/LsonLib.dll diff --git a/tests/srcWithManifest/classes/private/SecretWriter.ps1 b/tests/srcWithManifestTestRepo/src/classes/private/SecretWriter.ps1 similarity index 100% rename from tests/srcWithManifest/classes/private/SecretWriter.ps1 rename to tests/srcWithManifestTestRepo/src/classes/private/SecretWriter.ps1 diff --git a/tests/srcWithManifest/classes/public/Book.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/Book.ps1 similarity index 100% rename from tests/srcWithManifest/classes/public/Book.ps1 rename to tests/srcWithManifestTestRepo/src/classes/public/Book.ps1 diff --git a/tests/srcWithManifest/data/Config.psd1 b/tests/srcWithManifestTestRepo/src/data/Config.psd1 similarity index 100% rename from tests/srcWithManifest/data/Config.psd1 rename to tests/srcWithManifestTestRepo/src/data/Config.psd1 diff --git a/tests/srcWithManifest/data/Settings.psd1 b/tests/srcWithManifestTestRepo/src/data/Settings.psd1 similarity index 100% rename from tests/srcWithManifest/data/Settings.psd1 rename to tests/srcWithManifestTestRepo/src/data/Settings.psd1 diff --git a/tests/srcWithManifest/finally.ps1 b/tests/srcWithManifestTestRepo/src/finally.ps1 similarity index 100% rename from tests/srcWithManifest/finally.ps1 rename to tests/srcWithManifestTestRepo/src/finally.ps1 diff --git a/tests/srcWithManifest/formats/CultureInfo.Format.ps1xml b/tests/srcWithManifestTestRepo/src/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/srcWithManifest/formats/CultureInfo.Format.ps1xml rename to tests/srcWithManifestTestRepo/src/formats/CultureInfo.Format.ps1xml diff --git a/tests/srcWithManifest/formats/Mygciview.Format.ps1xml b/tests/srcWithManifestTestRepo/src/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/srcWithManifest/formats/Mygciview.Format.ps1xml rename to tests/srcWithManifestTestRepo/src/formats/Mygciview.Format.ps1xml diff --git a/tests/srcWithManifest/functions/private/Get-InternalPSModule.ps1 b/tests/srcWithManifestTestRepo/src/functions/private/Get-InternalPSModule.ps1 similarity index 100% rename from tests/srcWithManifest/functions/private/Get-InternalPSModule.ps1 rename to tests/srcWithManifestTestRepo/src/functions/private/Get-InternalPSModule.ps1 diff --git a/tests/srcWithManifest/functions/private/Set-InternalPSModule.ps1 b/tests/srcWithManifestTestRepo/src/functions/private/Set-InternalPSModule.ps1 similarity index 100% rename from tests/srcWithManifest/functions/private/Set-InternalPSModule.ps1 rename to tests/srcWithManifestTestRepo/src/functions/private/Set-InternalPSModule.ps1 diff --git a/tests/src/functions/public/Test-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 similarity index 52% rename from tests/src/functions/public/Test-PSModuleTest.ps1 rename to tests/srcWithManifestTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 index 4056e2f6..57257f1d 100644 --- a/tests/src/functions/public/Test-PSModuleTest.ps1 +++ b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 @@ -1,5 +1,9 @@ -#SkipTest:Verbose:Just want to test that a function can have multiple skips. -function Test-PSModuleTest { +#Requires -Modules Utilities +#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.1.4' } +#Requires -Modules @{ ModuleName = 'DynamicParams'; ModuleVersion = '1.1.8' } +#Requires -Modules @{ ModuleName = 'Store'; ModuleVersion = '0.3.1' } + +function Get-PSModuleTest { <# .SYNOPSIS Performs tests on a module. @@ -16,5 +20,4 @@ function Test-PSModuleTest { [string] $Name ) Write-Output "Hello, $Name!" - Write-Verbose 'Verbose message' -Verbose } diff --git a/tests/src/functions/public/New-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 similarity index 81% rename from tests/src/functions/public/New-PSModuleTest.ps1 rename to tests/srcWithManifestTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 index 8fc0641f..5fa16bc3 100644 --- a/tests/src/functions/public/New-PSModuleTest.ps1 +++ b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 @@ -1,6 +1,5 @@ -#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'} -#SkipTest:FunctionTest:Difficult to test due to the nature of the function. -#SkipTest:Verbose:Just want to test that a function can have multiple skips. +#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.1.4'} + function New-PSModuleTest { <# .SYNOPSIS @@ -28,11 +27,11 @@ function New-PSModuleTest { [Parameter(Mandatory)] [string] $Name ) - Write-Debug "Debug message" - Write-Verbose "Verbose message" -Verbose Write-Output "Hello, $Name!" } New-Alias New-PSModuleTestAlias3 New-PSModuleTest New-Alias -Name New-PSModuleTestAlias4 -Value New-PSModuleTest + + Set-Alias New-PSModuleTestAlias5 New-PSModuleTest diff --git a/tests/srcWithManifestTestRepo/src/functions/public/PSModule/PSModule.md b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/PSModule.md new file mode 100644 index 00000000..79741cf4 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/functions/public/PSModule/PSModule.md @@ -0,0 +1 @@ +# This is PSModule diff --git a/tests/srcWithManifest/functions/public/Set-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 similarity index 100% rename from tests/srcWithManifest/functions/public/Set-PSModuleTest.ps1 rename to tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 diff --git a/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/SomethingElse.md b/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/SomethingElse.md new file mode 100644 index 00000000..d9f7e9ee --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/SomethingElse.md @@ -0,0 +1 @@ +# This is SomethingElse diff --git a/tests/srcWithManifest/functions/public/Get-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 similarity index 83% rename from tests/srcWithManifest/functions/public/Get-PSModuleTest.ps1 rename to tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 index 0e9aacfe..26be2b9b 100644 --- a/tests/srcWithManifest/functions/public/Get-PSModuleTest.ps1 +++ b/tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 @@ -1,6 +1,4 @@ -#Requires -Modules Utilities - -function Get-PSModuleTest { +function Test-PSModuleTest { <# .SYNOPSIS Performs tests on a module. diff --git a/tests/srcWithManifestTestRepo/src/functions/public/completers.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/completers.ps1 new file mode 100644 index 00000000..6b1adbb7 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/functions/public/completers.ps1 @@ -0,0 +1,8 @@ +Register-ArgumentCompleter -CommandName New-PSModuleTest -ParameterName Name -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + + 'Alice', 'Bob', 'Charlie' | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } +} diff --git a/tests/srcWithManifest/header.ps1 b/tests/srcWithManifestTestRepo/src/header.ps1 similarity index 100% rename from tests/srcWithManifest/header.ps1 rename to tests/srcWithManifestTestRepo/src/header.ps1 diff --git a/tests/srcWithManifest/init/initializer.ps1 b/tests/srcWithManifestTestRepo/src/init/initializer.ps1 similarity index 100% rename from tests/srcWithManifest/init/initializer.ps1 rename to tests/srcWithManifestTestRepo/src/init/initializer.ps1 diff --git a/tests/srcWithManifest/manifest.psd1 b/tests/srcWithManifestTestRepo/src/manifest.psd1 similarity index 100% rename from tests/srcWithManifest/manifest.psd1 rename to tests/srcWithManifestTestRepo/src/manifest.psd1 diff --git a/tests/srcWithManifest/modules/OtherPSModule.psm1 b/tests/srcWithManifestTestRepo/src/modules/OtherPSModule.psm1 similarity index 100% rename from tests/srcWithManifest/modules/OtherPSModule.psm1 rename to tests/srcWithManifestTestRepo/src/modules/OtherPSModule.psm1 diff --git a/tests/srcWithManifest/scripts/loader.ps1 b/tests/srcWithManifestTestRepo/src/scripts/loader.ps1 similarity index 100% rename from tests/srcWithManifest/scripts/loader.ps1 rename to tests/srcWithManifestTestRepo/src/scripts/loader.ps1 diff --git a/tests/srcWithManifest/types/DirectoryInfo.Types.ps1xml b/tests/srcWithManifestTestRepo/src/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/srcWithManifest/types/DirectoryInfo.Types.ps1xml rename to tests/srcWithManifestTestRepo/src/types/DirectoryInfo.Types.ps1xml diff --git a/tests/srcWithManifest/types/FileInfo.Types.ps1xml b/tests/srcWithManifestTestRepo/src/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/srcWithManifest/types/FileInfo.Types.ps1xml rename to tests/srcWithManifestTestRepo/src/types/FileInfo.Types.ps1xml diff --git a/tests/srcWithManifest/variables/private/PrivateVariables.ps1 b/tests/srcWithManifestTestRepo/src/variables/private/PrivateVariables.ps1 similarity index 100% rename from tests/srcWithManifest/variables/private/PrivateVariables.ps1 rename to tests/srcWithManifestTestRepo/src/variables/private/PrivateVariables.ps1 diff --git a/tests/srcWithManifest/variables/public/Moons.ps1 b/tests/srcWithManifestTestRepo/src/variables/public/Moons.ps1 similarity index 100% rename from tests/srcWithManifest/variables/public/Moons.ps1 rename to tests/srcWithManifestTestRepo/src/variables/public/Moons.ps1 diff --git a/tests/srcWithManifest/variables/public/Planets.ps1 b/tests/srcWithManifestTestRepo/src/variables/public/Planets.ps1 similarity index 100% rename from tests/srcWithManifest/variables/public/Planets.ps1 rename to tests/srcWithManifestTestRepo/src/variables/public/Planets.ps1 diff --git a/tests/srcWithManifest/variables/public/SolarSystems.ps1 b/tests/srcWithManifestTestRepo/src/variables/public/SolarSystems.ps1 similarity index 100% rename from tests/srcWithManifest/variables/public/SolarSystems.ps1 rename to tests/srcWithManifestTestRepo/src/variables/public/SolarSystems.ps1 diff --git a/tests/srcWithManifestTestRepo/tests/Environments/Environment.Tests.ps1 b/tests/srcWithManifestTestRepo/tests/Environments/Environment.Tests.ps1 new file mode 100644 index 00000000..211be946 --- /dev/null +++ b/tests/srcWithManifestTestRepo/tests/Environments/Environment.Tests.ps1 @@ -0,0 +1,15 @@ +Describe 'Environment Variables are available' { + It 'Should be available [<_>]' -ForEach @( + 'TEST_APP_ENT_CLIENT_ID', + 'TEST_APP_ENT_PRIVATE_KEY', + 'TEST_APP_ORG_CLIENT_ID', + 'TEST_APP_ORG_PRIVATE_KEY', + 'TEST_USER_ORG_FG_PAT', + 'TEST_USER_USER_FG_PAT', + 'TEST_USER_PAT' + ) { + $name = $_ + Write-Verbose "Environment variable: [$name]" -Verbose + Get-ChildItem env: | Where-Object { $_.Name -eq $name } | Should -Not -BeNullOrEmpty + } +} diff --git a/tests/srcWithManifestTestRepo/tests/MyTests/PSModuleTest.Tests.ps1 b/tests/srcWithManifestTestRepo/tests/MyTests/PSModuleTest.Tests.ps1 new file mode 100644 index 00000000..9bf1bb64 --- /dev/null +++ b/tests/srcWithManifestTestRepo/tests/MyTests/PSModuleTest.Tests.ps1 @@ -0,0 +1,44 @@ +[CmdletBinding()] +Param( + # Path to the module to test. + [Parameter()] + [string] $Path +) + +Write-Verbose "Path to the module: [$Path]" -Verbose +Describe 'PSModuleTest.Tests.ps1' { + Context 'Function: Test-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Test-PSModuleTest -Name 'World' | Out-String) -Verbose + Test-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: Get-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Get-PSModuleTest -Name 'World' | Out-String) -Verbose + Get-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: New-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (New-PSModuleTest -Name 'World' | Out-String) -Verbose + New-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: Set-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Set-PSModuleTest -Name 'World' | Out-String) -Verbose + Set-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Variables' { + It "Exports a variable for SolarSystems that contains 'Solar System'" { + Write-Verbose ($SolarSystems | Out-String) -Verbose + $SolarSystems[0].Name | Should -Be 'Solar System' + } + } +} diff --git a/tests/srcWithManifestTestRepo/tools/1-build.ps1 b/tests/srcWithManifestTestRepo/tools/1-build.ps1 new file mode 100644 index 00000000..e762395b --- /dev/null +++ b/tests/srcWithManifestTestRepo/tools/1-build.ps1 @@ -0,0 +1 @@ +"1 - Build script executed." diff --git a/tests/srcWithManifestTestRepo/tools/2-build.ps1 b/tests/srcWithManifestTestRepo/tools/2-build.ps1 new file mode 100644 index 00000000..d2575a02 --- /dev/null +++ b/tests/srcWithManifestTestRepo/tools/2-build.ps1 @@ -0,0 +1 @@ +"2 - Build script executed." diff --git a/tests/tests/PSModuleTest.Tests.ps1 b/tests/tests/PSModuleTest.Tests.ps1 deleted file mode 100644 index 00b3cde7..00000000 --- a/tests/tests/PSModuleTest.Tests.ps1 +++ /dev/null @@ -1,11 +0,0 @@ -Describe 'Module' { - It 'Function: Get-PSModuleTest' { - Get-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' - } - It 'Function: Set-PSModuleTest' { - Set-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' - } - It 'Function: Test-PSModuleTest' { - Test-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' - } -} From 14f576ce269e8cbc73bddbf452e13685862b01bd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 23:07:18 +0100 Subject: [PATCH 050/172] Refactor: Remove unnecessary -AutoSize parameter from Format-List in main.ps1 for cleaner output --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index ff171b11..93f8a515 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -19,7 +19,7 @@ $codePath = switch ($testType) { TestType = $testType CodePath = $codePath TestPath = $testPath -} | Format-List -AutoSize +} | Format-List Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name TestPath -Value $testPath From 084035b61be5469cb3463bb2805ec6823c5a42ba Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 23:12:18 +0100 Subject: [PATCH 051/172] Refactor: Update test paths in GitHub workflows for improved clarity and organization --- .github/workflows/Action-Test-Src-Default.yml | 2 +- .github/workflows/Action-Test-Src-WithManifest.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Action-Test-Src-Default.yml b/.github/workflows/Action-Test-Src-Default.yml index c16dfe4d..c48f749e 100644 --- a/.github/workflows/Action-Test-Src-Default.yml +++ b/.github/workflows/Action-Test-Src-Default.yml @@ -36,7 +36,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} with: Name: PSModuleTest - Path: tests/src + Path: tests/srcTestRepo TestType: SourceCode OS: ${{ matrix.os }} diff --git a/.github/workflows/Action-Test-Src-WithManifest.yml b/.github/workflows/Action-Test-Src-WithManifest.yml index e9f6b6be..8ce25e4c 100644 --- a/.github/workflows/Action-Test-Src-WithManifest.yml +++ b/.github/workflows/Action-Test-Src-WithManifest.yml @@ -36,7 +36,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} with: Name: PSModuleTest - Path: tests/srcWithManifest + Path: tests/srcWithManifestTestRepo TestType: SourceCode OS: ${{ matrix.os }} From 9e271dff9d8fb608158febeacd91f8ca65610aab Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 23:21:12 +0100 Subject: [PATCH 052/172] Refactor: Simplify code path resolution in main.ps1 and update test paths in container scripts for consistency --- scripts/main.ps1 | 23 ++++++++++--------- .../PSModule/PSModule.Container.ps1 | 2 +- .../PSScriptAnalyzer.Container.ps1 | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 93f8a515..a2155add 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -2,17 +2,18 @@ $moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name $testType = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$testType" | Select-Object -ExpandProperty Path -$codePath = switch ($testType) { - 'Module' { - Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path - } - 'SourceCode' { - Resolve-Path -Path $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src | Select-Object -ExpandProperty Path - } - default { - throw "Invalid test type: [$testType]" - } -} +$codePath = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path +# switch ($testType) { +# 'Module' { +# Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path +# } +# 'SourceCode' { +# Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path +# } +# default { +# throw "Invalid test type: [$testType]" +# } +# } [pscustomobject]@{ ModuleName = $moduleName diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index 28716fce..6d3ec576 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $env:GITHUB_ACTION_INPUT_Run_Path + Path = "$env:GITHUB_ACTION_INPUT_Run_Path/src" TestsPath = "$env:GITHUB_ACTION_INPUT_Run_Path/tests" Debug = $false Verbose = $false diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 15c6c3f8..55679048 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $env:GITHUB_ACTION_INPUT_Run_Path + Path = "$env:GITHUB_ACTION_INPUT_Run_Path/src" SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false From 10870182a79f156636f2f97466422f91ba3f57c8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 23:26:10 +0100 Subject: [PATCH 053/172] Refactor: Update code path resolution in main.ps1 to use GITHUB_WORKSPACE for improved compatibility --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a2155add..c9ef1c90 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -2,7 +2,7 @@ $moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name $testType = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$testType" | Select-Object -ExpandProperty Path -$codePath = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path +$codePath = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" # switch ($testType) { # 'Module' { # Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path From 7d31ea5d11006f75df40671aa42a39a0b0915911 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 23:46:53 +0100 Subject: [PATCH 054/172] Refactor: Enhance module name handling in action.yml and update test paths for improved modularity --- action.yml | 2 ++ scripts/main.ps1 | 1 + scripts/tests/Module/Module.Configuration.ps1 | 3 +-- scripts/tests/Module/PSModule/PSModule.Container.ps1 | 2 +- .../Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 | 2 +- .../Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 | 5 +---- scripts/tests/SourceCode/SourceCode.Configuration.ps1 | 1 - 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 6c92df17..e561462d 100644 --- a/action.yml +++ b/action.yml @@ -57,6 +57,8 @@ runs: - name: Invoke-Pester uses: PSModule/Invoke-Pester@fix id: test + env: + ModuleName: ${{ fromJson(steps.paths.outputs.result).ModuleName }} with: TestResult_TestSuiteName: ${{ inputs.TestType }}-${{ inputs.OS }} Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c9ef1c90..bf4eb396 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -22,5 +22,6 @@ $codePath = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" TestPath = $testPath } | Format-List +Set-GitHubOutput -Name ModuleName -Value $moduleName Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name TestPath -Value $testPath diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index 2d7a1804..e21afb2e 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,7 +1,6 @@ @{ TestResult = @{ - Enabled = $true - TestSuiteName = 'Module' + Enabled = $true } CodeCoverage = @{ Enabled = $true diff --git a/scripts/tests/Module/PSModule/PSModule.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 index 37c6bb30..80d2b93b 100644 --- a/scripts/tests/Module/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $env:GITHUB_ACTION_INPUT_Run_Path + Path = "$env:GITHUB_ACTION_INPUT_Run_Path/output/modules/$env:ModuleName" Debug = $false Verbose = $false } diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index d1c53dba..7d1e6540 100644 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $env:GITHUB_ACTION_INPUT_Run_Path + Path = "$env:GITHUB_ACTION_INPUT_Run_Path/output/modules/$env:ModuleName" SettingsFilePath = "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" Debug = $false Verbose = $false diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 index 09cc3d0c..62a58184 100644 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 +++ b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 @@ -49,8 +49,5 @@ IgnoreAssignmentOperatorInsideHashTable = $true } } - ExcludeRules = @( - 'PSMissingModuleManifestField', # This rule is not applicable until the module is built. - 'PSUseToExportFieldsInManifest' - ) + ExcludeRules = @() } diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 index 4c4ca3dd..e965bfe5 100644 --- a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -1,7 +1,6 @@ @{ TestResult = @{ Enabled = $true - TestSuiteName = 'SourceCode' } Output = @{ Verbosity = 'Detailed' From 1dfbad31a3c45149c204cee20a0e347c5997b610 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 23:57:48 +0100 Subject: [PATCH 055/172] Refactor: Improve log messages formatting in PSModule.Tests.ps1 for better clarity --- .../SourceCode/PSModule/PSModule.Tests.ps1 | 22 +++++++++---------- .../SourceCode/SourceCode.Configuration.ps1 | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index ef7de1f1..7bac66f9 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -23,7 +23,7 @@ Param( BeforeAll { $scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File - LogGroup "Found $($scriptFiles.Count) script files in [$Path]" { + LogGroup "[$Path] - Found $($scriptFiles.Count) script files" { $scriptFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -31,7 +31,7 @@ BeforeAll { $functionsPath = Join-Path -Path $Path -ChildPath 'functions' $functionFiles = (Test-Path -Path $functionsPath) ? (Get-ChildItem -Path $functionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($functionFiles.Count) function files in [$functionsPath]" { + LogGroup "[$functionsPath] - Found $($functionFiles.Count) function files" { $functionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -39,21 +39,21 @@ BeforeAll { $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private' $privateFunctionFiles = (Test-Path -Path $privateFunctionsPath) ? (Get-ChildItem -Path $privateFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($privateFunctionFiles.Count) private function files in [$privateFunctionsPath]" { + LogGroup "[$privateFunctionsPath] - Found $($privateFunctionFiles.Count) private function files" { $privateFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public' $publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($publicFunctionFiles.Count) public function files in [$publicFunctionsPath]" { + LogGroup "[$publicFunctionsPath] - Found $($publicFunctionFiles.Count) public function files" { $publicFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $variablesPath = Join-Path -Path $Path -ChildPath 'variables' $variableFiles = (Test-Path -Path $variablesPath) ? (Get-ChildItem -Path $variablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($variableFiles.Count) variable files in [$variablesPath]" { + LogGroup "[$variablesPath] - Found $($variableFiles.Count) variable files" { $variableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -61,7 +61,7 @@ BeforeAll { $privateVariablesPath = Join-Path -Path $variablesPath -ChildPath 'private' $privateVariableFiles = (Test-Path -Path $privateVariablesPath) ? (Get-ChildItem -Path $privateVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($privateVariableFiles.Count) private variable files in [$privateVariablesPath]" { + LogGroup "[$privateVariablesPath] - Found $($privateVariableFiles.Count) private variable files" { $privateVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -69,14 +69,14 @@ BeforeAll { $publicVariablesPath = Join-Path -Path $variablesPath -ChildPath 'public' $publicVariableFiles = (Test-Path -Path $publicVariablesPath) ? (Get-ChildItem -Path $publicVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($publicVariableFiles.Count) public variable files in [$publicVariablesPath]" { + LogGroup "[$publicVariablesPath] - Found $($publicVariableFiles.Count) public variable files" { $publicVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $classPath = Join-Path -Path $Path -ChildPath 'classes' $classFiles = (Test-Path -Path $classPath) ? (Get-ChildItem -Path $classPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($classFiles.Count) class files in [$classPath]" { + LogGroup "[$classPath] - Found $($classFiles.Count) class files" { $classFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -84,7 +84,7 @@ BeforeAll { $privateClassPath = Join-Path -Path $classPath -ChildPath 'private' $privateClassFiles = (Test-Path -Path $privateClassPath) ? (Get-ChildItem -Path $privateClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($privateClassFiles.Count) private class files in [$privateClassPath]" { + LogGroup "[$privateClassPath] - Found $($privateClassFiles.Count) private class files" { $privateClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -92,13 +92,13 @@ BeforeAll { $publicClassPath = Join-Path -Path $classPath -ChildPath 'public' $publicClassFiles = (Test-Path -Path $publicClassPath) ? (Get-ChildItem -Path $publicClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "Found $($publicClassFiles.Count) public class files in [$publicClassPath]" { + LogGroup "[$publicClassPath] - Found $($publicClassFiles.Count) public class files" { $publicClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $testFiles = Get-ChildItem -Path $TestsPath -Include *.Tests.ps1 -Recurse -File - LogGroup "Found $($testFiles.Count) test files in [$TestsPath]" { + LogGroup "[$TestsPath] - Found $($testFiles.Count) test files" { $testFiles | ForEach-Object { Write-Host " - $($_.FullName)" } diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 index e965bfe5..e76f767f 100644 --- a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -1,6 +1,6 @@ @{ TestResult = @{ - Enabled = $true + Enabled = $true } Output = @{ Verbosity = 'Detailed' From 317b22d980699d014eea00be357d7a61988e84b6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Feb 2025 00:07:15 +0100 Subject: [PATCH 056/172] Refactor: Update log messages in PSModule.Tests.ps1 to use relative paths for improved clarity --- .../SourceCode/PSModule/PSModule.Tests.ps1 | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index 7bac66f9..3d16287e 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -22,16 +22,19 @@ Param( ) BeforeAll { + $rootPath = Split-Path -Path $Path -Parent + $scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File - LogGroup "[$Path] - Found $($scriptFiles.Count) script files" { + $relativePath = (Resolve-Path -Path $Path -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativePath] - Found $($scriptFiles.Count) script files" { $scriptFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $functionsPath = Join-Path -Path $Path -ChildPath 'functions' $functionFiles = (Test-Path -Path $functionsPath) ? (Get-ChildItem -Path $functionsPath -File -Filter '*.ps1' -Recurse) : $null - - LogGroup "[$functionsPath] - Found $($functionFiles.Count) function files" { + $relativeFunctionsPath = (Resolve-Path -Path $functionsPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativeFunctionsPath] - Found $($functionFiles.Count) function files" { $functionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -39,21 +42,24 @@ BeforeAll { $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private' $privateFunctionFiles = (Test-Path -Path $privateFunctionsPath) ? (Get-ChildItem -Path $privateFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "[$privateFunctionsPath] - Found $($privateFunctionFiles.Count) private function files" { + $relativePrivateFunctionsPath = (Resolve-Path -Path $privateFunctionsPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativePrivateFunctionsPath] - Found $($privateFunctionFiles.Count) private function files" { $privateFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public' $publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "[$publicFunctionsPath] - Found $($publicFunctionFiles.Count) public function files" { + $relativePublicFunctionsPath = (Resolve-Path -Path $publicFunctionsPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativePublicFunctionsPath] - Found $($publicFunctionFiles.Count) public function files" { $publicFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $variablesPath = Join-Path -Path $Path -ChildPath 'variables' $variableFiles = (Test-Path -Path $variablesPath) ? (Get-ChildItem -Path $variablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "[$variablesPath] - Found $($variableFiles.Count) variable files" { + $relativeVariablesPath = (Resolve-Path -Path $variablesPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativeVariablesPath] - Found $($variableFiles.Count) variable files" { $variableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -61,7 +67,8 @@ BeforeAll { $privateVariablesPath = Join-Path -Path $variablesPath -ChildPath 'private' $privateVariableFiles = (Test-Path -Path $privateVariablesPath) ? (Get-ChildItem -Path $privateVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "[$privateVariablesPath] - Found $($privateVariableFiles.Count) private variable files" { + $relativePrivateVariablesPath = (Resolve-Path -Path $privateVariablesPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativePrivateVariablesPath] - Found $($privateVariableFiles.Count) private variable files" { $privateVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -69,14 +76,16 @@ BeforeAll { $publicVariablesPath = Join-Path -Path $variablesPath -ChildPath 'public' $publicVariableFiles = (Test-Path -Path $publicVariablesPath) ? (Get-ChildItem -Path $publicVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "[$publicVariablesPath] - Found $($publicVariableFiles.Count) public variable files" { + $relativePublicVariablesPath = (Resolve-Path -Path $publicVariablesPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativePublicVariablesPath] - Found $($publicVariableFiles.Count) public variable files" { $publicVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $classPath = Join-Path -Path $Path -ChildPath 'classes' $classFiles = (Test-Path -Path $classPath) ? (Get-ChildItem -Path $classPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "[$classPath] - Found $($classFiles.Count) class files" { + $relativeClassPath = (Resolve-Path -Path $classPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativeClassPath] - Found $($classFiles.Count) class files" { $classFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -84,7 +93,8 @@ BeforeAll { $privateClassPath = Join-Path -Path $classPath -ChildPath 'private' $privateClassFiles = (Test-Path -Path $privateClassPath) ? (Get-ChildItem -Path $privateClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "[$privateClassPath] - Found $($privateClassFiles.Count) private class files" { + $relativePrivateClassPath = (Resolve-Path -Path $privateClassPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativePrivateClassPath] - Found $($privateClassFiles.Count) private class files" { $privateClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -92,13 +102,15 @@ BeforeAll { $publicClassPath = Join-Path -Path $classPath -ChildPath 'public' $publicClassFiles = (Test-Path -Path $publicClassPath) ? (Get-ChildItem -Path $publicClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup "[$publicClassPath] - Found $($publicClassFiles.Count) public class files" { + $relativePublicClassPath = (Resolve-Path -Path $publicClassPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativePublicClassPath] - Found $($publicClassFiles.Count) public class files" { $publicClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $testFiles = Get-ChildItem -Path $TestsPath -Include *.Tests.ps1 -Recurse -File - LogGroup "[$TestsPath] - Found $($testFiles.Count) test files" { + $relativeTestsPath = (Resolve-Path -Path $TestsPath -Relative -RelativeBasePath $rootPath).Path + LogGroup "[$relativeTestsPath] - Found $($testFiles.Count) test files" { $testFiles | ForEach-Object { Write-Host " - $($_.FullName)" } From 8eebcdf03dc493c07b8f7c13183a075990a05bec Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Feb 2025 00:14:49 +0100 Subject: [PATCH 057/172] Refactor: Simplify path handling in action.yml and main.ps1 for improved clarity and consistency --- action.yml | 2 -- scripts/main.ps1 | 24 +++++++++---------- .../PSModule/PSModule.Container.ps1 | 4 ++-- .../PSScriptAnalyzer.Container.ps1 | 4 ++-- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/action.yml b/action.yml index e561462d..6c92df17 100644 --- a/action.yml +++ b/action.yml @@ -57,8 +57,6 @@ runs: - name: Invoke-Pester uses: PSModule/Invoke-Pester@fix id: test - env: - ModuleName: ${{ fromJson(steps.paths.outputs.result).ModuleName }} with: TestResult_TestSuiteName: ${{ inputs.TestType }}-${{ inputs.OS }} Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index bf4eb396..381b9789 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -2,18 +2,17 @@ $moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name $testType = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$testType" | Select-Object -ExpandProperty Path -$codePath = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" -# switch ($testType) { -# 'Module' { -# Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path -# } -# 'SourceCode' { -# Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path -# } -# default { -# throw "Invalid test type: [$testType]" -# } -# } +$codePath = switch ($testType) { + 'Module' { + Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path + } + 'SourceCode' { + Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path + } + default { + throw "Invalid test type: [$testType]" + } +} [pscustomobject]@{ ModuleName = $moduleName @@ -22,6 +21,5 @@ $codePath = "$env:GITHUB_WORKSPACE/$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path" TestPath = $testPath } | Format-List -Set-GitHubOutput -Name ModuleName -Value $moduleName Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name TestPath -Value $testPath diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index 6d3ec576..21297ac1 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_ACTION_INPUT_Run_Path/src" - TestsPath = "$env:GITHUB_ACTION_INPUT_Run_Path/tests" + Path = "$env:GITHUB_ACTION_INPUT_Run_Path" | Get-Item + TestsPath = "$env:GITHUB_ACTION_INPUT_Run_Path/../tests" | Get-Item Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 index 55679048..edd63bf2 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_ACTION_INPUT_Run_Path/src" - SettingsFilePath = Resolve-Path -Path "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" + Path = "$env:GITHUB_ACTION_INPUT_Run_Path" | Get-Item + SettingsFilePath = "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" | Get-Item Debug = $false Verbose = $false } From 83525a69933a6fc359b496501d26617e7a4e6a82 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Feb 2025 01:00:41 +0100 Subject: [PATCH 058/172] Refactor: Simplify log messages in PSModule.Tests.ps1 for improved clarity --- .../SourceCode/PSModule/PSModule.Tests.ps1 | 35 ++++++------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index 3d16287e..638d50c1 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -22,19 +22,15 @@ Param( ) BeforeAll { - $rootPath = Split-Path -Path $Path -Parent - $scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File - $relativePath = (Resolve-Path -Path $Path -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativePath] - Found $($scriptFiles.Count) script files" { + LogGroup " - Script files [$($scriptFiles.Count)]" { $scriptFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $functionsPath = Join-Path -Path $Path -ChildPath 'functions' $functionFiles = (Test-Path -Path $functionsPath) ? (Get-ChildItem -Path $functionsPath -File -Filter '*.ps1' -Recurse) : $null - $relativeFunctionsPath = (Resolve-Path -Path $functionsPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativeFunctionsPath] - Found $($functionFiles.Count) function files" { + LogGroup " - Function files [$($functionFiles.Count)]" { $functionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -42,24 +38,21 @@ BeforeAll { $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private' $privateFunctionFiles = (Test-Path -Path $privateFunctionsPath) ? (Get-ChildItem -Path $privateFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - $relativePrivateFunctionsPath = (Resolve-Path -Path $privateFunctionsPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativePrivateFunctionsPath] - Found $($privateFunctionFiles.Count) private function files" { + LogGroup " - Private function files [$($privateFunctionFiles.Count)]" { $privateFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public' $publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - $relativePublicFunctionsPath = (Resolve-Path -Path $publicFunctionsPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativePublicFunctionsPath] - Found $($publicFunctionFiles.Count) public function files" { + LogGroup " - Public function files [$($publicFunctionFiles.Count)]" { $publicFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $variablesPath = Join-Path -Path $Path -ChildPath 'variables' $variableFiles = (Test-Path -Path $variablesPath) ? (Get-ChildItem -Path $variablesPath -File -Filter '*.ps1' -Recurse) : $null - $relativeVariablesPath = (Resolve-Path -Path $variablesPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativeVariablesPath] - Found $($variableFiles.Count) variable files" { + LogGroup " - Variable files [$($variableFiles.Count)]" { $variableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -67,8 +60,7 @@ BeforeAll { $privateVariablesPath = Join-Path -Path $variablesPath -ChildPath 'private' $privateVariableFiles = (Test-Path -Path $privateVariablesPath) ? (Get-ChildItem -Path $privateVariablesPath -File -Filter '*.ps1' -Recurse) : $null - $relativePrivateVariablesPath = (Resolve-Path -Path $privateVariablesPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativePrivateVariablesPath] - Found $($privateVariableFiles.Count) private variable files" { + LogGroup " - Private variable files [$($privateVariableFiles.Count)]" { $privateVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -76,16 +68,14 @@ BeforeAll { $publicVariablesPath = Join-Path -Path $variablesPath -ChildPath 'public' $publicVariableFiles = (Test-Path -Path $publicVariablesPath) ? (Get-ChildItem -Path $publicVariablesPath -File -Filter '*.ps1' -Recurse) : $null - $relativePublicVariablesPath = (Resolve-Path -Path $publicVariablesPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativePublicVariablesPath] - Found $($publicVariableFiles.Count) public variable files" { + LogGroup " - Public variable files [$($publicVariableFiles.Count)]" { $publicVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $classPath = Join-Path -Path $Path -ChildPath 'classes' $classFiles = (Test-Path -Path $classPath) ? (Get-ChildItem -Path $classPath -File -Filter '*.ps1' -Recurse) : $null - $relativeClassPath = (Resolve-Path -Path $classPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativeClassPath] - Found $($classFiles.Count) class files" { + LogGroup " - Class files [$($classFiles.Count)]" { $classFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -93,8 +83,7 @@ BeforeAll { $privateClassPath = Join-Path -Path $classPath -ChildPath 'private' $privateClassFiles = (Test-Path -Path $privateClassPath) ? (Get-ChildItem -Path $privateClassPath -File -Filter '*.ps1' -Recurse) : $null - $relativePrivateClassPath = (Resolve-Path -Path $privateClassPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativePrivateClassPath] - Found $($privateClassFiles.Count) private class files" { + LogGroup " - Private class files [$($privateClassFiles.Count)]" { $privateClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -102,15 +91,13 @@ BeforeAll { $publicClassPath = Join-Path -Path $classPath -ChildPath 'public' $publicClassFiles = (Test-Path -Path $publicClassPath) ? (Get-ChildItem -Path $publicClassPath -File -Filter '*.ps1' -Recurse) : $null - $relativePublicClassPath = (Resolve-Path -Path $publicClassPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativePublicClassPath] - Found $($publicClassFiles.Count) public class files" { + LogGroup " - Public class files [$($publicClassFiles.Count)]" { $publicClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $testFiles = Get-ChildItem -Path $TestsPath -Include *.Tests.ps1 -Recurse -File - $relativeTestsPath = (Resolve-Path -Path $TestsPath -Relative -RelativeBasePath $rootPath).Path - LogGroup "[$relativeTestsPath] - Found $($testFiles.Count) test files" { + LogGroup " - Test files [$($testFiles.Count)]" { $testFiles | ForEach-Object { Write-Host " - $($_.FullName)" } From 8f026d15681714daaaa1131cf1e0e18f1553208c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Feb 2025 08:51:39 +0100 Subject: [PATCH 059/172] Refactor: Update log messages in PSModule.Tests.ps1 for improved clarity and consistency --- .../tests/SourceCode/PSModule/PSModule.Tests.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index 638d50c1..dbe8ca4c 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -38,14 +38,14 @@ BeforeAll { $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private' $privateFunctionFiles = (Test-Path -Path $privateFunctionsPath) ? (Get-ChildItem -Path $privateFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private function files [$($privateFunctionFiles.Count)]" { + LogGroup " - Private [$($privateFunctionFiles.Count)]" { $privateFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public' $publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public function files [$($publicFunctionFiles.Count)]" { + LogGroup " - Public [$($publicFunctionFiles.Count)]" { $publicFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -60,7 +60,7 @@ BeforeAll { $privateVariablesPath = Join-Path -Path $variablesPath -ChildPath 'private' $privateVariableFiles = (Test-Path -Path $privateVariablesPath) ? (Get-ChildItem -Path $privateVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private variable files [$($privateVariableFiles.Count)]" { + LogGroup " - Private [$($privateVariableFiles.Count)]" { $privateVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -68,14 +68,14 @@ BeforeAll { $publicVariablesPath = Join-Path -Path $variablesPath -ChildPath 'public' $publicVariableFiles = (Test-Path -Path $publicVariablesPath) ? (Get-ChildItem -Path $publicVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public variable files [$($publicVariableFiles.Count)]" { + LogGroup " - Public [$($publicVariableFiles.Count)]" { $publicVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $classPath = Join-Path -Path $Path -ChildPath 'classes' $classFiles = (Test-Path -Path $classPath) ? (Get-ChildItem -Path $classPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Class files [$($classFiles.Count)]" { + LogGroup " - Class[$($classFiles.Count)]" { $classFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -83,7 +83,7 @@ BeforeAll { $privateClassPath = Join-Path -Path $classPath -ChildPath 'private' $privateClassFiles = (Test-Path -Path $privateClassPath) ? (Get-ChildItem -Path $privateClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private class files [$($privateClassFiles.Count)]" { + LogGroup " - Private[$($privateClassFiles.Count)]" { $privateClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -91,7 +91,7 @@ BeforeAll { $publicClassPath = Join-Path -Path $classPath -ChildPath 'public' $publicClassFiles = (Test-Path -Path $publicClassPath) ? (Get-ChildItem -Path $publicClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public class files [$($publicClassFiles.Count)]" { + LogGroup " - Public[$($publicClassFiles.Count)]" { $publicClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } From ebcf5f6f6202cfea75c96eb71242208c5b0ae39d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Feb 2025 08:59:06 +0100 Subject: [PATCH 060/172] Refactor: Align log message formatting in PSModule.Tests.ps1 for improved readability --- .../SourceCode/PSModule/PSModule.Tests.ps1 | 22 +++++++++---------- .../PSScriptAnalyzer.Tests.ps1 | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index dbe8ca4c..38eee4d1 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -23,14 +23,14 @@ Param( BeforeAll { $scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File - LogGroup " - Script files [$($scriptFiles.Count)]" { + LogGroup " - Script files [$($scriptFiles.Count)]" { $scriptFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $functionsPath = Join-Path -Path $Path -ChildPath 'functions' $functionFiles = (Test-Path -Path $functionsPath) ? (Get-ChildItem -Path $functionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Function files [$($functionFiles.Count)]" { + LogGroup " - Function files [$($functionFiles.Count)]" { $functionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -38,21 +38,21 @@ BeforeAll { $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private' $privateFunctionFiles = (Test-Path -Path $privateFunctionsPath) ? (Get-ChildItem -Path $privateFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private [$($privateFunctionFiles.Count)]" { + LogGroup " - Private [$($privateFunctionFiles.Count)]" { $privateFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public' $publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public [$($publicFunctionFiles.Count)]" { + LogGroup " - Public [$($publicFunctionFiles.Count)]" { $publicFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $variablesPath = Join-Path -Path $Path -ChildPath 'variables' $variableFiles = (Test-Path -Path $variablesPath) ? (Get-ChildItem -Path $variablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Variable files [$($variableFiles.Count)]" { + LogGroup " - Variable files [$($variableFiles.Count)]" { $variableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -60,7 +60,7 @@ BeforeAll { $privateVariablesPath = Join-Path -Path $variablesPath -ChildPath 'private' $privateVariableFiles = (Test-Path -Path $privateVariablesPath) ? (Get-ChildItem -Path $privateVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private [$($privateVariableFiles.Count)]" { + LogGroup " - Private [$($privateVariableFiles.Count)]" { $privateVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -68,14 +68,14 @@ BeforeAll { $publicVariablesPath = Join-Path -Path $variablesPath -ChildPath 'public' $publicVariableFiles = (Test-Path -Path $publicVariablesPath) ? (Get-ChildItem -Path $publicVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public [$($publicVariableFiles.Count)]" { + LogGroup " - Public [$($publicVariableFiles.Count)]" { $publicVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $classPath = Join-Path -Path $Path -ChildPath 'classes' $classFiles = (Test-Path -Path $classPath) ? (Get-ChildItem -Path $classPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Class[$($classFiles.Count)]" { + LogGroup " - Class [$($classFiles.Count)]" { $classFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -83,7 +83,7 @@ BeforeAll { $privateClassPath = Join-Path -Path $classPath -ChildPath 'private' $privateClassFiles = (Test-Path -Path $privateClassPath) ? (Get-ChildItem -Path $privateClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private[$($privateClassFiles.Count)]" { + LogGroup " - Private [$($privateClassFiles.Count)]" { $privateClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } @@ -91,13 +91,13 @@ BeforeAll { $publicClassPath = Join-Path -Path $classPath -ChildPath 'public' $publicClassFiles = (Test-Path -Path $publicClassPath) ? (Get-ChildItem -Path $publicClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public[$($publicClassFiles.Count)]" { + LogGroup " - Public [$($publicClassFiles.Count)]" { $publicClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } } $testFiles = Get-ChildItem -Path $TestsPath -Include *.Tests.ps1 -Recurse -File - LogGroup " - Test files [$($testFiles.Count)]" { + LogGroup " - Test files [$($testFiles.Count)]" { $testFiles | ForEach-Object { Write-Host " - $($_.FullName)" } diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 2a6039b8..cd1e5cda 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -38,7 +38,7 @@ BeforeDiscovery { Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath]" { BeforeAll { - $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose:$false + $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose Write-Warning "Found [$($testResults.Count)] issues" } From 85d3dc45c851a83013db7e4433e1c2192042a1fd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Feb 2025 10:20:33 +0100 Subject: [PATCH 061/172] Refactor: Import settings file in PSScriptAnalyzer.Tests.ps1 for improved rule management --- .../SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index cd1e5cda..c4f7d2ef 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -20,6 +20,7 @@ Param( ) BeforeDiscovery { + $settings = Import-PowerShellDataFile -Path $SettingsFilePath $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() $ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName foreach ($ruleObject in $ruleObjects) { @@ -29,6 +30,7 @@ BeforeDiscovery { CommonName = $ruleObject.CommonName Severity = $ruleObject.Severity Description = $ruleObject.Description + Skip = $ruleObject.RuleName -in $settings.ExcludeRules } ) } @@ -43,7 +45,7 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] } Context 'Severity: <_>' -ForEach 'Error', 'Warning', 'Information' { - It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $_) { + It ' ()' -Skip:$Skip -ForEach ($rules | Where-Object -Property Severity -EQ $_) { $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') From 3f88258e99d20776f27dc790b9d43bdd7c046370 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Feb 2025 10:27:35 +0100 Subject: [PATCH 062/172] Refactor: Disable verbose output in Invoke-ScriptAnalyzer for cleaner test results --- .../SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index c4f7d2ef..94fd2007 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -40,12 +40,12 @@ BeforeDiscovery { Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath]" { BeforeAll { - $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose + $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose:$false Write-Warning "Found [$($testResults.Count)] issues" } Context 'Severity: <_>' -ForEach 'Error', 'Warning', 'Information' { - It ' ()' -Skip:$Skip -ForEach ($rules | Where-Object -Property Severity -EQ $_) { + It ' ()' -Skip:$_.Skip -ForEach ($rules | Where-Object -Property Severity -EQ $_) { $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') From c31447b928fca0d744156e411981183adf14f268 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 21 Feb 2025 10:50:04 +0100 Subject: [PATCH 063/172] Refactor: Enhance severity handling in PSScriptAnalyzer.Tests.ps1 for improved test organization --- .../PSScriptAnalyzer.Tests.ps1 | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 94fd2007..e6f59385 100644 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -23,6 +23,7 @@ BeforeDiscovery { $settings = Import-PowerShellDataFile -Path $SettingsFilePath $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() $ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName + $Severeties = $ruleObjects | Select-Object -ExpandProperty Severity -Unique foreach ($ruleObject in $ruleObjects) { $rules.Add( [ordered]@{ @@ -44,14 +45,29 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] Write-Warning "Found [$($testResults.Count)] issues" } - Context 'Severity: <_>' -ForEach 'Error', 'Warning', 'Information' { - It ' ()' -Skip:$_.Skip -ForEach ($rules | Where-Object -Property Severity -EQ $_) { - $issues = [Collections.Generic.List[string]]::new() - $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { - $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') - $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) + foreach ($Severety in $Severeties) { + Context "Severity: $Severety" { + foreach ($rule in $rules | Where-Object -Property Severity -EQ $Severety) { + It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip { + $issues = [Collections.Generic.List[string]]::new() + $testResults | Where-Object -Property RuleName -EQ $rule.RuleName | ForEach-Object { + $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') + $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) + } + $issues -join '' | Should -BeNullOrEmpty -Because $rule.Description + } } - $issues -join '' | Should -BeNullOrEmpty -Because $Description } } + + + # It ' ()' -Skip:$_.Skip -ForEach ($rules | Where-Object -Property Severity -EQ $_) { + # $issues = [Collections.Generic.List[string]]::new() + # $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { + # $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') + # $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) + # } + # $issues -join '' | Should -BeNullOrEmpty -Because $Description + # } + } From 191938913f54272858b3364015d12cf78382a164 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 22:23:43 +0100 Subject: [PATCH 064/172] Refactor: Update Invoke-Pester action to version 3 and remove obsolete PSScriptAnalyzer files --- action.yml | 2 +- .../PSScriptAnalyzer.Container.ps1 | 9 --- .../PSScriptAnalyzer.Settings.psd1 | 53 -------------- .../PSScriptAnalyzer.Tests.ps1 | 55 -------------- .../PSScriptAnalyzer.Container.ps1 | 9 --- .../PSScriptAnalyzer.Settings.psd1 | 56 -------------- .../PSScriptAnalyzer.Tests.ps1 | 73 ------------------- 7 files changed, 1 insertion(+), 256 deletions(-) delete mode 100644 scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 delete mode 100644 scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 delete mode 100644 scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 delete mode 100644 scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 delete mode 100644 scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 delete mode 100644 scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 diff --git a/action.yml b/action.yml index 6c92df17..e8b4afc9 100644 --- a/action.yml +++ b/action.yml @@ -55,7 +55,7 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - uses: PSModule/Invoke-Pester@fix + uses: PSModule/Invoke-Pester@v3 id: test with: TestResult_TestSuiteName: ${{ inputs.TestType }}-${{ inputs.OS }} diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 deleted file mode 100644 index 7d1e6540..00000000 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -@{ - Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName - Data = @{ - Path = "$env:GITHUB_ACTION_INPUT_Run_Path/output/modules/$env:ModuleName" - SettingsFilePath = "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" - Debug = $false - Verbose = $false - } -} diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 deleted file mode 100644 index 62a58184..00000000 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 +++ /dev/null @@ -1,53 +0,0 @@ -@{ - Rules = @{ - PSAlignAssignmentStatement = @{ - Enable = $true - CheckHashtable = $true - } - PSAvoidLongLines = @{ - Enable = $true - MaximumLineLength = 150 - } - PSAvoidSemicolonsAsLineTerminators = @{ - Enable = $true - } - PSPlaceCloseBrace = @{ - Enable = $true - NewLineAfter = $false - IgnoreOneLineBlock = $true - NoEmptyLineBefore = $false - } - PSPlaceOpenBrace = @{ - Enable = $true - OnSameLine = $true - NewLineAfter = $true - IgnoreOneLineBlock = $true - } - PSProvideCommentHelp = @{ - Enable = $true - ExportedOnly = $false - BlockComment = $true - VSCodeSnippetCorrection = $false - Placement = 'begin' - } - PSUseConsistentIndentation = @{ - Enable = $true - IndentationSize = 4 - PipelineIndentation = 'IncreaseIndentationForFirstPipeline' - Kind = 'space' - } - PSUseConsistentWhitespace = @{ - Enable = $true - CheckInnerBrace = $true - CheckOpenBrace = $true - CheckOpenParen = $true - CheckOperator = $true - CheckPipe = $true - CheckPipeForRedundantWhitespace = $true - CheckSeparator = $true - CheckParameter = $true - IgnoreAssignmentOperatorInsideHashTable = $true - } - } - ExcludeRules = @() -} diff --git a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 deleted file mode 100644 index 2a6039b8..00000000 --- a/scripts/tests/Module/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ /dev/null @@ -1,55 +0,0 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSReviewUnusedParameter', 'Path', - Justification = 'Path is being used.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSReviewUnusedParameter', 'SettingsFilePath', - Justification = 'SettingsFilePath is being used.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseDeclaredVarsMoreThanAssignments', 'relativeSettingsFilePath', - Justification = 'relativeSettingsFilePath is being used.' -)] -[CmdLetBinding()] -Param( - [Parameter(Mandatory)] - [string] $Path, - - [Parameter(Mandatory)] - [string] $SettingsFilePath -) - -BeforeDiscovery { - $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() - $ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName - foreach ($ruleObject in $ruleObjects) { - $rules.Add( - [ordered]@{ - RuleName = $ruleObject.RuleName - CommonName = $ruleObject.CommonName - Severity = $ruleObject.Severity - Description = $ruleObject.Description - } - ) - } - Write-Warning "Discovered [$($rules.Count)] rules" - $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/') -} - -Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath]" { - BeforeAll { - $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose:$false - Write-Warning "Found [$($testResults.Count)] issues" - } - - Context 'Severity: <_>' -ForEach 'Error', 'Warning', 'Information' { - It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $_) { - $issues = [Collections.Generic.List[string]]::new() - $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { - $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') - $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) - } - $issues -join '' | Should -BeNullOrEmpty -Because $Description - } - } -} diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 deleted file mode 100644 index edd63bf2..00000000 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Container.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -@{ - Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName - Data = @{ - Path = "$env:GITHUB_ACTION_INPUT_Run_Path" | Get-Item - SettingsFilePath = "$PSScriptRoot/PSScriptAnalyzer.Settings.psd1" | Get-Item - Debug = $false - Verbose = $false - } -} diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 deleted file mode 100644 index 09cc3d0c..00000000 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Settings.psd1 +++ /dev/null @@ -1,56 +0,0 @@ -@{ - Rules = @{ - PSAlignAssignmentStatement = @{ - Enable = $true - CheckHashtable = $true - } - PSAvoidLongLines = @{ - Enable = $true - MaximumLineLength = 150 - } - PSAvoidSemicolonsAsLineTerminators = @{ - Enable = $true - } - PSPlaceCloseBrace = @{ - Enable = $true - NewLineAfter = $false - IgnoreOneLineBlock = $true - NoEmptyLineBefore = $false - } - PSPlaceOpenBrace = @{ - Enable = $true - OnSameLine = $true - NewLineAfter = $true - IgnoreOneLineBlock = $true - } - PSProvideCommentHelp = @{ - Enable = $true - ExportedOnly = $false - BlockComment = $true - VSCodeSnippetCorrection = $false - Placement = 'begin' - } - PSUseConsistentIndentation = @{ - Enable = $true - IndentationSize = 4 - PipelineIndentation = 'IncreaseIndentationForFirstPipeline' - Kind = 'space' - } - PSUseConsistentWhitespace = @{ - Enable = $true - CheckInnerBrace = $true - CheckOpenBrace = $true - CheckOpenParen = $true - CheckOperator = $true - CheckPipe = $true - CheckPipeForRedundantWhitespace = $true - CheckSeparator = $true - CheckParameter = $true - IgnoreAssignmentOperatorInsideHashTable = $true - } - } - ExcludeRules = @( - 'PSMissingModuleManifestField', # This rule is not applicable until the module is built. - 'PSUseToExportFieldsInManifest' - ) -} diff --git a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 deleted file mode 100644 index e6f59385..00000000 --- a/scripts/tests/SourceCode/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ /dev/null @@ -1,73 +0,0 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSReviewUnusedParameter', 'Path', - Justification = 'Path is being used.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSReviewUnusedParameter', 'SettingsFilePath', - Justification = 'SettingsFilePath is being used.' -)] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseDeclaredVarsMoreThanAssignments', 'relativeSettingsFilePath', - Justification = 'relativeSettingsFilePath is being used.' -)] -[CmdLetBinding()] -Param( - [Parameter(Mandatory)] - [string] $Path, - - [Parameter(Mandatory)] - [string] $SettingsFilePath -) - -BeforeDiscovery { - $settings = Import-PowerShellDataFile -Path $SettingsFilePath - $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() - $ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName - $Severeties = $ruleObjects | Select-Object -ExpandProperty Severity -Unique - foreach ($ruleObject in $ruleObjects) { - $rules.Add( - [ordered]@{ - RuleName = $ruleObject.RuleName - CommonName = $ruleObject.CommonName - Severity = $ruleObject.Severity - Description = $ruleObject.Description - Skip = $ruleObject.RuleName -in $settings.ExcludeRules - } - ) - } - Write-Warning "Discovered [$($rules.Count)] rules" - $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/') -} - -Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath]" { - BeforeAll { - $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose:$false - Write-Warning "Found [$($testResults.Count)] issues" - } - - foreach ($Severety in $Severeties) { - Context "Severity: $Severety" { - foreach ($rule in $rules | Where-Object -Property Severity -EQ $Severety) { - It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip { - $issues = [Collections.Generic.List[string]]::new() - $testResults | Where-Object -Property RuleName -EQ $rule.RuleName | ForEach-Object { - $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') - $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) - } - $issues -join '' | Should -BeNullOrEmpty -Because $rule.Description - } - } - } - } - - - # It ' ()' -Skip:$_.Skip -ForEach ($rules | Where-Object -Property Severity -EQ $_) { - # $issues = [Collections.Generic.List[string]]::new() - # $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { - # $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') - # $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) - # } - # $issues -join '' | Should -BeNullOrEmpty -Because $Description - # } - -} From 51e445619e0e16baef1b944eb5085a49671ac9e4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 22:33:55 +0100 Subject: [PATCH 065/172] Refactor: Consolidate action test workflows into a single Action-Test.yml file --- .github/workflows/Action-Test-Src-Default.yml | 51 ---------- .../Action-Test-Src-WithManifest.yml | 51 ---------- .github/workflows/Action-Test-outputs.yml | 51 ---------- .github/workflows/Action-Test.yml | 92 +++++++++++++++++++ action.yml | 20 ---- 5 files changed, 92 insertions(+), 173 deletions(-) delete mode 100644 .github/workflows/Action-Test-Src-Default.yml delete mode 100644 .github/workflows/Action-Test-Src-WithManifest.yml delete mode 100644 .github/workflows/Action-Test-outputs.yml create mode 100644 .github/workflows/Action-Test.yml diff --git a/.github/workflows/Action-Test-Src-Default.yml b/.github/workflows/Action-Test-Src-Default.yml deleted file mode 100644 index c48f749e..00000000 --- a/.github/workflows/Action-Test-Src-Default.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Action-Test [Src-Default] - -run-name: "Action-Test [Src-Default] - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '0 0 * * *' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: {} - -jobs: - ActionTest: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - name: Action-Test [Src-Default] - [${{ matrix.os }}] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - - name: Action-Test - uses: ./ - id: action-test - env: - GITHUB_TOKEN: ${{ github.token }} - with: - Name: PSModuleTest - Path: tests/srcTestRepo - TestType: SourceCode - OS: ${{ matrix.os }} - - - name: Status - shell: pwsh - env: - PASSED: ${{ steps.action-test.outputs.passed }} - run: | - Write-Host "Passed: [$env:PASSED]" - if ($env:PASSED -ne 'true') { - exit 1 - } diff --git a/.github/workflows/Action-Test-Src-WithManifest.yml b/.github/workflows/Action-Test-Src-WithManifest.yml deleted file mode 100644 index 8ce25e4c..00000000 --- a/.github/workflows/Action-Test-Src-WithManifest.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Action-Test [Src-WithManifest] - -run-name: "Action-Test [Src-WithManifest] - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '0 0 * * *' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: {} - -jobs: - ActionTest: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - name: Action-Test [Src-WithManifest] - [${{ matrix.os }}] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - - name: Action-Test - uses: ./ - id: action-test - env: - GITHUB_TOKEN: ${{ github.token }} - with: - Name: PSModuleTest - Path: tests/srcWithManifestTestRepo - TestType: SourceCode - OS: ${{ matrix.os }} - - - name: Status - shell: pwsh - env: - PASSED: ${{ steps.action-test.outputs.passed }} - run: | - Write-Host "Passed: [$env:PASSED]" - if ($env:PASSED -ne 'true') { - exit 1 - } diff --git a/.github/workflows/Action-Test-outputs.yml b/.github/workflows/Action-Test-outputs.yml deleted file mode 100644 index 0406a4c7..00000000 --- a/.github/workflows/Action-Test-outputs.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Action-Test [outputs] - -run-name: "Action-Test [outputs] - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '0 0 * * *' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: {} - -jobs: - ActionTest: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - name: Action-Test [outputs] - [${{ matrix.os }}] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - - name: Action-Test - uses: ./ - id: action-test - env: - GITHUB_TOKEN: ${{ github.token }} - with: - Name: PSModuleTest - Path: tests/outputTestRepo - TestType: Module - OS: ${{ matrix.os }} - - - name: Status - shell: pwsh - env: - PASSED: ${{ steps.action-test.outputs.passed }} - run: | - Write-Host "Passed: [$env:PASSED]" - if ($env:PASSED -ne 'true') { - exit 1 - } diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml new file mode 100644 index 00000000..33515035 --- /dev/null +++ b/.github/workflows/Action-Test.yml @@ -0,0 +1,92 @@ +name: Action-Test + +run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" + +on: + workflow_dispatch: + pull_request: + schedule: + - cron: '0 0 * * *' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +jobs: + ActionTestOutputs: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + name: Action-Test [outputs] - [${{ matrix.os }}] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + + - name: Action-Test + uses: ./ + id: action-test + env: + GITHUB_TOKEN: ${{ github.token }} + with: + Name: PSModuleTest + Path: tests/outputTestRepo + TestType: Module + OS: ${{ matrix.os }} + + ActionTestSrcDefault: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + name: Action-Test [Src-Default] - [${{ matrix.os }}] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + + - name: Action-Test + uses: ./ + id: action-test + env: + GITHUB_TOKEN: ${{ github.token }} + with: + Name: PSModuleTest + Path: tests/srcTestRepo + TestType: SourceCode + OS: ${{ matrix.os }} + + + ActionTestsSrcWithManifest: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + name: Action-Test [Src-WithManifest] - [${{ matrix.os }}] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + + - name: Action-Test + uses: ./ + id: action-test + env: + GITHUB_TOKEN: ${{ github.token }} + with: + Name: PSModuleTest + Path: tests/srcWithManifestTestRepo + TestType: SourceCode + OS: ${{ matrix.os }} diff --git a/action.yml b/action.yml index e8b4afc9..9571fa12 100644 --- a/action.yml +++ b/action.yml @@ -19,26 +19,6 @@ inputs: OS: description: The operating system to run the tests on. required: true - # Debug: - # description: Enable debug output. - # required: false - # default: 'false' - # Verbose: - # description: Enable verbose output. - # required: false - # default: 'false' - # Version: - # description: Specifies the version of the GitHub module to be installed. The value must be an exact version. - # required: false - # Prerelease: - # description: Allow prerelease versions if available. - # required: false - # default: 'false' - -outputs: - passed: - description: If the tests passed. - value: ${{ steps.test.outputs.Passed }} runs: using: composite From 0a40039f3f9c2f884cb7bac57c1dc3a307cc7370 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 22:47:04 +0100 Subject: [PATCH 066/172] Refactor: Update Action-Test workflows to streamline settings and test suite naming --- .github/workflows/Action-Test.yml | 34 ++++++++----------------------- action.yml | 2 +- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 33515035..bc681cab 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -16,77 +16,61 @@ permissions: {} jobs: ActionTestOutputs: + name: Action-Test [outputs] - [${{ matrix.os }}] strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - name: Action-Test [outputs] - [${{ matrix.os }}] runs-on: ${{ matrix.os }} steps: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Action-Test uses: ./ id: action-test - env: - GITHUB_TOKEN: ${{ github.token }} with: Name: PSModuleTest Path: tests/outputTestRepo - TestType: Module - OS: ${{ matrix.os }} + Settings: Module + TestSuiteName: outputs-Module-${{ matrix.os }} ActionTestSrcDefault: + name: Action-Test [Src-Default] - [${{ matrix.os }}] strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - name: Action-Test [Src-Default] - [${{ matrix.os }}] runs-on: ${{ matrix.os }} steps: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Action-Test uses: ./ id: action-test - env: - GITHUB_TOKEN: ${{ github.token }} with: Name: PSModuleTest Path: tests/srcTestRepo - TestType: SourceCode - OS: ${{ matrix.os }} - + Settings: SourceCode + TestSuiteName: SrcDefault-SourceCode-${{ matrix.os }} ActionTestsSrcWithManifest: + name: Action-Test [Src-WithManifest] - [${{ matrix.os }}] strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - name: Action-Test [Src-WithManifest] - [${{ matrix.os }}] runs-on: ${{ matrix.os }} steps: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Action-Test uses: ./ id: action-test - env: - GITHUB_TOKEN: ${{ github.token }} with: Name: PSModuleTest Path: tests/srcWithManifestTestRepo - TestType: SourceCode - OS: ${{ matrix.os }} + Settings: SourceCode + TestSuiteName: SrcWithManifest-SourceCode-${{ matrix.os }} diff --git a/action.yml b/action.yml index 9571fa12..c82c637f 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,6 @@ runs: uses: PSModule/Invoke-Pester@v3 id: test with: - TestResult_TestSuiteName: ${{ inputs.TestType }}-${{ inputs.OS }} + TestResult_TestSuiteName: ${{ inputs.TestSuiteName}} Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} From 588f2bbb3e9c7c1628ef909c5de8b4f5e42151a8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 23:06:44 +0100 Subject: [PATCH 067/172] Refactor: Rename TestType input to Settings and update related references for clarity --- action.yml | 11 ++++------- scripts/main.ps1 | 16 ++++++++++------ scripts/tests/Module/Module.Configuration.ps1 | 3 --- .../SourceCode/SourceCode.Configuration.ps1 | 3 --- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/action.yml b/action.yml index c82c637f..bcfa8102 100644 --- a/action.yml +++ b/action.yml @@ -13,12 +13,10 @@ inputs: description: The path to the repo. required: true default: ${{ github.workspace }} - TestType: + Settings: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true - OS: - description: The operating system to run the tests on. - required: true + runs: using: composite @@ -29,8 +27,7 @@ runs: env: GITHUB_ACTION_INPUT_TEST_PSMODULE_Name: ${{ inputs.Name }} GITHUB_ACTION_INPUT_TEST_PSMODULE_Path: ${{ inputs.Path }} - GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType: ${{ inputs.TestType }} - GITHUB_ACTION_INPUT_TEST_PSMODULE_OS: ${{ inputs.OS }} + GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings: ${{ inputs.Settings }} with: Script: ${{ github.action_path }}/scripts/main.ps1 @@ -38,6 +35,6 @@ runs: uses: PSModule/Invoke-Pester@v3 id: test with: - TestResult_TestSuiteName: ${{ inputs.TestSuiteName}} + TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 381b9789..7ed3a611 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,8 +1,12 @@ # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. -$moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name -$testType = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_TestType -$testPath = Resolve-Path -Path "$PSScriptRoot/tests/$testType" | Select-Object -ExpandProperty Path -$codePath = switch ($testType) { +$moduleName = if ([string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name)) { + $env:GITHUB_REPOSITORY_NAME +} else { + $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name +} +$settings = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings +$testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path +$codePath = switch ($settings) { 'Module' { Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path } @@ -10,13 +14,13 @@ $codePath = switch ($testType) { Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path } default { - throw "Invalid test type: [$testType]" + throw "Invalid test type: [$settings]" } } [pscustomobject]@{ ModuleName = $moduleName - TestType = $testType + Settings = $settings CodePath = $codePath TestPath = $testPath } | Format-List diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index e21afb2e..3b6e185e 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,7 +1,4 @@ @{ - TestResult = @{ - Enabled = $true - } CodeCoverage = @{ Enabled = $true OutputFormat = 'JaCoCo' diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 index e76f767f..07385eba 100644 --- a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -1,7 +1,4 @@ @{ - TestResult = @{ - Enabled = $true - } Output = @{ Verbosity = 'Detailed' } From add09cd19209f8e26d5e0549052023f48580a85a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 23:11:01 +0100 Subject: [PATCH 068/172] Refactor: Add environment initialization step to action workflow --- action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index bcfa8102..de72e685 100644 --- a/action.yml +++ b/action.yml @@ -17,10 +17,12 @@ inputs: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true - runs: using: composite steps: + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + - name: Get test paths uses: PSModule/Github-Script@v1 id: paths From e3bfac1d49ea47c4dbecffe4cd6a806ce76a3363 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 23:20:27 +0100 Subject: [PATCH 069/172] Refactor: Remove TestSuiteName from Action-Test workflows and simplify path handling in PSModule.Container scripts --- .github/workflows/Action-Test.yml | 3 --- scripts/tests/Module/PSModule/PSModule.Container.ps1 | 2 +- scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index bc681cab..79a72205 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -33,7 +33,6 @@ jobs: Name: PSModuleTest Path: tests/outputTestRepo Settings: Module - TestSuiteName: outputs-Module-${{ matrix.os }} ActionTestSrcDefault: name: Action-Test [Src-Default] - [${{ matrix.os }}] @@ -53,7 +52,6 @@ jobs: Name: PSModuleTest Path: tests/srcTestRepo Settings: SourceCode - TestSuiteName: SrcDefault-SourceCode-${{ matrix.os }} ActionTestsSrcWithManifest: name: Action-Test [Src-WithManifest] - [${{ matrix.os }}] @@ -73,4 +71,3 @@ jobs: Name: PSModuleTest Path: tests/srcWithManifestTestRepo Settings: SourceCode - TestSuiteName: SrcWithManifest-SourceCode-${{ matrix.os }} diff --git a/scripts/tests/Module/PSModule/PSModule.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 index 80d2b93b..37c6bb30 100644 --- a/scripts/tests/Module/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_ACTION_INPUT_Run_Path/output/modules/$env:ModuleName" + Path = $env:GITHUB_ACTION_INPUT_Run_Path Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index 21297ac1..85ddb7a0 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = "$env:GITHUB_ACTION_INPUT_Run_Path" | Get-Item - TestsPath = "$env:GITHUB_ACTION_INPUT_Run_Path/../tests" | Get-Item + Path = $env:GITHUB_ACTION_INPUT_Run_Path + TestsPath = Resolve-Path $env:GITHUB_ACTION_INPUT_Run_Path/../tests | Select-Object -ExpandProperty Path Debug = $false Verbose = $false } From 121eeaaf070fc178a5eafaca98444f0e6ae84b4b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 00:10:40 +0100 Subject: [PATCH 070/172] Refactor: Add debug, verbose, version, and prerelease inputs to action.yml for enhanced configuration options --- action.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/action.yml b/action.yml index de72e685..e1c3971d 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,21 @@ inputs: Settings: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true + Debug: + description: Enable debug output. + required: false + default: 'false' + Verbose: + description: Enable verbose output. + required: false + default: 'false' + Version: + description: Specifies the version of the GitHub module to be installed. The value must be an exact version. + required: false + Prerelease: + description: Allow prerelease versions if available. + required: false + default: 'false' runs: using: composite @@ -31,12 +46,20 @@ runs: GITHUB_ACTION_INPUT_TEST_PSMODULE_Path: ${{ inputs.Path }} GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings: ${{ inputs.Settings }} with: + Debug: ${{ inputs.Debug }} + Prerelease: ${{ inputs.Prerelease }} + Verbose: ${{ inputs.Verbose }} + Version: ${{ inputs.Version }} Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester uses: PSModule/Invoke-Pester@v3 id: test with: + Debug: ${{ inputs.Debug }} + Prerelease: ${{ inputs.Prerelease }} + Verbose: ${{ inputs.Verbose }} + Version: ${{ inputs.Version }} TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} From ce3426f8cf0d3cfaa33710f7dd0c1e2b6b451bd3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 00:14:22 +0100 Subject: [PATCH 071/172] Refactor: Suppress Write-Host warnings for logging in GitHub Actions and adjust output verbosity settings --- scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 | 4 ++++ scripts/tests/SourceCode/SourceCode.Configuration.ps1 | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index 38eee4d1..05d6ad67 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -10,6 +10,10 @@ 'PSUseDeclaredVarsMoreThanAssignments', 'functionBearingFiles', Justification = 'Variables are used in the test.' )] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Logging to Github Actions.' +)] [CmdLetBinding()] Param( # The path to the 'src' folder of the repo. diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 index 07385eba..e4950855 100644 --- a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -1,5 +1,5 @@ @{ - Output = @{ + Output = @{ Verbosity = 'Detailed' } } From 32377f38475e7827417e33e83cab56a52aef15df Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 00:49:12 +0100 Subject: [PATCH 072/172] Refactor: Update path resolution for module outputs in PSModule.Container scripts --- scripts/tests/Module/PSModule/PSModule.Container.ps1 | 2 +- scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 index 37c6bb30..a9c5738c 100644 --- a/scripts/tests/Module/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $env:GITHUB_ACTION_INPUT_Run_Path + Path = Resolve-Path "$env:GITHUB_ACTION_INPUT_Run_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index 85ddb7a0..ca4c13ca 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $env:GITHUB_ACTION_INPUT_Run_Path + Path = Resolve-Path "$env:GITHUB_ACTION_INPUT_Run_Path/src" | Select-Object -ExpandProperty Path TestsPath = Resolve-Path $env:GITHUB_ACTION_INPUT_Run_Path/../tests | Select-Object -ExpandProperty Path Debug = $false Verbose = $false From 4a711eb1a08ba8f4c14277dacf5a7c2bfdbdf78b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 01:57:47 +0100 Subject: [PATCH 073/172] Refactor: Enhance module name handling in action workflow and update path resolution in test scripts --- action.yml | 2 ++ scripts/main.ps1 | 13 ++----------- .../tests/Module/PSModule/PSModule.Container.ps1 | 2 +- .../SourceCode/PSModule/PSModule.Container.ps1 | 4 ++-- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index e1c3971d..d2a831d6 100644 --- a/action.yml +++ b/action.yml @@ -55,6 +55,8 @@ runs: - name: Invoke-Pester uses: PSModule/Invoke-Pester@v3 id: test + env: + ModuleName: ${{ fromJson(steps.paths.outputs.result).ModuleName }} with: Debug: ${{ inputs.Debug }} Prerelease: ${{ inputs.Prerelease }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 7ed3a611..0c35f5eb 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -6,17 +6,7 @@ $moduleName = if ([string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE } $settings = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path -$codePath = switch ($settings) { - 'Module' { - Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path - } - 'SourceCode' { - Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path - } - default { - throw "Invalid test type: [$settings]" - } -} +$codePath = Resolve-Path -Path $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path [pscustomobject]@{ ModuleName = $moduleName @@ -25,5 +15,6 @@ $codePath = switch ($settings) { TestPath = $testPath } | Format-List +Set-GitHubOutput -Name ModuleName -Value $moduleName Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name TestPath -Value $testPath diff --git a/scripts/tests/Module/PSModule/PSModule.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 index a9c5738c..ce77ee3b 100644 --- a/scripts/tests/Module/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path "$env:GITHUB_ACTION_INPUT_Run_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path + Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Run_Path/outputs/modules/$env:ModuleName" | Select-Object -ExpandProperty Path Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index ca4c13ca..75f09a2d 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path "$env:GITHUB_ACTION_INPUT_Run_Path/src" | Select-Object -ExpandProperty Path - TestsPath = Resolve-Path $env:GITHUB_ACTION_INPUT_Run_Path/../tests | Select-Object -ExpandProperty Path + Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Run_Path/src" | Select-Object -ExpandProperty Path + TestsPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Run_Path/tests" | Select-Object -ExpandProperty Path Debug = $false Verbose = $false } From 18285b7650f622c9e297e7ca9c76db44560c8524 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 02:39:13 +0100 Subject: [PATCH 074/172] Refactor: Update test path handling in action workflow and scripts for improved clarity and functionality --- action.yml | 2 +- scripts/main.ps1 | 25 +++++++++++++------ .../Module/PSModule/PSModule.Container.ps1 | 2 +- .../PSModule/PSModule.Container.ps1 | 4 +-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index d2a831d6..9cc399dd 100644 --- a/action.yml +++ b/action.yml @@ -56,7 +56,7 @@ runs: uses: PSModule/Invoke-Pester@v3 id: test env: - ModuleName: ${{ fromJson(steps.paths.outputs.result).ModuleName }} + LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} with: Debug: ${{ inputs.Debug }} Prerelease: ${{ inputs.Prerelease }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 0c35f5eb..f08c5a52 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -6,15 +6,26 @@ $moduleName = if ([string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE } $settings = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path -$codePath = Resolve-Path -Path $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path | Select-Object -ExpandProperty Path - +$localTestPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path +$codePath = switch ($settings) { + 'Module' { + Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path + } + 'SourceCode' { + Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path + } + default { + throw "Invalid test type: [$settings]" + } +} [pscustomobject]@{ - ModuleName = $moduleName - Settings = $settings - CodePath = $codePath - TestPath = $testPath + ModuleName = $moduleName + Settings = $settings + CodePath = $codePath + LocalTestPath = $localTestPath + TestPath = $testPath } | Format-List -Set-GitHubOutput -Name ModuleName -Value $moduleName Set-GitHubOutput -Name CodePath -Value $codePath +Set-GitHubOutput -Name LocalTestPath -Value $localTestPath Set-GitHubOutput -Name TestPath -Value $testPath diff --git a/scripts/tests/Module/PSModule/PSModule.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 index ce77ee3b..37c6bb30 100644 --- a/scripts/tests/Module/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Run_Path/outputs/modules/$env:ModuleName" | Select-Object -ExpandProperty Path + Path = $env:GITHUB_ACTION_INPUT_Run_Path Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index 75f09a2d..66c3d5a3 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,8 +1,8 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Run_Path/src" | Select-Object -ExpandProperty Path - TestsPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Run_Path/tests" | Select-Object -ExpandProperty Path + Path = $env:GITHUB_ACTION_INPUT_Run_Path + TestsPath = $env:LocalTestPath Debug = $false Verbose = $false } From 071ff41298c8d955ca1bd51505cb38294d7b18b0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 02:41:57 +0100 Subject: [PATCH 075/172] Refactor: Update local test path resolution in main.ps1 for improved clarity in source code handling --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index f08c5a52..db9db737 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -6,12 +6,12 @@ $moduleName = if ([string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE } $settings = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path -$localTestPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path $codePath = switch ($settings) { 'Module' { Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path } 'SourceCode' { + $localTestPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path } default { From cf8ae08c5eafbea9b194bd353200ca04d2eadb84 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 02:46:58 +0100 Subject: [PATCH 076/172] Refactor: Enhance test path resolution in main.ps1 and add environment variable tests --- scripts/main.ps1 | 3 +- .../tests/Environments/Environment.Tests.ps1 | 15 +++++++ .../tests/MyTests/PSModuleTest.Tests.ps1 | 44 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/outputTestRepo/tests/Environments/Environment.Tests.ps1 create mode 100644 tests/outputTestRepo/tests/MyTests/PSModuleTest.Tests.ps1 diff --git a/scripts/main.ps1 b/scripts/main.ps1 index db9db737..7ede76d7 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -6,12 +6,12 @@ $moduleName = if ([string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE } $settings = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path +$localTestPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path $codePath = switch ($settings) { 'Module' { Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path } 'SourceCode' { - $localTestPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path } default { @@ -26,6 +26,7 @@ $codePath = switch ($settings) { TestPath = $testPath } | Format-List +Set-GitHubOutput -Name ModuleName -Value $moduleName Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name LocalTestPath -Value $localTestPath Set-GitHubOutput -Name TestPath -Value $testPath diff --git a/tests/outputTestRepo/tests/Environments/Environment.Tests.ps1 b/tests/outputTestRepo/tests/Environments/Environment.Tests.ps1 new file mode 100644 index 00000000..211be946 --- /dev/null +++ b/tests/outputTestRepo/tests/Environments/Environment.Tests.ps1 @@ -0,0 +1,15 @@ +Describe 'Environment Variables are available' { + It 'Should be available [<_>]' -ForEach @( + 'TEST_APP_ENT_CLIENT_ID', + 'TEST_APP_ENT_PRIVATE_KEY', + 'TEST_APP_ORG_CLIENT_ID', + 'TEST_APP_ORG_PRIVATE_KEY', + 'TEST_USER_ORG_FG_PAT', + 'TEST_USER_USER_FG_PAT', + 'TEST_USER_PAT' + ) { + $name = $_ + Write-Verbose "Environment variable: [$name]" -Verbose + Get-ChildItem env: | Where-Object { $_.Name -eq $name } | Should -Not -BeNullOrEmpty + } +} diff --git a/tests/outputTestRepo/tests/MyTests/PSModuleTest.Tests.ps1 b/tests/outputTestRepo/tests/MyTests/PSModuleTest.Tests.ps1 new file mode 100644 index 00000000..9bf1bb64 --- /dev/null +++ b/tests/outputTestRepo/tests/MyTests/PSModuleTest.Tests.ps1 @@ -0,0 +1,44 @@ +[CmdletBinding()] +Param( + # Path to the module to test. + [Parameter()] + [string] $Path +) + +Write-Verbose "Path to the module: [$Path]" -Verbose +Describe 'PSModuleTest.Tests.ps1' { + Context 'Function: Test-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Test-PSModuleTest -Name 'World' | Out-String) -Verbose + Test-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: Get-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Get-PSModuleTest -Name 'World' | Out-String) -Verbose + Get-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: New-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (New-PSModuleTest -Name 'World' | Out-String) -Verbose + New-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Function: Set-PSModuleTest' { + It 'Should be able to call the function' { + Write-Verbose (Set-PSModuleTest -Name 'World' | Out-String) -Verbose + Set-PSModuleTest -Name 'World' | Should -Be 'Hello, World!' + } + } + + Context 'Variables' { + It "Exports a variable for SolarSystems that contains 'Solar System'" { + Write-Verbose ($SolarSystems | Out-String) -Verbose + $SolarSystems[0].Name | Should -Be 'Solar System' + } + } +} From 91d1c87303b0832b099180ee1bfb850e3e64a9e6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 12:20:21 +0100 Subject: [PATCH 077/172] Refactor: Add environment initialization step in Action-Test workflow and remove from action.yml --- .github/workflows/Action-Test.yml | 9 +++++++++ action.yml | 3 --- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 79a72205..f571b113 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -26,6 +26,9 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + - name: Action-Test uses: ./ id: action-test @@ -45,6 +48,9 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + - name: Action-Test uses: ./ id: action-test @@ -64,6 +70,9 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 + - name: Initialize environment + uses: PSModule/Initialize-PSModule@main + - name: Action-Test uses: ./ id: action-test diff --git a/action.yml b/action.yml index 9cc399dd..f1bdbbc9 100644 --- a/action.yml +++ b/action.yml @@ -35,9 +35,6 @@ inputs: runs: using: composite steps: - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Get test paths uses: PSModule/Github-Script@v1 id: paths From 3c310e59d2ae91bf5662e7780cee0c0980d783d6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 13:09:07 +0100 Subject: [PATCH 078/172] Refactor: Correct module output path in README and main.ps1 for consistency --- README.md | 2 +- scripts/main.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2461ad07..049c6d63 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ jobs: - name: Test-PSModule uses: PSModule/Test-PSModule@main with: - Path: outputs/modules + Path: outputs/module TestType: Module ``` diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 7ede76d7..14e7f928 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -9,7 +9,7 @@ $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object - $localTestPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path $codePath = switch ($settings) { 'Module' { - Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/modules/$moduleName" | Select-Object -ExpandProperty Path + Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/module/$moduleName" | Select-Object -ExpandProperty Path } 'SourceCode' { Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path From c95d6aa8996b69b3716831612f7651dd97c22ff2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 16:49:11 +0100 Subject: [PATCH 079/172] Refactor: Add new configuration and type definition files for PSModuleTest, remove obsolete files --- .../PSModuleTest/PSModuleTest.psd1 | 0 .../PSModuleTest/PSModuleTest.psm1 | 0 .../PSModuleTest/assemblies/LsonLib.dll | Bin .../PSModuleTest/data/Config.psd1 | 0 .../PSModuleTest/data/Settings.psd1 | 0 .../PSModuleTest/formats/CultureInfo.Format.ps1xml | 0 .../PSModuleTest/formats/Mygciview.Format.ps1xml | 0 .../PSModuleTest/modules/OtherPSModule.psm1 | 0 .../PSModuleTest/scripts/loader.ps1 | 0 .../PSModuleTest/types/DirectoryInfo.Types.ps1xml | 0 .../PSModuleTest/types/FileInfo.Types.ps1xml | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/PSModuleTest.psd1 (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/PSModuleTest.psm1 (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/assemblies/LsonLib.dll (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/data/Config.psd1 (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/data/Settings.psd1 (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/formats/CultureInfo.Format.ps1xml (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/formats/Mygciview.Format.ps1xml (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/modules/OtherPSModule.psm1 (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/scripts/loader.ps1 (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/types/DirectoryInfo.Types.ps1xml (100%) rename tests/outputTestRepo/outputs/{modules => module}/PSModuleTest/types/FileInfo.Types.ps1xml (100%) diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psd1 b/tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psd1 similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psd1 rename to tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psd1 diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psm1 b/tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psm1 similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psm1 rename to tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psm1 diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/assemblies/LsonLib.dll b/tests/outputTestRepo/outputs/module/PSModuleTest/assemblies/LsonLib.dll similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/assemblies/LsonLib.dll rename to tests/outputTestRepo/outputs/module/PSModuleTest/assemblies/LsonLib.dll diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/data/Config.psd1 b/tests/outputTestRepo/outputs/module/PSModuleTest/data/Config.psd1 similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/data/Config.psd1 rename to tests/outputTestRepo/outputs/module/PSModuleTest/data/Config.psd1 diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/data/Settings.psd1 b/tests/outputTestRepo/outputs/module/PSModuleTest/data/Settings.psd1 similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/data/Settings.psd1 rename to tests/outputTestRepo/outputs/module/PSModuleTest/data/Settings.psd1 diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml b/tests/outputTestRepo/outputs/module/PSModuleTest/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml rename to tests/outputTestRepo/outputs/module/PSModuleTest/formats/CultureInfo.Format.ps1xml diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml b/tests/outputTestRepo/outputs/module/PSModuleTest/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml rename to tests/outputTestRepo/outputs/module/PSModuleTest/formats/Mygciview.Format.ps1xml diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 b/tests/outputTestRepo/outputs/module/PSModuleTest/modules/OtherPSModule.psm1 similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 rename to tests/outputTestRepo/outputs/module/PSModuleTest/modules/OtherPSModule.psm1 diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/scripts/loader.ps1 b/tests/outputTestRepo/outputs/module/PSModuleTest/scripts/loader.ps1 similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/scripts/loader.ps1 rename to tests/outputTestRepo/outputs/module/PSModuleTest/scripts/loader.ps1 diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml b/tests/outputTestRepo/outputs/module/PSModuleTest/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml rename to tests/outputTestRepo/outputs/module/PSModuleTest/types/DirectoryInfo.Types.ps1xml diff --git a/tests/outputTestRepo/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml b/tests/outputTestRepo/outputs/module/PSModuleTest/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/outputTestRepo/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml rename to tests/outputTestRepo/outputs/module/PSModuleTest/types/FileInfo.Types.ps1xml From 51ab417254b80917983f059972930c6b029d5f9b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Feb 2025 22:27:01 +0100 Subject: [PATCH 080/172] Refactor: Add Add-PSModulePath helper function and improve variable consistency in module helpers --- .../PSModule/helpers/Add-PSModulePath.ps1 | 29 +++++++++++++++++++ .../PSModule/helpers/Import-PSModule.ps1 | 17 +++++------ .../PSModule/helpers/Remove-PSModule.ps1 | 1 - .../helpers/Resolve-PSModuleDependency.ps1 | 20 ++++++++++--- 4 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 scripts/tests/Module/PSModule/helpers/Add-PSModulePath.ps1 diff --git a/scripts/tests/Module/PSModule/helpers/Add-PSModulePath.ps1 b/scripts/tests/Module/PSModule/helpers/Add-PSModulePath.ps1 new file mode 100644 index 00000000..f5abf042 --- /dev/null +++ b/scripts/tests/Module/PSModule/helpers/Add-PSModulePath.ps1 @@ -0,0 +1,29 @@ +function Add-PSModulePath { + <# + .SYNOPSIS + Adds a path to the PSModulePath environment variable. + + .DESCRIPTION + Adds a path to the PSModulePath environment variable. + For Linux and macOS, the path delimiter is ':' and for Windows it is ';'. + + .EXAMPLE + Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules' + + Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable. + #> + [CmdletBinding()] + param( + # Path to the folder where the module source code is located. + [Parameter(Mandatory)] + [string] $Path + ) + $PSModulePathSeparator = [System.IO.Path]::PathSeparator + + $env:PSModulePath += "$PSModulePathSeparator$Path" + + Write-Verbose 'PSModulePath:' + $env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object { + Write-Verbose " - [$_]" + } +} diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 index 65e653d6..e109f050 100644 --- a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -7,12 +7,11 @@ Imports a build PS module. .EXAMPLE - Import-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $ModuleName + Import-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $moduleName - Imports a module located at $ModuleFolderPath with the name $ModuleName. + Imports a module located at $ModuleFolderPath with the name $moduleName. #> [CmdletBinding()] - #Requires -Modules Utilities [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' @@ -24,14 +23,12 @@ ) $moduleName = Split-Path -Path $Path -Leaf - $manifestFileName = "$moduleName.psd1" - $manifestFilePath = Join-Path -Path $Path $manifestFileName - $manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose + $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" Write-Host " - Manifest file path: [$($manifestFile.FullName)]" - Remove-PSModule -Name $ModuleName - Resolve-PSModuleDependency -ManifestFilePath $manifestFile - Import-Module -Name $ModuleName -RequiredVersion '999.0.0' + Remove-PSModule -Name $moduleName + Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath + Import-Module -Name $moduleName -RequiredVersion '999.0.0' Write-Host ' - List loaded modules' $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false @@ -39,7 +36,7 @@ Write-Host ' - List commands' Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) - if ($ModuleName -notin $availableModules.Name) { + if ($moduleName -notin $availableModules.Name) { throw 'Module not found' } } diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index 749765e4..fe51e84c 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -3,7 +3,6 @@ .SYNOPSIS Removes and uninstalls a PowerShell module. - .EXAMPLE Remove-PSModule -ModuleName 'Utilities' diff --git a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 index 4a144233..4275080e 100644 --- a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 @@ -16,8 +16,6 @@ Should later be adapted to take 4 parameters sets: specific version ("requiredVersion" | "GUID"), latest version ModuleVersion, and latest version within a range MinimumVersion - MaximumVersion. #> - [Alias('Resolve-PSModuleDependencies')] - #Requires -Modules Retry [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' @@ -54,8 +52,22 @@ Write-Host " - [$($installParams.Name)] - Uninstalling module" Remove-PSModule -Name $installParams.Name Write-Host " - [$($installParams.Name)] - Installing module" - Retry -Count 5 -Delay 10 { - Install-Module @installParams -AllowClobber + $Count = 5 + $Delay = 10 + for ($i = 0; $i -lt $Count; $i++) { + try { + Install-Module @installParams + break + } catch { + Write-Warning 'The command:' + Write-Warning $Run.ToString() + Write-Warning "failed with error: $_" + if ($i -eq $Count - 1) { + throw + } + Write-Warning "Retrying in $Delay seconds..." + Start-Sleep -Seconds $Delay + } } $VerbosePreference = $VerbosePreferenceOriginal Write-Host " - [$($installParams.Name)] - Importing module" From 2abce080693cf65ba81fe9319ab3337b536f186e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 25 Feb 2025 23:36:18 +0100 Subject: [PATCH 081/172] Refactor: Update Import-PSModule.ps1 to improve manifest file path handling and add module listing --- scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 index e109f050..a86977ab 100644 --- a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -25,9 +25,14 @@ $moduleName = Split-Path -Path $Path -Leaf $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" - Write-Host " - Manifest file path: [$($manifestFile.FullName)]" + Write-Host " - Manifest file path: [$manifestFilePath]" Remove-PSModule -Name $moduleName Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath + + Write-Host ' - List installed modules' + Get-InstalledPSResource | Format-Table -AutoSize + + Write-Host " - Importing module [$moduleName] v999" Import-Module -Name $moduleName -RequiredVersion '999.0.0' Write-Host ' - List loaded modules' From 93d27c0951622b57b66d2bae26e7e6b9a4f6cd15 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:03:30 +0100 Subject: [PATCH 082/172] Refactor: Enhance error handling in Remove-PSModule.ps1 by adding -ErrorAction SilentlyContinue to Get-InstalledPSResource --- scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 index fe51e84c..84bdd05b 100644 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 @@ -33,7 +33,7 @@ Write-Host " - Removing command [$($command.Name)]" $command | Remove-Item -Force } - $installedModule = Get-InstalledPSResource | Where-Object { $_.Name -eq $Name } + $installedModule = Get-InstalledPSResource -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $Name } Write-Host " - Found [$($installedModule.Count)] installed modules to remove" foreach ($module in $installedModule) { Write-Host " - Uninstalling module [$($module.Name)]" From 131cdd3dae7a1b40559228e69b785345c0893f31 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:16:08 +0100 Subject: [PATCH 083/172] Refactor: Remove Add-PSModulePath and Remove-PSModule functions, streamline module import process --- .../tests/Module/PSModule/PSModule.Tests.ps1 | 2 - .../PSModule/helpers/Add-PSModulePath.ps1 | 29 ------------ .../PSModule/helpers/Import-PSModule.ps1 | 3 +- .../PSModule/helpers/Remove-PSModule.ps1 | 44 ------------------- .../helpers/Resolve-PSModuleDependency.ps1 | 2 - 5 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 scripts/tests/Module/PSModule/helpers/Add-PSModulePath.ps1 delete mode 100644 scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index 83812ea0..7381d398 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -17,8 +17,6 @@ BeforeAll { $moduleName = Split-Path -Path $Path -Leaf Write-Verbose "[$moduleName] - Processing" -Verbose - $outputFolder = Split-Path -Path $Path -Parent - Add-PSModulePath -Path $outputFolder Import-PSModule -Path $Path } } diff --git a/scripts/tests/Module/PSModule/helpers/Add-PSModulePath.ps1 b/scripts/tests/Module/PSModule/helpers/Add-PSModulePath.ps1 deleted file mode 100644 index f5abf042..00000000 --- a/scripts/tests/Module/PSModule/helpers/Add-PSModulePath.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -function Add-PSModulePath { - <# - .SYNOPSIS - Adds a path to the PSModulePath environment variable. - - .DESCRIPTION - Adds a path to the PSModulePath environment variable. - For Linux and macOS, the path delimiter is ':' and for Windows it is ';'. - - .EXAMPLE - Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules' - - Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable. - #> - [CmdletBinding()] - param( - # Path to the folder where the module source code is located. - [Parameter(Mandatory)] - [string] $Path - ) - $PSModulePathSeparator = [System.IO.Path]::PathSeparator - - $env:PSModulePath += "$PSModulePathSeparator$Path" - - Write-Verbose 'PSModulePath:' - $env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object { - Write-Verbose " - [$_]" - } -} diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 index a86977ab..0e176be9 100644 --- a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -26,14 +26,13 @@ $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" Write-Host " - Manifest file path: [$manifestFilePath]" - Remove-PSModule -Name $moduleName Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath Write-Host ' - List installed modules' Get-InstalledPSResource | Format-Table -AutoSize Write-Host " - Importing module [$moduleName] v999" - Import-Module -Name $moduleName -RequiredVersion '999.0.0' + Import-Module $Path Write-Host ' - List loaded modules' $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false diff --git a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 deleted file mode 100644 index 84bdd05b..00000000 --- a/scripts/tests/Module/PSModule/helpers/Remove-PSModule.ps1 +++ /dev/null @@ -1,44 +0,0 @@ -filter Remove-PSModule { - <# - .SYNOPSIS - Removes and uninstalls a PowerShell module. - - .EXAMPLE - Remove-PSModule -ModuleName 'Utilities' - - Removes a module 'Utilities' from the session then from the system. - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - [CmdletBinding(SupportsShouldProcess)] - param( - # Name of the module. - [Parameter(Mandatory, ValueFromPipeline)] - [string] $Name - ) - - if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { - Write-Host "[$Name] - Remove module" - $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } - Write-Host " - Found [$($importedModule.Count)] modules to remove" - foreach ($module in $importedModule) { - Write-Host " - Removing module [$($module.Name)]" - $module | Remove-Module -Force - } - $commands = Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } - Write-Host " - Found [$($commands.Count)] commands to remove" - foreach ($command in $commands) { - Write-Host " - Removing command [$($command.Name)]" - $command | Remove-Item -Force - } - $installedModule = Get-InstalledPSResource -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $Name } - Write-Host " - Found [$($installedModule.Count)] installed modules to remove" - foreach ($module in $installedModule) { - Write-Host " - Uninstalling module [$($module.Name)]" - $module | Uninstall-PSResource -SkipDependencyCheck - } - Get-Command -Module $Name | Format-Table -AutoSize - } -} diff --git a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 index 4275080e..5a1c52c9 100644 --- a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 @@ -49,8 +49,6 @@ $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Write-Host " - [$($installParams.Name)] - Uninstalling module" - Remove-PSModule -Name $installParams.Name Write-Host " - [$($installParams.Name)] - Installing module" $Count = 5 $Delay = 10 From 917cba8508701a8f7133b184f85d7b53e3233737 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:48:07 +0100 Subject: [PATCH 084/172] Refactor: Update Import-PSModule and Resolve-PSModuleDependency to enhance module installation and dependency resolution --- .../PSModule/helpers/Import-PSModule.ps1 | 3 +- .../helpers/Resolve-PSModuleDependency.ps1 | 108 +++++++++++++----- 2 files changed, 81 insertions(+), 30 deletions(-) diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 index 0e176be9..3d384cd5 100644 --- a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -38,9 +38,10 @@ $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize Write-Host ' - List commands' + $commands = Get-Command -Module $moduleName -ListImported Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) - if ($moduleName -notin $availableModules.Name) { + if ($moduleName -notin $commands.Source) { throw 'Module not found' } } diff --git a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 index 5a1c52c9..3dfe9640 100644 --- a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 @@ -1,15 +1,17 @@ function Resolve-PSModuleDependency { <# .SYNOPSIS - Resolve dependencies for a module based on the manifest file. + Resolves module dependencies from a manifest file using Install-PSResource. .DESCRIPTION - Resolve dependencies for a module based on the manifest file, following PSModuleInfo structure + Reads a module manifest (PSD1) and for each required module converts the old + Install-Module parameters (MinimumVersion, MaximumVersion, RequiredVersion) + into a single NuGet version range string for Install-PSResource's –Version parameter. + (Note: If RequiredVersion is set, that value takes precedence.) .EXAMPLE - Resolve-PSModuleDependency -Path 'C:\MyModule\MyModule.psd1' - - Installs all modules defined in the manifest file, following PSModuleInfo structure. + Resolve-PSModuleDependency -ManifestFilePath 'C:\MyModule\MyModule.psd1' + Installs all modules defined in the manifest file, following PSModuleInfo structure. .NOTES Should later be adapted to support both pre-reqs, and dependencies. @@ -27,53 +29,101 @@ [string] $ManifestFilePath ) - Write-Host 'Resolving dependencies' + # Helper: Convert legacy version parameters into a NuGet version range string. + function Convert-VersionSpec { + param( + [string]$MinimumVersion, + [string]$MaximumVersion, + [string]$RequiredVersion + ) + if ($RequiredVersion) { + # Use exact match in bracket notation. + return "[$RequiredVersion]" + } elseif ($MinimumVersion -and $MaximumVersion) { + # Both bounds provided; both are inclusive. + return "[$MinimumVersion,$MaximumVersion]" + } elseif ($MinimumVersion) { + # Only a minimum is provided. Use a minimum-inclusive range. + return "[$MinimumVersion, ]" + } elseif ($MaximumVersion) { + # Only a maximum is provided; lower bound open. + return "(, $MaximumVersion]" + } else { + return $null + } + } + Write-Host 'Resolving dependencies' $manifest = Import-PowerShellDataFile -Path $ManifestFilePath Write-Host " - Reading [$ManifestFilePath]" - Write-Host " - Found [$($manifest.RequiredModules.Count)] modules to install" + Write-Host " - Found [$($manifest.RequiredModules.Count)] module(s) to install" foreach ($requiredModule in $manifest.RequiredModules) { - $installParams = @{} + # Build parameters for Install-PSResource (new version spec). + $psResourceParams = @{ + TrustRepository = $true + } + # Build parameters for Import-Module (legacy version spec). + $importParams = @{ + Force = $true + Verbose = $false + } if ($requiredModule -is [string]) { - $installParams.Name = $requiredModule + $psResourceParams.Name = $requiredModule + $importParams.Name = $requiredModule } else { - $installParams.Name = $requiredModule.ModuleName - $installParams.MinimumVersion = $requiredModule.ModuleVersion - $installParams.RequiredVersion = $requiredModule.RequiredVersion - $installParams.MaximumVersion = $requiredModule.MaximumVersion + $psResourceParams.Name = $requiredModule.ModuleName + $importParams.Name = $requiredModule.ModuleName + + # Convert legacy version info for Install-PSResource. + $versionSpec = Convert-VersionSpec ` + -MinimumVersion $requiredModule.ModuleVersion ` + -MaximumVersion $requiredModule.MaximumVersion ` + -RequiredVersion $requiredModule.RequiredVersion + + if ($versionSpec) { + $psResourceParams.Version = $versionSpec + } + + # For Import-Module, keep the original version parameters. + if ($requiredModule.ModuleVersion) { + $importParams.MinimumVersion = $requiredModule.ModuleVersion + } + if ($requiredModule.RequiredVersion) { + $importParams.RequiredVersion = $requiredModule.RequiredVersion + } + if ($requiredModule.MaximumVersion) { + $importParams.MaximumVersion = $requiredModule.MaximumVersion + } } - $installParams.Force = $true - $installParams.Verbose = $false + Write-Host " - [$($psResourceParams.Name)] - Installing module with Install-PSResource using version spec: $($psResourceParams.Version)" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Write-Host " - [$($installParams.Name)] - Installing module" - $Count = 5 - $Delay = 10 - for ($i = 0; $i -lt $Count; $i++) { + $retryCount = 5 + $retryDelay = 10 + for ($i = 0; $i -lt $retryCount; $i++) { try { - Install-Module @installParams + Install-PSResource @psResourceParams break } catch { - Write-Warning 'The command:' - Write-Warning $Run.ToString() - Write-Warning "failed with error: $_" - if ($i -eq $Count - 1) { + Write-Warning "Installation of $($psResourceParams.Name) failed with error: $_" + if ($i -eq $retryCount - 1) { throw } - Write-Warning "Retrying in $Delay seconds..." - Start-Sleep -Seconds $Delay + Write-Warning "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay } } $VerbosePreference = $VerbosePreferenceOriginal - Write-Host " - [$($installParams.Name)] - Importing module" + + Write-Host " - [$($importParams.Name)] - Importing module with legacy version spec" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Import-Module @installParams + Import-Module @importParams $VerbosePreference = $VerbosePreferenceOriginal - Write-Host " - [$($installParams.Name)] - Done" + Write-Host " - [$($importParams.Name)] - Done" } Write-Host ' - Resolving dependencies - Done' } From c82e85b1645f4a70a0600800b37e374403e7af5e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:55:48 +0100 Subject: [PATCH 085/172] Refactor: Update PSModule.Tests to use Import-PSModule for improved module import testing --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index 7381d398..c10dab85 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -14,21 +14,13 @@ BeforeAll { Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { . $_.FullName } - - $moduleName = Split-Path -Path $Path -Leaf - Write-Verbose "[$moduleName] - Processing" -Verbose - Import-PSModule -Path $Path } } Describe 'PSModule - Module tests' { Context 'Module' { - It 'The module should be available' { - Get-Module -Name $moduleName -ListAvailable | Should -Not -BeNullOrEmpty - Write-Verbose (Get-Module -Name $moduleName -ListAvailable | Out-String) - } It 'The module should be importable' { - { Import-Module -Name $moduleName -RequiredVersion 999.0.0 -Force } | Should -Not -Throw + { Import-PSModule -Path $Path } | Should -Not -Throw } } From 461245d023398c940bc831b76301661865ba3afa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:58:21 +0100 Subject: [PATCH 086/172] Refactor: Update PSModule.Tests to use Import-Module for module import validation and enhance manifest file path handling --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index c10dab85..2fc14840 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -14,13 +14,20 @@ BeforeAll { Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { . $_.FullName } + + $moduleName = Split-Path -Path $Path -Leaf + Write-Verbose "[$moduleName] - Processing" -Verbose + $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" + + Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose + Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath } } Describe 'PSModule - Module tests' { Context 'Module' { It 'The module should be importable' { - { Import-PSModule -Path $Path } | Should -Not -Throw + { Import-Module -Path $Path } | Should -Not -Throw } } From ac7fb6b14ed281590df0a27420f5ee8210e9e8b6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:59:49 +0100 Subject: [PATCH 087/172] Refactor: Update PSModule.Tests to use Import-Module with -Name parameter for improved module import validation --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index 2fc14840..1bad47c8 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -27,7 +27,7 @@ BeforeAll { Describe 'PSModule - Module tests' { Context 'Module' { It 'The module should be importable' { - { Import-Module -Path $Path } | Should -Not -Throw + { Import-Module -Name $Path } | Should -Not -Throw } } From d5c2c74e0fbc6c72c0b440c37566c0a67fceb779 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 00:06:16 +0100 Subject: [PATCH 088/172] Refactor: Add TestResults configuration to Module.Configuration for enhanced test management --- scripts/tests/Module/Module.Configuration.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index 3b6e185e..ad423e3c 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,4 +1,7 @@ @{ + TestRestults = @{ + Enabled = $true + } CodeCoverage = @{ Enabled = $true OutputFormat = 'JaCoCo' From 3b3edc25eaba9108e6ec970fc9015126568c87b1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 00:06:46 +0100 Subject: [PATCH 089/172] Fix typo in TestResults configuration key in Module.Configuration --- scripts/tests/Module/Module.Configuration.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index ad423e3c..3f3e92a9 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,5 +1,5 @@ @{ - TestRestults = @{ + TestRestult = @{ Enabled = $true } CodeCoverage = @{ From 82392f57a47f780c32692813a76af86152342dea Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 00:21:50 +0100 Subject: [PATCH 090/172] Fix typo in TestResults configuration key in Module.Configuration --- scripts/tests/Module/Module.Configuration.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index 3f3e92a9..bb2acf92 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,5 +1,5 @@ @{ - TestRestult = @{ + TestRestult = @{ Enabled = $true } CodeCoverage = @{ From 48cb05f8867f96ad3de84d7ed980829508bdd69e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 09:32:37 +0100 Subject: [PATCH 091/172] Remove redundant environment initialization step from Action-Test workflow --- .github/workflows/Action-Test.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index f571b113..79a72205 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -26,9 +26,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Action-Test uses: ./ id: action-test @@ -48,9 +45,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Action-Test uses: ./ id: action-test @@ -70,9 +64,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Action-Test uses: ./ id: action-test From cef67fe1fa7a070655bed6dcbe0833c63a61914f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 09:35:23 +0100 Subject: [PATCH 092/172] Update Invoke-Pester action to use fixDefaultsForMerge for improved functionality --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index f1bdbbc9..a10a0b2e 100644 --- a/action.yml +++ b/action.yml @@ -51,6 +51,7 @@ runs: - name: Invoke-Pester uses: PSModule/Invoke-Pester@v3 + uses: PSModule/Invoke-Pester@fixDefaultsForMerge id: test env: LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} From d75b536a5cddee9964b9b7b4995a9745418883bd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 09:35:33 +0100 Subject: [PATCH 093/172] Update Invoke-Pester action to use fixDefaultsForMerge for improved functionality --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a10a0b2e..d60e1269 100644 --- a/action.yml +++ b/action.yml @@ -50,7 +50,7 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - uses: PSModule/Invoke-Pester@v3 + # uses: PSModule/Invoke-Pester@v3 uses: PSModule/Invoke-Pester@fixDefaultsForMerge id: test env: From d67d4cef6e66823ce988c165b7178da9f22b9661 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 09:55:13 +0100 Subject: [PATCH 094/172] Add newline at end of Action-Test workflow file for consistency --- .github/workflows/Action-Test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 79a72205..ba3cb958 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -71,3 +71,5 @@ jobs: Name: PSModuleTest Path: tests/srcWithManifestTestRepo Settings: SourceCode + + \ No newline at end of file From 7210d1c6ce3461ff9fa32166889ba4fd93dac350 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 10:17:11 +0100 Subject: [PATCH 095/172] Update Invoke-Pester action version and fix typo in Module.Configuration --- action.yml | 3 +-- scripts/tests/Module/Module.Configuration.ps1 | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index d60e1269..f1bdbbc9 100644 --- a/action.yml +++ b/action.yml @@ -50,8 +50,7 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - # uses: PSModule/Invoke-Pester@v3 - uses: PSModule/Invoke-Pester@fixDefaultsForMerge + uses: PSModule/Invoke-Pester@v3 id: test env: LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index bb2acf92..e21afb2e 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,5 +1,5 @@ @{ - TestRestult = @{ + TestResult = @{ Enabled = $true } CodeCoverage = @{ From bd2ce7b8a0df96b598c4741f1e6e786f19323e7f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 10:20:16 +0100 Subject: [PATCH 096/172] Update Invoke-Pester action to use fixDefaultsForMerge for improved functionality --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f1bdbbc9..d60e1269 100644 --- a/action.yml +++ b/action.yml @@ -50,7 +50,8 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - uses: PSModule/Invoke-Pester@v3 + # uses: PSModule/Invoke-Pester@v3 + uses: PSModule/Invoke-Pester@fixDefaultsForMerge id: test env: LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} From eff1b3c59c3b448dedd3abd421f353c6cd3e7af1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 27 Feb 2025 10:24:19 +0100 Subject: [PATCH 097/172] Remove unnecessary blank lines and add newline at end of Action-Test workflow file for consistency --- .github/workflows/Action-Test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index ba3cb958..79a72205 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -71,5 +71,3 @@ jobs: Name: PSModuleTest Path: tests/srcWithManifestTestRepo Settings: SourceCode - - \ No newline at end of file From 69218ed3f047c70e16c9c483856755aecf36b291 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 02:28:36 +0100 Subject: [PATCH 098/172] Rename environment variables for consistency in action.yml and main.ps1 --- action.yml | 6 +++--- scripts/main.ps1 | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index d60e1269..03502c1e 100644 --- a/action.yml +++ b/action.yml @@ -39,9 +39,9 @@ runs: uses: PSModule/Github-Script@v1 id: paths env: - GITHUB_ACTION_INPUT_TEST_PSMODULE_Name: ${{ inputs.Name }} - GITHUB_ACTION_INPUT_TEST_PSMODULE_Path: ${{ inputs.Path }} - GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings: ${{ inputs.Settings }} + PSMODULE_TEST_PSMODULE_INPUT_Name: ${{ inputs.Name }} + PSMODULE_TEST_PSMODULE_INPUT_Path: ${{ inputs.Path }} + PSMODULE_TEST_PSMODULE_INPUT_Settings: ${{ inputs.Settings }} with: Debug: ${{ inputs.Debug }} Prerelease: ${{ inputs.Prerelease }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 14e7f928..45389a7a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,18 +1,18 @@ # If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. -$moduleName = if ([string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name)) { +$moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME } else { - $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Name + $env:PSMODULE_TEST_PSMODULE_INPUT_Name } -$settings = $env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Settings +$settings = $env:PSMODULE_TEST_PSMODULE_INPUT_Settings $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path -$localTestPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/tests" | Select-Object -ExpandProperty Path +$localTestPath = Resolve-Path -Path "$env:PSMODULE_TEST_PSMODULE_INPUT_Path/tests" | Select-Object -ExpandProperty Path $codePath = switch ($settings) { 'Module' { - Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/outputs/module/$moduleName" | Select-Object -ExpandProperty Path + Resolve-Path -Path "$env:PSMODULE_TEST_PSMODULE_INPUT_Path/outputs/module/$moduleName" | Select-Object -ExpandProperty Path } 'SourceCode' { - Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_TEST_PSMODULE_Path/src" | Select-Object -ExpandProperty Path + Resolve-Path -Path "$env:PSMODULE_TEST_PSMODULE_INPUT_Path/src" | Select-Object -ExpandProperty Path } default { throw "Invalid test type: [$settings]" From a9ca5b82895518c4364d4169351ea766938cae9c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 02:28:42 +0100 Subject: [PATCH 099/172] Add Convert-VersionSpec function for NuGet version range conversion --- .../PSModule/helpers/Convert-VersionSpec.ps1 | 98 +++++++++++++++++++ .../helpers/Resolve-PSModuleDependency.ps1 | 24 ----- 2 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 scripts/tests/Module/PSModule/helpers/Convert-VersionSpec.ps1 diff --git a/scripts/tests/Module/PSModule/helpers/Convert-VersionSpec.ps1 b/scripts/tests/Module/PSModule/helpers/Convert-VersionSpec.ps1 new file mode 100644 index 00000000..14357a88 --- /dev/null +++ b/scripts/tests/Module/PSModule/helpers/Convert-VersionSpec.ps1 @@ -0,0 +1,98 @@ +function Convert-VersionSpec { + <# + .SYNOPSIS + Converts legacy version parameters into a NuGet version range string. + + .DESCRIPTION + This function takes minimum, maximum, or required version parameters + and constructs a NuGet-compatible version range string. + + - If `RequiredVersion` is specified, the output is an exact match range. + - If both `MinimumVersion` and `MaximumVersion` are provided, + an inclusive range is returned. + - If only `MinimumVersion` is provided, it returns a minimum-inclusive range. + - If only `MaximumVersion` is provided, it returns an upper-bound range. + - If no parameters are provided, `$null` is returned. + + .EXAMPLE + Convert-VersionSpec -MinimumVersion "1.0.0" -MaximumVersion "2.0.0" + + Output: + ```powershell + [1.0.0,2.0.0] + ``` + + Returns an inclusive version range from 1.0.0 to 2.0.0. + + .EXAMPLE + Convert-VersionSpec -RequiredVersion "1.5.0" + + Output: + ```powershell + [1.5.0] + ``` + + Returns an exact match for version 1.5.0. + + .EXAMPLE + Convert-VersionSpec -MinimumVersion "1.0.0" + + Output: + ```powershell + [1.0.0, ] + ``` + + Returns a minimum-inclusive version range starting at 1.0.0. + + .EXAMPLE + Convert-VersionSpec -MaximumVersion "2.0.0" + + Output: + ```powershell + (, 2.0.0] + ``` + + Returns an upper-bound range up to version 2.0.0. + + .OUTPUTS + string + + .NOTES + The NuGet version range string based on the provided parameters. + The returned string follows NuGet versioning syntax. + + .LINK + https://psmodule.io/Convert/Functions/Convert-VersionSpec + #> + [OutputType([string])] + [CmdletBinding()] + param( + # The minimum version for the range. If specified alone, the range is open-ended upwards. + [Parameter()] + [string] $MinimumVersion, + + # The maximum version for the range. If specified alone, the range is open-ended downwards. + [Parameter()] + [string] $MaximumVersion, + + # Specifies an exact required version. If set, an exact version range is returned. + [Parameter()] + [string] $RequiredVersion + ) + + if ($RequiredVersion) { + # Use exact match in bracket notation. + return "[$RequiredVersion]" + } elseif ($MinimumVersion -and $MaximumVersion) { + # Both bounds provided; both are inclusive. + return "[$MinimumVersion,$MaximumVersion]" + } elseif ($MinimumVersion) { + # Only a minimum is provided. Use a minimum-inclusive range. + return "[$MinimumVersion, ]" + } elseif ($MaximumVersion) { + # Only a maximum is provided; lower bound open. + return "(, $MaximumVersion]" + } else { + return $null + } +} diff --git a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 index 3dfe9640..edb3c29c 100644 --- a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 @@ -29,30 +29,6 @@ [string] $ManifestFilePath ) - # Helper: Convert legacy version parameters into a NuGet version range string. - function Convert-VersionSpec { - param( - [string]$MinimumVersion, - [string]$MaximumVersion, - [string]$RequiredVersion - ) - if ($RequiredVersion) { - # Use exact match in bracket notation. - return "[$RequiredVersion]" - } elseif ($MinimumVersion -and $MaximumVersion) { - # Both bounds provided; both are inclusive. - return "[$MinimumVersion,$MaximumVersion]" - } elseif ($MinimumVersion) { - # Only a minimum is provided. Use a minimum-inclusive range. - return "[$MinimumVersion, ]" - } elseif ($MaximumVersion) { - # Only a maximum is provided; lower bound open. - return "(, $MaximumVersion]" - } else { - return $null - } - } - Write-Host 'Resolving dependencies' $manifest = Import-PowerShellDataFile -Path $ManifestFilePath Write-Host " - Reading [$ManifestFilePath]" From 739246d31e54c8a2afb0d716f8007ace5cafa949 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 02:36:20 +0100 Subject: [PATCH 100/172] Add WorkingDirectory input to action.yml and update script paths accordingly --- action.yml | 9 ++++++++- scripts/main.ps1 | 19 +++++++++++-------- .../Module/PSModule/PSModule.Container.ps1 | 2 +- .../PSModule/PSModule.Container.ps1 | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index 03502c1e..aa612d08 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,6 @@ inputs: Path: description: The path to the repo. required: true - default: ${{ github.workspace }} Settings: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true @@ -31,6 +30,10 @@ inputs: description: Allow prerelease versions if available. required: false default: 'false' + WorkingDirectory: + description: The working directory to use for the action. + required: false + default: ${{ github.workspace }} runs: using: composite @@ -42,11 +45,13 @@ runs: PSMODULE_TEST_PSMODULE_INPUT_Name: ${{ inputs.Name }} PSMODULE_TEST_PSMODULE_INPUT_Path: ${{ inputs.Path }} PSMODULE_TEST_PSMODULE_INPUT_Settings: ${{ inputs.Settings }} + PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }} with: Debug: ${{ inputs.Debug }} Prerelease: ${{ inputs.Prerelease }} Verbose: ${{ inputs.Verbose }} Version: ${{ inputs.Version }} + WorkingDirectory: ${{ inputs.WorkingDirectory }} Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester @@ -55,11 +60,13 @@ runs: id: test env: LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} + WorkingDirectory: ${{ fromJson(steps.paths.outputs.result).WorkingDirectory }} with: Debug: ${{ inputs.Debug }} Prerelease: ${{ inputs.Prerelease }} Verbose: ${{ inputs.Verbose }} Version: ${{ inputs.Version }} + WorkingDirectory: ${{ inputs.WorkingDirectory }} TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 45389a7a..87c5ab08 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,28 +5,31 @@ $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name $env:PSMODULE_TEST_PSMODULE_INPUT_Name } $settings = $env:PSMODULE_TEST_PSMODULE_INPUT_Settings +$workingDirectory = $env:PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path -$localTestPath = Resolve-Path -Path "$env:PSMODULE_TEST_PSMODULE_INPUT_Path/tests" | Select-Object -ExpandProperty Path +$localTestPath = Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath "tests") | Select-Object -ExpandProperty Path $codePath = switch ($settings) { 'Module' { - Resolve-Path -Path "$env:PSMODULE_TEST_PSMODULE_INPUT_Path/outputs/module/$moduleName" | Select-Object -ExpandProperty Path + Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath "outputs/module/$moduleName") | Select-Object -ExpandProperty Path } 'SourceCode' { - Resolve-Path -Path "$env:PSMODULE_TEST_PSMODULE_INPUT_Path/src" | Select-Object -ExpandProperty Path + Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath "src") | Select-Object -ExpandProperty Path } default { throw "Invalid test type: [$settings]" } } [pscustomobject]@{ - ModuleName = $moduleName - Settings = $settings - CodePath = $codePath - LocalTestPath = $localTestPath - TestPath = $testPath + ModuleName = $moduleName + Settings = $settings + CodePath = $codePath + LocalTestPath = $localTestPath + TestPath = $testPath + WorkingDirectory = $workingDirectory } | Format-List Set-GitHubOutput -Name ModuleName -Value $moduleName Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name LocalTestPath -Value $localTestPath Set-GitHubOutput -Name TestPath -Value $testPath +Set-GitHubOutput -Name WorkingDirectory -Value $workingDirectory diff --git a/scripts/tests/Module/PSModule/PSModule.Container.ps1 b/scripts/tests/Module/PSModule/PSModule.Container.ps1 index 37c6bb30..31d42d3c 100644 --- a/scripts/tests/Module/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $env:GITHUB_ACTION_INPUT_Run_Path + Path = $env:PSMODULE_INVOKE_PESTER_INPUT_Run_Path Debug = $false Verbose = $false } diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 index 66c3d5a3..1f425cff 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Container.ps1 @@ -1,7 +1,7 @@ @{ Path = Get-ChildItem -Path $PSScriptRoot -Filter *.Tests.ps1 | Select-Object -ExpandProperty FullName Data = @{ - Path = $env:GITHUB_ACTION_INPUT_Run_Path + Path = $env:PSMODULE_INVOKE_PESTER_INPUT_Run_Path TestsPath = $env:LocalTestPath Debug = $false Verbose = $false From 166e4173babff40f45ecc21890b72d642dd56e3b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 02:43:17 +0100 Subject: [PATCH 101/172] Update Invoke-Pester action version and standardize string quotes in main.ps1 --- action.yml | 3 +-- scripts/main.ps1 | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index aa612d08..66463c07 100644 --- a/action.yml +++ b/action.yml @@ -55,8 +55,7 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - # uses: PSModule/Invoke-Pester@v3 - uses: PSModule/Invoke-Pester@fixDefaultsForMerge + uses: PSModule/Invoke-Pester@v3 id: test env: LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 87c5ab08..b2f7eedc 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -7,24 +7,24 @@ $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name $settings = $env:PSMODULE_TEST_PSMODULE_INPUT_Settings $workingDirectory = $env:PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path -$localTestPath = Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath "tests") | Select-Object -ExpandProperty Path +$localTestPath = Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath 'tests') | Select-Object -ExpandProperty Path $codePath = switch ($settings) { 'Module' { Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath "outputs/module/$moduleName") | Select-Object -ExpandProperty Path } 'SourceCode' { - Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath "src") | Select-Object -ExpandProperty Path + Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath 'src') | Select-Object -ExpandProperty Path } default { throw "Invalid test type: [$settings]" } } [pscustomobject]@{ - ModuleName = $moduleName - Settings = $settings - CodePath = $codePath - LocalTestPath = $localTestPath - TestPath = $testPath + ModuleName = $moduleName + Settings = $settings + CodePath = $codePath + LocalTestPath = $localTestPath + TestPath = $testPath WorkingDirectory = $workingDirectory } | Format-List From 60f08382b52409c11fa7ff7d72944e42a922ef00 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 02:53:41 +0100 Subject: [PATCH 102/172] Refactor Action-Test workflow to replace 'Path' with 'WorkingDirectory' input and update README for clarity --- .github/workflows/Action-Test.yml | 8 ++++---- README.md | 27 ++++++++++++--------------- action.yml | 6 +----- scripts/main.ps1 | 2 +- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 79a72205..36dee76b 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -1,6 +1,6 @@ name: Action-Test -run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" +run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' on: workflow_dispatch: @@ -31,7 +31,7 @@ jobs: id: action-test with: Name: PSModuleTest - Path: tests/outputTestRepo + WorkingDirectory: tests/outputTestRepo Settings: Module ActionTestSrcDefault: @@ -50,7 +50,7 @@ jobs: id: action-test with: Name: PSModuleTest - Path: tests/srcTestRepo + WorkingDirectory: tests/srcTestRepo Settings: SourceCode ActionTestsSrcWithManifest: @@ -69,5 +69,5 @@ jobs: id: action-test with: Name: PSModuleTest - Path: tests/srcWithManifestTestRepo + WorkingDirectory: tests/srcWithManifestTestRepo Settings: SourceCode diff --git a/README.md b/README.md index 049c6d63..45f1e36f 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,12 @@ Test-PSModule enables: The action runs the following the Pester test framework: - [PSScriptAnalyzer tests](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/readme?view=ps-modules) - [PSModule framework tests](#psmodule-tests) -- If `TestType` is set to `Module`: +- If `Settings` is set to `Module`: - The module manifest is tested using [Test-ModuleManifest](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/test-modulemanifest). - The module is imported. - Custom module tests from the `tests` directory in the module repository are run. - CodeCoverage is calculated. -- If `TestType` is set to `SourceCode`: +- If `Settings` is set to `SourceCode`: - The source code is tested with: - `PSScriptAnalyzer` for best practices, using custom settings. - `PSModule.SourceCode` for other PSModule standards. @@ -57,8 +57,8 @@ jobs: - name: Test-PSModule uses: PSModule/Test-PSModule@main with: - Path: src - TestType: SourceCode + Settings: SourceCode + WorkingDirectory: ${{ github.workspace }} ``` @@ -85,8 +85,8 @@ jobs: - name: Test-PSModule uses: PSModule/Test-PSModule@main with: - Path: outputs/module - TestType: Module + Settings: Module + WorkingDirectory: ${{ github.workspace }} ``` @@ -97,16 +97,13 @@ jobs: | Name | Description | Required | Default | | ---- | ----------- | -------- | ------- | -| `Path` | The path to the code to test. | `true` | | -| `TestType` | The type of tests to run. Can be either `Module` or `SourceCode`. | `true` | | +| `Settings` | The type of tests to run. Can be either `Module` or `SourceCode`. | `true` | | | `Name` | The name of the module to test. The name of the repository is used if not specified. | `false` | | -| `TestsPath` | The path to the tests to run. | `false` | `tests` | -| `StackTraceVerbosity` | Verbosity level of the stack trace. Allowed values: `None`, `FirstLine`, `Filtered`, `Full`. | `false` | `Filtered` | -| `Verbosity` | Verbosity level of the test output. Allowed values: `None`, `Normal`, `Detailed`, `Diagnostic`. | `false` | `Detailed` | -| `Debug` | Enable debug output. | `'false'` | `false` | -| `Verbose` | Enable verbose output. | `'false'` | `false` | -| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | | `false` | -| `Prerelease` | Allow prerelease versions if available. | `'false'` | `false` | +| `WorkingDirectory` | The working directory to use for the action. This is the root folder where tests and outputs are expected. | `false` | `${{ github.workspace }}` | +| `Debug` | Enable debug output. | `false` | `'false'` | +| `Verbose` | Enable verbose output. | `false` | `'false'` | +| `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | +| `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | ### Outputs diff --git a/action.yml b/action.yml index 66463c07..f17fcfc8 100644 --- a/action.yml +++ b/action.yml @@ -9,9 +9,6 @@ inputs: Name: description: The name of the module to test. The name of the repository is used if not specified. required: false - Path: - description: The path to the repo. - required: true Settings: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true @@ -31,7 +28,7 @@ inputs: required: false default: 'false' WorkingDirectory: - description: The working directory to use for the action. + description: The working directory to use for the action. This is the root folder where tests and outputs are expected. required: false default: ${{ github.workspace }} @@ -43,7 +40,6 @@ runs: id: paths env: PSMODULE_TEST_PSMODULE_INPUT_Name: ${{ inputs.Name }} - PSMODULE_TEST_PSMODULE_INPUT_Path: ${{ inputs.Path }} PSMODULE_TEST_PSMODULE_INPUT_Settings: ${{ inputs.Settings }} PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }} with: diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b2f7eedc..5a426462 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,4 +1,4 @@ -# If test type is module, the code we ought to test is in the path/name folder, otherwise it's in the path folder. +# If test type is module, the code we ought to test is in the WorkingDirectory/outputs/module/Name folder, otherwise it's in the WorkingDirectory/src folder. $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME } else { From 73994032ad946d5f066aa97204fd75b4b2380fca Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 02:58:14 +0100 Subject: [PATCH 103/172] Enhance path resolution in main.ps1 by adding existence checks for tests, module, and source directories, improving error handling and warnings. --- scripts/main.ps1 | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 5a426462..05013d1b 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -7,18 +7,41 @@ $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name $settings = $env:PSMODULE_TEST_PSMODULE_INPUT_Settings $workingDirectory = $env:PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path -$localTestPath = Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath 'tests') | Select-Object -ExpandProperty Path + +# Check if the tests directory exists before attempting to resolve its path +$localTestsDir = Join-Path -Path $workingDirectory -ChildPath 'tests' +$localTestPath = if (Test-Path -Path $localTestsDir) { + Resolve-Path -Path $localTestsDir | Select-Object -ExpandProperty Path +} else { + # Return the path even though it doesn't exist, to avoid errors + $localTestsDir +} + +# Check if expected code paths exist before resolving them $codePath = switch ($settings) { 'Module' { - Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath "outputs/module/$moduleName") | Select-Object -ExpandProperty Path + $moduleDir = Join-Path -Path $workingDirectory -ChildPath "outputs/module/$moduleName" + if (Test-Path -Path $moduleDir) { + Resolve-Path -Path $moduleDir | Select-Object -ExpandProperty Path + } else { + Write-Warning "Module directory does not exist: $moduleDir" + $moduleDir + } } 'SourceCode' { - Resolve-Path -Path (Join-Path -Path $workingDirectory -ChildPath 'src') | Select-Object -ExpandProperty Path + $srcDir = Join-Path -Path $workingDirectory -ChildPath 'src' + if (Test-Path -Path $srcDir) { + Resolve-Path -Path $srcDir | Select-Object -ExpandProperty Path + } else { + Write-Warning "Source directory does not exist: $srcDir" + $srcDir + } } default { throw "Invalid test type: [$settings]" } } + [pscustomobject]@{ ModuleName = $moduleName Settings = $settings From c5a31ce16bc704803bc04cbd4e994f6da522a303 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 17:08:51 +0100 Subject: [PATCH 104/172] Improve working directory resolution in main.ps1 by using Resolve-Path for better path handling --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 05013d1b..705c3fe8 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,7 +5,7 @@ $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name $env:PSMODULE_TEST_PSMODULE_INPUT_Name } $settings = $env:PSMODULE_TEST_PSMODULE_INPUT_Settings -$workingDirectory = $env:PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory +$workingDirectory = Resolve-Path -Path $env:PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory | Select-Object -ExpandProperty Path $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path # Check if the tests directory exists before attempting to resolve its path From 6e319948fa3ae71adbb5b73986fd1bdaac3f711f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 17:14:16 +0100 Subject: [PATCH 105/172] Refactor working directory resolution in main.ps1 to use current directory instead of input variable --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 705c3fe8..94de2e7d 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,7 +5,7 @@ $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name $env:PSMODULE_TEST_PSMODULE_INPUT_Name } $settings = $env:PSMODULE_TEST_PSMODULE_INPUT_Settings -$workingDirectory = Resolve-Path -Path $env:PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory | Select-Object -ExpandProperty Path +$workingDirectory = Resolve-Path -Path . | Select-Object -ExpandProperty Path $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path # Check if the tests directory exists before attempting to resolve its path From af4128b1157b82acef840917f8d3285728174261 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 17:27:14 +0100 Subject: [PATCH 106/172] Refactor path resolution in main.ps1 to simplify directory checks and improve clarity --- scripts/main.ps1 | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 94de2e7d..969080b0 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,37 +5,15 @@ $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name $env:PSMODULE_TEST_PSMODULE_INPUT_Name } $settings = $env:PSMODULE_TEST_PSMODULE_INPUT_Settings -$workingDirectory = Resolve-Path -Path . | Select-Object -ExpandProperty Path $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path -# Check if the tests directory exists before attempting to resolve its path -$localTestsDir = Join-Path -Path $workingDirectory -ChildPath 'tests' -$localTestPath = if (Test-Path -Path $localTestsDir) { - Resolve-Path -Path $localTestsDir | Select-Object -ExpandProperty Path -} else { - # Return the path even though it doesn't exist, to avoid errors - $localTestsDir -} - -# Check if expected code paths exist before resolving them +$localTestPath = Resolve-Path -Path 'tests' | Select-Object -ExpandProperty Path $codePath = switch ($settings) { 'Module' { - $moduleDir = Join-Path -Path $workingDirectory -ChildPath "outputs/module/$moduleName" - if (Test-Path -Path $moduleDir) { - Resolve-Path -Path $moduleDir | Select-Object -ExpandProperty Path - } else { - Write-Warning "Module directory does not exist: $moduleDir" - $moduleDir - } + Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path } 'SourceCode' { - $srcDir = Join-Path -Path $workingDirectory -ChildPath 'src' - if (Test-Path -Path $srcDir) { - Resolve-Path -Path $srcDir | Select-Object -ExpandProperty Path - } else { - Write-Warning "Source directory does not exist: $srcDir" - $srcDir - } + Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path } default { throw "Invalid test type: [$settings]" @@ -48,11 +26,9 @@ $codePath = switch ($settings) { CodePath = $codePath LocalTestPath = $localTestPath TestPath = $testPath - WorkingDirectory = $workingDirectory } | Format-List Set-GitHubOutput -Name ModuleName -Value $moduleName Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name LocalTestPath -Value $localTestPath Set-GitHubOutput -Name TestPath -Value $testPath -Set-GitHubOutput -Name WorkingDirectory -Value $workingDirectory From d90d9a82a1ec9de81367718214088db0c7456b3f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 17:31:42 +0100 Subject: [PATCH 107/172] Format output properties in main.ps1 for improved readability --- scripts/main.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 969080b0..ef58183a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -21,11 +21,11 @@ $codePath = switch ($settings) { } [pscustomobject]@{ - ModuleName = $moduleName - Settings = $settings - CodePath = $codePath - LocalTestPath = $localTestPath - TestPath = $testPath + ModuleName = $moduleName + Settings = $settings + CodePath = $codePath + LocalTestPath = $localTestPath + TestPath = $testPath } | Format-List Set-GitHubOutput -Name ModuleName -Value $moduleName From b1cac71c1914bdadd5c5a4dfa7351c67742844a5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 19:53:44 +0100 Subject: [PATCH 108/172] Improve readability of comments in main.ps1 for better clarity --- scripts/main.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index ef58183a..299aabdc 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,4 +1,5 @@ -# If test type is module, the code we ought to test is in the WorkingDirectory/outputs/module/Name folder, otherwise it's in the WorkingDirectory/src folder. +# If test type is module, the code we ought to test is in the WorkingDirectory/outputs/module/Name folder, +# otherwise it's in the WorkingDirectory/src folder. $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME } else { From 56cf681efb353bed2661c43e21551c0e249afb46 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 1 Mar 2025 10:08:38 +0100 Subject: [PATCH 109/172] Fix duplicate entry for WorkingDirectory in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 45f1e36f..a686adab 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,11 @@ jobs: | ---- | ----------- | -------- | ------- | | `Settings` | The type of tests to run. Can be either `Module` or `SourceCode`. | `true` | | | `Name` | The name of the module to test. The name of the repository is used if not specified. | `false` | | -| `WorkingDirectory` | The working directory to use for the action. This is the root folder where tests and outputs are expected. | `false` | `${{ github.workspace }}` | | `Debug` | Enable debug output. | `false` | `'false'` | | `Verbose` | Enable verbose output. | `false` | `'false'` | | `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | | `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | +| `WorkingDirectory` | The working directory to use for the action. This is the root folder where tests and outputs are expected. | `false` | `${{ github.workspace }}` | ### Outputs From 88c4d357fd99b9cfd300e3db2f5e06b89d327707 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 11:22:51 +0100 Subject: [PATCH 110/172] Format output in main.ps1 to string and comment out unused test contexts in PSModule.Tests.ps1 --- scripts/main.ps1 | 2 +- .../tests/SourceCode/PSModule/PSModule.Tests.ps1 | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 299aabdc..7ebe37c4 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -27,7 +27,7 @@ $codePath = switch ($settings) { CodePath = $codePath LocalTestPath = $localTestPath TestPath = $testPath -} | Format-List +} | Format-List | Out-String Set-GitHubOutput -Name ModuleName -Value $moduleName Set-GitHubOutput -Name CodePath -Value $codePath diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index 05d6ad67..95e0100d 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -210,8 +210,8 @@ Describe 'PSModule - SourceCode tests' { } } - Context 'classes' { - } + # Context 'classes' { + # } Context 'functions' { Context 'Generic' { @@ -381,14 +381,9 @@ Describe 'PSModule - SourceCode tests' { Should -BeNullOrEmpty -Because 'a test should exist for each of the functions in the module' } } - Context 'private functions' {} - } - - Context 'variables' { + # Context 'private functions' {} } - Context 'Module manifest' { - # It 'Module Manifest exists (maifest.psd1 or modulename.psd1)' {} - # It 'Module Manifest is valid' {} - } + # Context 'variables' { + # } } From 4bc0e67a10846a2a81772eccd9ca19ab235607ea Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 12:33:00 +0100 Subject: [PATCH 111/172] Refactor output formatting in Import-PSModule.ps1 for improved readability --- scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 index 3d384cd5..76224cd2 100644 --- a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 +++ b/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 @@ -29,17 +29,17 @@ Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath Write-Host ' - List installed modules' - Get-InstalledPSResource | Format-Table -AutoSize + Get-InstalledPSResource | Format-Table -AutoSize | Out-String Write-Host " - Importing module [$moduleName] v999" Import-Module $Path Write-Host ' - List loaded modules' $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false - $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize + $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize | Out-String Write-Host ' - List commands' $commands = Get-Command -Module $moduleName -ListImported - Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) + Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String if ($moduleName -notin $commands.Source) { throw 'Module not found' From 2169406db6d2553ccf23c3a2634ea5a21be43d61 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 13:50:18 +0100 Subject: [PATCH 112/172] Update action.yml to switch Invoke-Pester version for testing stability --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f17fcfc8..ca6ea0d2 100644 --- a/action.yml +++ b/action.yml @@ -51,7 +51,8 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - uses: PSModule/Invoke-Pester@v3 + # uses: PSModule/Invoke-Pester@v3 + uses: PSModule/Invoke-Pester@fix id: test env: LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} From d38b0909fe7fcd60905838eacf49401d13ffa878 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 14:20:41 +0100 Subject: [PATCH 113/172] Add a blank line for improved readability in Action-Test.yml --- .github/workflows/Action-Test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 36dee76b..880a6f28 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -14,6 +14,7 @@ concurrency: permissions: {} + jobs: ActionTestOutputs: name: Action-Test [outputs] - [${{ matrix.os }}] From 73b3a9fbbe532813b27fec9f856326b3be86dcaa Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 17:51:50 +0100 Subject: [PATCH 114/172] Add a blank line to README.md for improved readability --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a686adab..9783edd7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Test-PSModule + Test PowerShell modules with Pester and PSScriptAnalyzer. This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. From 58cb45bbc042a712392cd1ae7de6fb0f02b10933 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 18:27:55 +0100 Subject: [PATCH 115/172] Remove unnecessary blank lines in Action-Test.yml and README.md for improved clarity --- .github/workflows/Action-Test.yml | 1 - README.md | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 880a6f28..36dee76b 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -14,7 +14,6 @@ concurrency: permissions: {} - jobs: ActionTestOutputs: name: Action-Test [outputs] - [${{ matrix.os }}] diff --git a/README.md b/README.md index 9783edd7..a686adab 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Test-PSModule - Test PowerShell modules with Pester and PSScriptAnalyzer. This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. From 6716dd40579ca78b201290a32e15504b5135ab33 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 18:30:52 +0100 Subject: [PATCH 116/172] Update action.yml to revert Invoke-Pester version for consistency in testing --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index ca6ea0d2..f17fcfc8 100644 --- a/action.yml +++ b/action.yml @@ -51,8 +51,7 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - # uses: PSModule/Invoke-Pester@v3 - uses: PSModule/Invoke-Pester@fix + uses: PSModule/Invoke-Pester@v3 id: test env: LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} From f2047a1d9821ff28cbf370df93ad57a5122dc263 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 18:39:12 +0100 Subject: [PATCH 117/172] Add Output_Verbosity parameter to action.yml for detailed output --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index f17fcfc8..c7f98761 100644 --- a/action.yml +++ b/action.yml @@ -63,5 +63,6 @@ runs: Version: ${{ inputs.Version }} WorkingDirectory: ${{ inputs.WorkingDirectory }} TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} + Output_Verbosity: Detailed Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} From e1485552bf5ce77742d0c2d2971135223aee2b51 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 18:39:57 +0100 Subject: [PATCH 118/172] Remove Output_Verbosity parameter from action.yml for streamlined configuration --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index c7f98761..f17fcfc8 100644 --- a/action.yml +++ b/action.yml @@ -63,6 +63,5 @@ runs: Version: ${{ inputs.Version }} WorkingDirectory: ${{ inputs.WorkingDirectory }} TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} - Output_Verbosity: Detailed Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} From 1b38fab6c6b1235ff9a344de4ac8fdb5dbb94c26 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 21:55:52 +0100 Subject: [PATCH 119/172] Add a blank line to README.md for improved readability --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a686adab..9783edd7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Test-PSModule + Test PowerShell modules with Pester and PSScriptAnalyzer. This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. From ba3bd906d447c37df6b660a74c6a83f9938740c2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 3 Mar 2025 22:11:26 +0100 Subject: [PATCH 120/172] Remove unnecessary blank line from README.md for improved clarity --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9783edd7..a686adab 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Test-PSModule - Test PowerShell modules with Pester and PSScriptAnalyzer. This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. From 4ca6221e1ae08b6c1729385f205d831be7bd0be6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:03:44 +0100 Subject: [PATCH 121/172] Add local repository registration and module installation for 'Module' test type --- scripts/main.ps1 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 7ebe37c4..b4382c68 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -9,12 +9,21 @@ $settings = $env:PSMODULE_TEST_PSMODULE_INPUT_Settings $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object -ExpandProperty Path $localTestPath = Resolve-Path -Path 'tests' | Select-Object -ExpandProperty Path -$codePath = switch ($settings) { +switch ($settings) { 'Module' { - Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path + $codePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path + $localRepo = @{ + Name = 'Local' + Uri = New-Item -Path $PSScriptRoot -Name '.localpsmodulerepo' -ItemType Directory -PassThru + Trusted = $true + Priority = 1 + } + Register-PSResourceRepository @localRepo + Publish-PSResource -Path $codePath -Repository Local + Install-PSResource -Name $moduleName } 'SourceCode' { - Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path + $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path } default { throw "Invalid test type: [$settings]" From dcbe3ecb760228cc268b89be5c670883592e8c56 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:06:49 +0100 Subject: [PATCH 122/172] Remove unnecessary parameter from local repository creation in main.ps1 --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b4382c68..c2c77af0 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -14,7 +14,7 @@ switch ($settings) { $codePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path $localRepo = @{ Name = 'Local' - Uri = New-Item -Path $PSScriptRoot -Name '.localpsmodulerepo' -ItemType Directory -PassThru + Uri = New-Item -Path $PSScriptRoot -Name '.localpsmodulerepo' -ItemType Directory Trusted = $true Priority = 1 } From a97f93d34b8e216d4f30a1df1cad71d5ab68d0ac Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:08:41 +0100 Subject: [PATCH 123/172] Update priority for local repository and specify repository in Install-PSResource command --- scripts/main.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c2c77af0..ee982163 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -16,11 +16,11 @@ switch ($settings) { Name = 'Local' Uri = New-Item -Path $PSScriptRoot -Name '.localpsmodulerepo' -ItemType Directory Trusted = $true - Priority = 1 + Priority = 100 } Register-PSResourceRepository @localRepo Publish-PSResource -Path $codePath -Repository Local - Install-PSResource -Name $moduleName + Install-PSResource -Name $moduleName -Repository Local } 'SourceCode' { $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path From d7085ea7894664673d8a1bfbf492322658216c45 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:12:20 +0100 Subject: [PATCH 124/172] Update PSSemVer module version to 1.1.5 in PSModuleTest.psd1 --- .../outputs/module/PSModuleTest/PSModuleTest.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psd1 b/tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psd1 index ebe988d3..b0fdcc2f 100644 --- a/tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psd1 +++ b/tests/outputTestRepo/outputs/module/PSModuleTest/PSModuleTest.psd1 @@ -14,7 +14,7 @@ ProcessorArchitecture = 'None' RequiredModules = @( @{ - ModuleVersion = '1.0' + ModuleVersion = '1.1.5' ModuleName = 'PSSemVer' } 'Utilities' From f85d62ed78e68e540f651490517299b800bd1e2d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:18:18 +0100 Subject: [PATCH 125/172] Refactor module test scripts to improve helper path resolution and add new helper functions for module import and version specification --- .../PSModule => }/helpers/Convert-VersionSpec.ps1 | 0 .../Module/PSModule => }/helpers/Import-PSModule.ps1 | 0 .../helpers/Resolve-PSModuleDependency.ps1 | 0 scripts/main.ps1 | 11 ++++++++++- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 2 +- 5 files changed, 11 insertions(+), 2 deletions(-) rename scripts/{tests/Module/PSModule => }/helpers/Convert-VersionSpec.ps1 (100%) rename scripts/{tests/Module/PSModule => }/helpers/Import-PSModule.ps1 (100%) rename scripts/{tests/Module/PSModule => }/helpers/Resolve-PSModuleDependency.ps1 (100%) diff --git a/scripts/tests/Module/PSModule/helpers/Convert-VersionSpec.ps1 b/scripts/helpers/Convert-VersionSpec.ps1 similarity index 100% rename from scripts/tests/Module/PSModule/helpers/Convert-VersionSpec.ps1 rename to scripts/helpers/Convert-VersionSpec.ps1 diff --git a/scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 similarity index 100% rename from scripts/tests/Module/PSModule/helpers/Import-PSModule.ps1 rename to scripts/helpers/Import-PSModule.ps1 diff --git a/scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 similarity index 100% rename from scripts/tests/Module/PSModule/helpers/Resolve-PSModuleDependency.ps1 rename to scripts/helpers/Resolve-PSModuleDependency.ps1 diff --git a/scripts/main.ps1 b/scripts/main.ps1 index ee982163..fc3c0714 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,5 +1,11 @@ -# If test type is module, the code we ought to test is in the WorkingDirectory/outputs/module/Name folder, +$helperPath = "$PSScriptRoot/../../../helpers" +Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { + . $_.FullName +} + +# If test type is module, the code we ought to test is in the WorkingDirectory/outputs/module/Name folder, # otherwise it's in the WorkingDirectory/src folder. + $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME } else { @@ -19,6 +25,9 @@ switch ($settings) { Priority = 100 } Register-PSResourceRepository @localRepo + $manifestFilePath = Join-Path -Path $codePath "$moduleName.psd1" + Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose + Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath Publish-PSResource -Path $codePath -Repository Local Install-PSResource -Name $moduleName -Repository Local } diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index 1bad47c8..31c8888b 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -10,7 +10,7 @@ Param( BeforeAll { LogGroup "Load module from path [$Path]" { - $helperPath = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') + $helperPath = "$PSScriptRoot/../../../helpers" Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { . $_.FullName } From 0600c01f6d61a584ddce6239414a9d74a5b592ed Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:20:29 +0100 Subject: [PATCH 126/172] Fix helper path resolution in main.ps1 to correctly reference the helpers directory --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index fc3c0714..e040d631 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,4 +1,4 @@ -$helperPath = "$PSScriptRoot/../../../helpers" +$helperPath = "$PSScriptRoot/helpers" Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { . $_.FullName } From 4a46826b6fff54cbc73bf703022ea7a5a0292e1c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:23:49 +0100 Subject: [PATCH 127/172] Add repository specification for Install-PSResource in Resolve-PSModuleDependency.ps1 --- scripts/helpers/Resolve-PSModuleDependency.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index edb3c29c..5b989417 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -37,6 +37,7 @@ foreach ($requiredModule in $manifest.RequiredModules) { # Build parameters for Install-PSResource (new version spec). $psResourceParams = @{ + Repository = 'PSGallery' TrustRepository = $true } # Build parameters for Import-Module (legacy version spec). From addd28f68e4577c166b295cfd577d75014665aae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:26:51 +0100 Subject: [PATCH 128/172] Add output formatting for PSResourceRepository in main.ps1 --- scripts/main.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index e040d631..ff21ab47 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -25,6 +25,7 @@ switch ($settings) { Priority = 100 } Register-PSResourceRepository @localRepo + Get-PSResourceRepository | Format-List | Out-String $manifestFilePath = Join-Path -Path $codePath "$moduleName.psd1" Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath From 245e547c2b02f7460e803fbf7e0c3d5f816cc4cd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:33:37 +0100 Subject: [PATCH 129/172] Refactor module installation process in main.ps1 to use PSModulePath for directory management --- scripts/main.ps1 | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index ff21ab47..9b6860c1 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -18,19 +18,12 @@ $localTestPath = Resolve-Path -Path 'tests' | Select-Object -ExpandProperty Path switch ($settings) { 'Module' { $codePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path - $localRepo = @{ - Name = 'Local' - Uri = New-Item -Path $PSScriptRoot -Name '.localpsmodulerepo' -ItemType Directory - Trusted = $true - Priority = 100 - } - Register-PSResourceRepository @localRepo - Get-PSResourceRepository | Format-List | Out-String $manifestFilePath = Join-Path -Path $codePath "$moduleName.psd1" Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath - Publish-PSResource -Path $codePath -Repository Local - Install-PSResource -Name $moduleName -Repository Local + $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 + New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Name "" -Force + Copy-Item -Path $codePath -Destination "$PSModulePath/$moduleName/999.0.0" -Recurse -Force } 'SourceCode' { $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path From 2aeb7a5cc545e80acd316495287e55e869823ef4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:35:36 +0100 Subject: [PATCH 130/172] Remove redundant loading of helper scripts in PSModule.Tests.ps1 --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index 31c8888b..ffce7231 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -8,22 +8,6 @@ Param( [string] $Path ) -BeforeAll { - LogGroup "Load module from path [$Path]" { - $helperPath = "$PSScriptRoot/../../../helpers" - Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { - . $_.FullName - } - - $moduleName = Split-Path -Path $Path -Leaf - Write-Verbose "[$moduleName] - Processing" -Verbose - $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" - - Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose - Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath - } -} - Describe 'PSModule - Module tests' { Context 'Module' { It 'The module should be importable' { From 337a731cbdf03b7fbeda1f0a1ccbf4957ed70f2e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:39:02 +0100 Subject: [PATCH 131/172] Refactor module installation logic in main.ps1 to store the installation path in a variable --- scripts/main.ps1 | 4 ++-- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 9b6860c1..8a041579 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -22,8 +22,8 @@ switch ($settings) { Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 - New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Name "" -Force - Copy-Item -Path $codePath -Destination "$PSModulePath/$moduleName/999.0.0" -Recurse -Force + $moduleInstallPath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force + Copy-Item -Path $codePath -Destination $moduleInstallPath -Recurse -Force } 'SourceCode' { $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index ffce7231..af160629 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -11,12 +11,16 @@ Param( Describe 'PSModule - Module tests' { Context 'Module' { It 'The module should be importable' { - { Import-Module -Name $Path } | Should -Not -Throw + { + $moduleName = Split-Path -Path $Path -Leaf + Import-Module -Name $moduleName + } | Should -Not -Throw } } Context 'Module Manifest' { BeforeAll { + $moduleName = Split-Path -Path $Path -Leaf $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" Write-Verbose "Module Manifest Path: [$moduleManifestPath]" } From cf4a9212f38a70d0a5ee5058fd25e2647ec7088e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:49:29 +0100 Subject: [PATCH 132/172] Add output of installed module files in main.ps1 after installation --- scripts/main.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 8a041579..1bd20619 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -24,6 +24,7 @@ switch ($settings) { $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 $moduleInstallPath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force Copy-Item -Path $codePath -Destination $moduleInstallPath -Recurse -Force + Get-ChildItem -Path $moduleInstallPath -Recurse | Select-Object FullName | Out-String } 'SourceCode' { $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path From 4b2f08afc2075348f95cb01b9b101bf041f2b9a1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 12:53:53 +0100 Subject: [PATCH 133/172] Import module after installation and update output path in main.ps1 --- scripts/main.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 1bd20619..c2e21e4f 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -25,6 +25,7 @@ switch ($settings) { $moduleInstallPath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force Copy-Item -Path $codePath -Destination $moduleInstallPath -Recurse -Force Get-ChildItem -Path $moduleInstallPath -Recurse | Select-Object FullName | Out-String + Import-Module -Name $moduleName -Verbose } 'SourceCode' { $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path @@ -37,12 +38,12 @@ switch ($settings) { [pscustomobject]@{ ModuleName = $moduleName Settings = $settings - CodePath = $codePath + CodePath = $moduleInstallPath LocalTestPath = $localTestPath TestPath = $testPath } | Format-List | Out-String Set-GitHubOutput -Name ModuleName -Value $moduleName -Set-GitHubOutput -Name CodePath -Value $codePath +Set-GitHubOutput -Name CodePath -Value $moduleInstallPath Set-GitHubOutput -Name LocalTestPath -Value $localTestPath Set-GitHubOutput -Name TestPath -Value $testPath From 22526b5c92f891f839ea2aad34ae18d3d37aec70 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 15:25:55 +0100 Subject: [PATCH 134/172] Refactor module path handling in main.ps1 to improve clarity and consistency --- scripts/main.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c2e21e4f..ecc8fa3c 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -17,14 +17,14 @@ $testPath = Resolve-Path -Path "$PSScriptRoot/tests/$settings" | Select-Object - $localTestPath = Resolve-Path -Path 'tests' | Select-Object -ExpandProperty Path switch ($settings) { 'Module' { - $codePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path - $manifestFilePath = Join-Path -Path $codePath "$moduleName.psd1" + $modulePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path + $manifestFilePath = Join-Path -Path $modulePath "$moduleName.psd1" Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 - $moduleInstallPath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force - Copy-Item -Path $codePath -Destination $moduleInstallPath -Recurse -Force - Get-ChildItem -Path $moduleInstallPath -Recurse | Select-Object FullName | Out-String + $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force + Copy-Item -Path $codePath -Destination $codePath -Recurse -Force + Get-ChildItem -Path $codePath -Recurse | Select-Object FullName | Out-String Import-Module -Name $moduleName -Verbose } 'SourceCode' { @@ -38,12 +38,12 @@ switch ($settings) { [pscustomobject]@{ ModuleName = $moduleName Settings = $settings - CodePath = $moduleInstallPath + CodePath = $codePath LocalTestPath = $localTestPath TestPath = $testPath } | Format-List | Out-String Set-GitHubOutput -Name ModuleName -Value $moduleName -Set-GitHubOutput -Name CodePath -Value $moduleInstallPath +Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name LocalTestPath -Value $localTestPath Set-GitHubOutput -Name TestPath -Value $testPath From 5a9ac0bab82c8364f132126674dc70138ccfd19e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 15:28:53 +0100 Subject: [PATCH 135/172] Fix module copy path in main.ps1 to ensure correct installation of module files --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index ecc8fa3c..4d57f62f 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -23,7 +23,7 @@ switch ($settings) { Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force - Copy-Item -Path $codePath -Destination $codePath -Recurse -Force + Copy-Item -Path $modulePath -Destination $codePath -Recurse -Force Get-ChildItem -Path $codePath -Recurse | Select-Object FullName | Out-String Import-Module -Name $moduleName -Verbose } From b613f4563e49b9bae8a46c512f41860d0d2b8129 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 15:31:18 +0100 Subject: [PATCH 136/172] Add validation for module manifest file in main.ps1 --- scripts/main.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 4d57f62f..2fab518a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -19,6 +19,7 @@ switch ($settings) { 'Module' { $modulePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path $manifestFilePath = Join-Path -Path $modulePath "$moduleName.psd1" + Test-ModuleManifest -Path $manifestFilePath -Verbose Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 From e0a502ba8b4205b9127965bc4a865634524658ea Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 15:33:21 +0100 Subject: [PATCH 137/172] Reorder module manifest validation in main.ps1 for improved execution flow --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 2fab518a..177754a9 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -19,9 +19,9 @@ switch ($settings) { 'Module' { $modulePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path $manifestFilePath = Join-Path -Path $modulePath "$moduleName.psd1" - Test-ModuleManifest -Path $manifestFilePath -Verbose Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath + Test-ModuleManifest -Path $manifestFilePath -Verbose $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force Copy-Item -Path $modulePath -Destination $codePath -Recurse -Force From b7ce99a13bc7e4d1881fe54ccbe6b43895951b03 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 15:38:37 +0100 Subject: [PATCH 138/172] Add output of available modules after installation in main.ps1 --- scripts/main.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 177754a9..8172b61b 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -26,6 +26,9 @@ switch ($settings) { $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force Copy-Item -Path $modulePath -Destination $codePath -Recurse -Force Get-ChildItem -Path $codePath -Recurse | Select-Object FullName | Out-String + + Get-Module -ListAvailable | Format-Table -AutoSize | Out-String + Import-Module -Name $moduleName -Verbose } 'SourceCode' { From bb2d9b13e77484fa4ed52dc0634a5dcfd1cddec6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 15:46:12 +0100 Subject: [PATCH 139/172] Fix module copy command to include all files in the source path --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 8172b61b..3670282e 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -24,7 +24,7 @@ switch ($settings) { Test-ModuleManifest -Path $manifestFilePath -Verbose $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force - Copy-Item -Path $modulePath -Destination $codePath -Recurse -Force + Copy-Item -Path "$modulePath/*" -Destination $codePath -Recurse -Force Get-ChildItem -Path $codePath -Recurse | Select-Object FullName | Out-String Get-Module -ListAvailable | Format-Table -AutoSize | Out-String From 3545e31ae9229cb9be7949eb2212ebfd96f3bf07 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 15:49:43 +0100 Subject: [PATCH 140/172] Fix code path assignment to ensure correct directory path retrieval in module installation --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 3670282e..33bcae86 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -23,7 +23,7 @@ switch ($settings) { Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath Test-ModuleManifest -Path $manifestFilePath -Verbose $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 - $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force + $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force | Select-Object -ExpandProperty FullName Copy-Item -Path "$modulePath/*" -Destination $codePath -Recurse -Force Get-ChildItem -Path $codePath -Recurse | Select-Object FullName | Out-String From 3587cbcfa4fadc094cc22082451b2a9da1a398de Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 15:54:04 +0100 Subject: [PATCH 141/172] Refactor module import process in main.ps1 for improved logging and clarity --- scripts/main.ps1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 33bcae86..b9bc1475 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -21,15 +21,12 @@ switch ($settings) { $manifestFilePath = Join-Path -Path $modulePath "$moduleName.psd1" Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath - Test-ModuleManifest -Path $manifestFilePath -Verbose $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force | Select-Object -ExpandProperty FullName Copy-Item -Path "$modulePath/*" -Destination $codePath -Recurse -Force - Get-ChildItem -Path $codePath -Recurse | Select-Object FullName | Out-String - - Get-Module -ListAvailable | Format-Table -AutoSize | Out-String - - Import-Module -Name $moduleName -Verbose + LogGroup 'Importing module' { + Import-Module -Name $moduleName -Verbose + } } 'SourceCode' { $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path From 45990fa8171661e6dba608fb5256a6736cca6aa9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 16:00:04 +0100 Subject: [PATCH 142/172] Refactor PSModule.Tests.ps1 to streamline module import and manifest path retrieval --- scripts/tests/Module/PSModule/PSModule.Tests.ps1 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 index af160629..1253ce7f 100644 --- a/scripts/tests/Module/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/Module/PSModule/PSModule.Tests.ps1 @@ -8,22 +8,20 @@ Param( [string] $Path ) +BeforeAll { + $moduleName = Split-Path -Path (Split-Path -Path $Path -Parent) -Leaf + $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" + Write-Verbose "Module Manifest Path: [$moduleManifestPath]" +} + Describe 'PSModule - Module tests' { Context 'Module' { It 'The module should be importable' { - { - $moduleName = Split-Path -Path $Path -Leaf - Import-Module -Name $moduleName - } | Should -Not -Throw + { Import-Module -Name $moduleName } | Should -Not -Throw } } Context 'Module Manifest' { - BeforeAll { - $moduleName = Split-Path -Path $Path -Leaf - $moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1" - Write-Verbose "Module Manifest Path: [$moduleManifestPath]" - } It 'Module Manifest exists' { $result = Test-Path -Path $moduleManifestPath $result | Should -Be $true From 5b296fe239df1343d446341aa04d4cbb64130dc9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 20:08:37 +0100 Subject: [PATCH 143/172] Add PSModuleHelpers installation step and remove deprecated helper scripts --- action.yml | 3 + scripts/helpers/Convert-VersionSpec.ps1 | 98 ---------------- scripts/helpers/Import-PSModule.ps1 | 47 -------- .../helpers/Resolve-PSModuleDependency.ps1 | 106 ------------------ scripts/main.ps1 | 17 +-- 5 files changed, 5 insertions(+), 266 deletions(-) delete mode 100644 scripts/helpers/Convert-VersionSpec.ps1 delete mode 100644 scripts/helpers/Import-PSModule.ps1 delete mode 100644 scripts/helpers/Resolve-PSModuleDependency.ps1 diff --git a/action.yml b/action.yml index f17fcfc8..9dabe922 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,9 @@ inputs: runs: using: composite steps: + - name: Install-PSModuleHelpers + uses: PSModule/Install-PSModuleHelpers@main + - name: Get test paths uses: PSModule/Github-Script@v1 id: paths diff --git a/scripts/helpers/Convert-VersionSpec.ps1 b/scripts/helpers/Convert-VersionSpec.ps1 deleted file mode 100644 index 14357a88..00000000 --- a/scripts/helpers/Convert-VersionSpec.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -function Convert-VersionSpec { - <# - .SYNOPSIS - Converts legacy version parameters into a NuGet version range string. - - .DESCRIPTION - This function takes minimum, maximum, or required version parameters - and constructs a NuGet-compatible version range string. - - - If `RequiredVersion` is specified, the output is an exact match range. - - If both `MinimumVersion` and `MaximumVersion` are provided, - an inclusive range is returned. - - If only `MinimumVersion` is provided, it returns a minimum-inclusive range. - - If only `MaximumVersion` is provided, it returns an upper-bound range. - - If no parameters are provided, `$null` is returned. - - .EXAMPLE - Convert-VersionSpec -MinimumVersion "1.0.0" -MaximumVersion "2.0.0" - - Output: - ```powershell - [1.0.0,2.0.0] - ``` - - Returns an inclusive version range from 1.0.0 to 2.0.0. - - .EXAMPLE - Convert-VersionSpec -RequiredVersion "1.5.0" - - Output: - ```powershell - [1.5.0] - ``` - - Returns an exact match for version 1.5.0. - - .EXAMPLE - Convert-VersionSpec -MinimumVersion "1.0.0" - - Output: - ```powershell - [1.0.0, ] - ``` - - Returns a minimum-inclusive version range starting at 1.0.0. - - .EXAMPLE - Convert-VersionSpec -MaximumVersion "2.0.0" - - Output: - ```powershell - (, 2.0.0] - ``` - - Returns an upper-bound range up to version 2.0.0. - - .OUTPUTS - string - - .NOTES - The NuGet version range string based on the provided parameters. - The returned string follows NuGet versioning syntax. - - .LINK - https://psmodule.io/Convert/Functions/Convert-VersionSpec - #> - [OutputType([string])] - [CmdletBinding()] - param( - # The minimum version for the range. If specified alone, the range is open-ended upwards. - [Parameter()] - [string] $MinimumVersion, - - # The maximum version for the range. If specified alone, the range is open-ended downwards. - [Parameter()] - [string] $MaximumVersion, - - # Specifies an exact required version. If set, an exact version range is returned. - [Parameter()] - [string] $RequiredVersion - ) - - if ($RequiredVersion) { - # Use exact match in bracket notation. - return "[$RequiredVersion]" - } elseif ($MinimumVersion -and $MaximumVersion) { - # Both bounds provided; both are inclusive. - return "[$MinimumVersion,$MaximumVersion]" - } elseif ($MinimumVersion) { - # Only a minimum is provided. Use a minimum-inclusive range. - return "[$MinimumVersion, ]" - } elseif ($MaximumVersion) { - # Only a maximum is provided; lower bound open. - return "(, $MaximumVersion]" - } else { - return $null - } -} diff --git a/scripts/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 deleted file mode 100644 index 76224cd2..00000000 --- a/scripts/helpers/Import-PSModule.ps1 +++ /dev/null @@ -1,47 +0,0 @@ -function Import-PSModule { - <# - .SYNOPSIS - Imports a build PS module. - - .DESCRIPTION - Imports a build PS module. - - .EXAMPLE - Import-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $moduleName - - Imports a module located at $ModuleFolderPath with the name $moduleName. - #> - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - param( - # Path to the folder where the module source code is located. - [Parameter(Mandatory)] - [string] $Path - ) - - $moduleName = Split-Path -Path $Path -Leaf - $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" - - Write-Host " - Manifest file path: [$manifestFilePath]" - Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath - - Write-Host ' - List installed modules' - Get-InstalledPSResource | Format-Table -AutoSize | Out-String - - Write-Host " - Importing module [$moduleName] v999" - Import-Module $Path - - Write-Host ' - List loaded modules' - $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false - $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize | Out-String - Write-Host ' - List commands' - $commands = Get-Command -Module $moduleName -ListImported - Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String - - if ($moduleName -notin $commands.Source) { - throw 'Module not found' - } -} diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 deleted file mode 100644 index 5b989417..00000000 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ /dev/null @@ -1,106 +0,0 @@ -function Resolve-PSModuleDependency { - <# - .SYNOPSIS - Resolves module dependencies from a manifest file using Install-PSResource. - - .DESCRIPTION - Reads a module manifest (PSD1) and for each required module converts the old - Install-Module parameters (MinimumVersion, MaximumVersion, RequiredVersion) - into a single NuGet version range string for Install-PSResource's –Version parameter. - (Note: If RequiredVersion is set, that value takes precedence.) - - .EXAMPLE - Resolve-PSModuleDependency -ManifestFilePath 'C:\MyModule\MyModule.psd1' - Installs all modules defined in the manifest file, following PSModuleInfo structure. - - .NOTES - Should later be adapted to support both pre-reqs, and dependencies. - Should later be adapted to take 4 parameters sets: specific version ("requiredVersion" | "GUID"), latest version ModuleVersion, - and latest version within a range MinimumVersion - MaximumVersion. - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - [CmdletBinding()] - param( - # The path to the manifest file. - [Parameter(Mandatory)] - [string] $ManifestFilePath - ) - - Write-Host 'Resolving dependencies' - $manifest = Import-PowerShellDataFile -Path $ManifestFilePath - Write-Host " - Reading [$ManifestFilePath]" - Write-Host " - Found [$($manifest.RequiredModules.Count)] module(s) to install" - - foreach ($requiredModule in $manifest.RequiredModules) { - # Build parameters for Install-PSResource (new version spec). - $psResourceParams = @{ - Repository = 'PSGallery' - TrustRepository = $true - } - # Build parameters for Import-Module (legacy version spec). - $importParams = @{ - Force = $true - Verbose = $false - } - - if ($requiredModule -is [string]) { - $psResourceParams.Name = $requiredModule - $importParams.Name = $requiredModule - } else { - $psResourceParams.Name = $requiredModule.ModuleName - $importParams.Name = $requiredModule.ModuleName - - # Convert legacy version info for Install-PSResource. - $versionSpec = Convert-VersionSpec ` - -MinimumVersion $requiredModule.ModuleVersion ` - -MaximumVersion $requiredModule.MaximumVersion ` - -RequiredVersion $requiredModule.RequiredVersion - - if ($versionSpec) { - $psResourceParams.Version = $versionSpec - } - - # For Import-Module, keep the original version parameters. - if ($requiredModule.ModuleVersion) { - $importParams.MinimumVersion = $requiredModule.ModuleVersion - } - if ($requiredModule.RequiredVersion) { - $importParams.RequiredVersion = $requiredModule.RequiredVersion - } - if ($requiredModule.MaximumVersion) { - $importParams.MaximumVersion = $requiredModule.MaximumVersion - } - } - - Write-Host " - [$($psResourceParams.Name)] - Installing module with Install-PSResource using version spec: $($psResourceParams.Version)" - $VerbosePreferenceOriginal = $VerbosePreference - $VerbosePreference = 'SilentlyContinue' - $retryCount = 5 - $retryDelay = 10 - for ($i = 0; $i -lt $retryCount; $i++) { - try { - Install-PSResource @psResourceParams - break - } catch { - Write-Warning "Installation of $($psResourceParams.Name) failed with error: $_" - if ($i -eq $retryCount - 1) { - throw - } - Write-Warning "Retrying in $retryDelay seconds..." - Start-Sleep -Seconds $retryDelay - } - } - $VerbosePreference = $VerbosePreferenceOriginal - - Write-Host " - [$($importParams.Name)] - Importing module with legacy version spec" - $VerbosePreferenceOriginal = $VerbosePreference - $VerbosePreference = 'SilentlyContinue' - Import-Module @importParams - $VerbosePreference = $VerbosePreferenceOriginal - Write-Host " - [$($importParams.Name)] - Done" - } - Write-Host ' - Resolving dependencies - Done' -} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b9bc1475..573ae046 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,9 +1,4 @@ -$helperPath = "$PSScriptRoot/helpers" -Get-ChildItem -Path $helperPath -Filter '*.ps1' -Recurse | ForEach-Object { - . $_.FullName -} - -# If test type is module, the code we ought to test is in the WorkingDirectory/outputs/module/Name folder, +# If test type is module, the code we ought to test is in the WorkingDirectory/outputs/module/Name folder, # otherwise it's in the WorkingDirectory/src folder. $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name)) { @@ -18,15 +13,7 @@ $localTestPath = Resolve-Path -Path 'tests' | Select-Object -ExpandProperty Path switch ($settings) { 'Module' { $modulePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path - $manifestFilePath = Join-Path -Path $modulePath "$moduleName.psd1" - Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose - Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath - $PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1 - $codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force | Select-Object -ExpandProperty FullName - Copy-Item -Path "$modulePath/*" -Destination $codePath -Recurse -Force - LogGroup 'Importing module' { - Import-Module -Name $moduleName -Verbose - } + Install-PSModule -Path $modulePath } 'SourceCode' { $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path From 01fc381bcc5afd6afe3ea32cb819e59f3aea3fe1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 20:10:42 +0100 Subject: [PATCH 144/172] Update Install-PSModuleHelpers action to use version 1 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9dabe922..df26925a 100644 --- a/action.yml +++ b/action.yml @@ -36,7 +36,7 @@ runs: using: composite steps: - name: Install-PSModuleHelpers - uses: PSModule/Install-PSModuleHelpers@main + uses: PSModule/Install-PSModuleHelpers@v1 - name: Get test paths uses: PSModule/Github-Script@v1 From 35588d92f2042d86476b7abb441de659fb4a19ce Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 20:14:23 +0100 Subject: [PATCH 145/172] Update module installation to capture and store the code path returned by Install-PSModule --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 573ae046..12cff757 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -13,7 +13,7 @@ $localTestPath = Resolve-Path -Path 'tests' | Select-Object -ExpandProperty Path switch ($settings) { 'Module' { $modulePath = Resolve-Path -Path "outputs/module/$moduleName" | Select-Object -ExpandProperty Path - Install-PSModule -Path $modulePath + $codePath = Install-PSModule -Path $modulePath -PassThru } 'SourceCode' { $codePath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path From e45c49c25f23a8e4252b18e5e0c30a65d4160504 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 6 Mar 2025 13:19:44 +0100 Subject: [PATCH 146/172] Add CodeCoverage_CoveragePercentTarget parameter to action.yml --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index df26925a..ead3e693 100644 --- a/action.yml +++ b/action.yml @@ -66,5 +66,6 @@ runs: Version: ${{ inputs.Version }} WorkingDirectory: ${{ inputs.WorkingDirectory }} TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} + CodeCoverage_CoveragePercentTarget: 0 Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} From 08e677562f1eee32758072cb8a9bd294533f1399 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 6 Mar 2025 17:16:59 +0100 Subject: [PATCH 147/172] Update WorkingDirectory default value to current directory in README and action.yml --- README.md | 4 +--- action.yml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a686adab..4ce12cf6 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,6 @@ jobs: uses: PSModule/Test-PSModule@main with: Settings: SourceCode - WorkingDirectory: ${{ github.workspace }} ``` @@ -86,7 +85,6 @@ jobs: uses: PSModule/Test-PSModule@main with: Settings: Module - WorkingDirectory: ${{ github.workspace }} ``` @@ -103,7 +101,7 @@ jobs: | `Verbose` | Enable verbose output. | `false` | `'false'` | | `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | | `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | -| `WorkingDirectory` | The working directory to use for the action. This is the root folder where tests and outputs are expected. | `false` | `${{ github.workspace }}` | +| `WorkingDirectory` | The working directory to use for the action. This is the root folder where tests and outputs are expected. | `false` | `'.'` | ### Outputs diff --git a/action.yml b/action.yml index ead3e693..229d8053 100644 --- a/action.yml +++ b/action.yml @@ -30,7 +30,7 @@ inputs: WorkingDirectory: description: The working directory to use for the action. This is the root folder where tests and outputs are expected. required: false - default: ${{ github.workspace }} + default: '.' runs: using: composite From bf83470a0b32088672260b89d825b1670e69029b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 8 Mar 2025 11:57:31 +0100 Subject: [PATCH 148/172] Remove GITHUB_TOKEN environment variable from Auto-Release workflow --- .github/workflows/Auto-Release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index ec157c9d..680da5c0 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -30,7 +30,5 @@ jobs: - name: Auto-Release uses: PSModule/Auto-Release@v1 - env: - GITHUB_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication with: IncrementalPrerelease: false From 976a84e4a85880548737347e656ffbc86184ea83 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 9 Mar 2025 18:51:39 +0100 Subject: [PATCH 149/172] Add outputs for test run results in action.yml --- action.yml | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/action.yml b/action.yml index 229d8053..2763890b 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,56 @@ inputs: required: false default: '.' +outputs: + Outcome: + description: | + The outcome of the test run. + value: ${{ steps.test.outcome }} + Conclusion: + description: | + The conclusion of the test run. + value: ${{ steps.test.conclusion }} + Executed: + description: | + Whether tests were executed. + value: ${{ steps.test.outputs.Executed }} + Result: + description: | + Overall result of the Pester test run (e.g., Passed, Failed). + value: ${{ steps.test.outputs.Result }} + FailedCount: + description: | + Number of failed tests. + value: ${{ steps.test.outputs.FailedCount }} + FailedBlocksCount: + description: | + Number of failed blocks. + value: ${{ steps.test.outputs.FailedBlocksCount }} + FailedContainersCount: + description: | + Number of failed containers. + value: ${{ steps.test.outputs.FailedContainersCount }} + PassedCount: + description: | + Number of passed tests. + value: ${{ steps.test.outputs.PassedCount }} + SkippedCount: + description: | + Number of skipped tests. + value: ${{ steps.test.outputs.SkippedCount }} + InconclusiveCount: + description: | + Number of inconclusive tests. + value: ${{ steps.test.outputs.InconclusiveCount }} + NotRunCount: + description: | + Number of tests not run. + value: ${{ steps.test.outputs.NotRunCount }} + TotalCount: + description: | + Total count of tests. + value: ${{ steps.test.outputs.TotalCount }} + runs: using: composite steps: @@ -66,6 +116,7 @@ runs: Version: ${{ inputs.Version }} WorkingDirectory: ${{ inputs.WorkingDirectory }} TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} + StepSummary_Enabled: true CodeCoverage_CoveragePercentTarget: 0 Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} From e7186d64d8f14da0a60b6619b5aa2a9ccf01884e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 9 Mar 2025 20:47:11 +0100 Subject: [PATCH 150/172] Update Invoke-Pester action to version 4 and remove StepSummary_Enabled parameter --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 2763890b..27dadb2d 100644 --- a/action.yml +++ b/action.yml @@ -104,7 +104,7 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - uses: PSModule/Invoke-Pester@v3 + uses: PSModule/Invoke-Pester@v4 id: test env: LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} @@ -116,7 +116,6 @@ runs: Version: ${{ inputs.Version }} WorkingDirectory: ${{ inputs.WorkingDirectory }} TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} - StepSummary_Enabled: true CodeCoverage_CoveragePercentTarget: 0 Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} From 3685052ceeb57cb7529e15baf7b2ec06791c654b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 10 Mar 2025 11:23:33 +0100 Subject: [PATCH 151/172] Refactor output handling in main.ps1 to use GITHUB_OUTPUT for setting module and code paths --- scripts/main.ps1 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 12cff757..1706791f 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -1,6 +1,7 @@ -# If test type is module, the code we ought to test is in the WorkingDirectory/outputs/module/Name folder, -# otherwise it's in the WorkingDirectory/src folder. +[CmdletBinding()] +param() +$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' $moduleName = if ([string]::IsNullOrEmpty($env:PSMODULE_TEST_PSMODULE_INPUT_Name)) { $env:GITHUB_REPOSITORY_NAME } else { @@ -31,7 +32,7 @@ switch ($settings) { TestPath = $testPath } | Format-List | Out-String -Set-GitHubOutput -Name ModuleName -Value $moduleName -Set-GitHubOutput -Name CodePath -Value $codePath -Set-GitHubOutput -Name LocalTestPath -Value $localTestPath -Set-GitHubOutput -Name TestPath -Value $testPath +"ModuleName=$moduleName" >> $env:GITHUB_OUTPUT +"CodePath=$codePath" >> $env:GITHUB_OUTPUT +"LocalTestPath=$localTestPath" >> $env:GITHUB_OUTPUT +"TestPath=$testPath" >> $env:GITHUB_OUTPUT From 611fcc7e0652832048a38e18626ac42c2b5b3eb9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 10 Mar 2025 11:23:45 +0100 Subject: [PATCH 152/172] Refactor action.yml to streamline test path retrieval by executing main.ps1 directly --- action.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 27dadb2d..ef64c4e1 100644 --- a/action.yml +++ b/action.yml @@ -89,19 +89,15 @@ runs: uses: PSModule/Install-PSModuleHelpers@v1 - name: Get test paths - uses: PSModule/Github-Script@v1 + shell: pwsh id: paths env: PSMODULE_TEST_PSMODULE_INPUT_Name: ${{ inputs.Name }} PSMODULE_TEST_PSMODULE_INPUT_Settings: ${{ inputs.Settings }} PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }} - with: - Debug: ${{ inputs.Debug }} - Prerelease: ${{ inputs.Prerelease }} - Verbose: ${{ inputs.Verbose }} - Version: ${{ inputs.Version }} - WorkingDirectory: ${{ inputs.WorkingDirectory }} - Script: ${{ github.action_path }}/scripts/main.ps1 + run: | + # Get test paths + ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester uses: PSModule/Invoke-Pester@v4 From 55f8a2189d80664fade452f547dd4b6e428ca1e7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 10 Mar 2025 11:29:48 +0100 Subject: [PATCH 153/172] Update action.yml to set working directory for test path retrieval --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ef64c4e1..4e65f8af 100644 --- a/action.yml +++ b/action.yml @@ -91,10 +91,10 @@ runs: - name: Get test paths shell: pwsh id: paths + working-directory: ${{ inputs.WorkingDirectory }} env: PSMODULE_TEST_PSMODULE_INPUT_Name: ${{ inputs.Name }} PSMODULE_TEST_PSMODULE_INPUT_Settings: ${{ inputs.Settings }} - PSMODULE_TEST_PSMODULE_INPUT_WorkingDirectory: ${{ inputs.WorkingDirectory }} run: | # Get test paths ${{ github.action_path }}/scripts/main.ps1 From 49257cc18e60da61d871cb0ed6f9b974de712e4c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 10 Mar 2025 11:34:14 +0100 Subject: [PATCH 154/172] Refactor action.yml to simplify environment variable retrieval for test paths --- action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 4e65f8af..8a29e63c 100644 --- a/action.yml +++ b/action.yml @@ -103,8 +103,8 @@ runs: uses: PSModule/Invoke-Pester@v4 id: test env: - LocalTestPath: ${{ fromJson(steps.paths.outputs.result).LocalTestPath }} - WorkingDirectory: ${{ fromJson(steps.paths.outputs.result).WorkingDirectory }} + LocalTestPath: ${{ steps.paths.outputs.LocalTestPath }} + WorkingDirectory: ${{ inputs.WorkingDirectory }} with: Debug: ${{ inputs.Debug }} Prerelease: ${{ inputs.Prerelease }} @@ -113,5 +113,5 @@ runs: WorkingDirectory: ${{ inputs.WorkingDirectory }} TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} CodeCoverage_CoveragePercentTarget: 0 - Path: ${{ fromJson(steps.paths.outputs.result).TestPath }} - Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} + Path: ${{ steps.paths.outputs.TestPath }} + Run_Path: ${{ steps.paths.outputs.CodePath }} From c060792466db212fcd6483c049cf2e9406be2187 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 10 Mar 2025 12:07:31 +0100 Subject: [PATCH 155/172] Refactor action.yml to enhance clarity in environment variable usage --- .../SourceCode/PSModule/PSModule.Tests.ps1 | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index 95e0100d..91e809ea 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -27,85 +27,85 @@ Param( BeforeAll { $scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File - LogGroup " - Script files [$($scriptFiles.Count)]" { - $scriptFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Script files [$($scriptFiles.Count)]" + $scriptFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $functionsPath = Join-Path -Path $Path -ChildPath 'functions' $functionFiles = (Test-Path -Path $functionsPath) ? (Get-ChildItem -Path $functionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Function files [$($functionFiles.Count)]" { - $functionFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Function files [$($functionFiles.Count)]" + $functionFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private' $privateFunctionFiles = (Test-Path -Path $privateFunctionsPath) ? (Get-ChildItem -Path $privateFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private [$($privateFunctionFiles.Count)]" { - $privateFunctionFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Private [$($privateFunctionFiles.Count)]" + $privateFunctionFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public' $publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public [$($publicFunctionFiles.Count)]" { - $publicFunctionFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Public [$($publicFunctionFiles.Count)]" + $publicFunctionFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $variablesPath = Join-Path -Path $Path -ChildPath 'variables' $variableFiles = (Test-Path -Path $variablesPath) ? (Get-ChildItem -Path $variablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Variable files [$($variableFiles.Count)]" { - $variableFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Variable files [$($variableFiles.Count)]" + $variableFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $privateVariablesPath = Join-Path -Path $variablesPath -ChildPath 'private' $privateVariableFiles = (Test-Path -Path $privateVariablesPath) ? (Get-ChildItem -Path $privateVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private [$($privateVariableFiles.Count)]" { - $privateVariableFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Private [$($privateVariableFiles.Count)]" + $privateVariableFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $publicVariablesPath = Join-Path -Path $variablesPath -ChildPath 'public' $publicVariableFiles = (Test-Path -Path $publicVariablesPath) ? (Get-ChildItem -Path $publicVariablesPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public [$($publicVariableFiles.Count)]" { - $publicVariableFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Public [$($publicVariableFiles.Count)]" + $publicVariableFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $classPath = Join-Path -Path $Path -ChildPath 'classes' $classFiles = (Test-Path -Path $classPath) ? (Get-ChildItem -Path $classPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Class [$($classFiles.Count)]" { - $classFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Class [$($classFiles.Count)]" + $classFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $privateClassPath = Join-Path -Path $classPath -ChildPath 'private' $privateClassFiles = (Test-Path -Path $privateClassPath) ? (Get-ChildItem -Path $privateClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Private [$($privateClassFiles.Count)]" { - $privateClassFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Private [$($privateClassFiles.Count)]" + $privateClassFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $publicClassPath = Join-Path -Path $classPath -ChildPath 'public' $publicClassFiles = (Test-Path -Path $publicClassPath) ? (Get-ChildItem -Path $publicClassPath -File -Filter '*.ps1' -Recurse) : $null - LogGroup " - Public [$($publicClassFiles.Count)]" { - $publicClassFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Public [$($publicClassFiles.Count)]" + $publicClassFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' $testFiles = Get-ChildItem -Path $TestsPath -Include *.Tests.ps1 -Recurse -File - LogGroup " - Test files [$($testFiles.Count)]" { - $testFiles | ForEach-Object { - Write-Host " - $($_.FullName)" - } + "::group:: - Test files [$($testFiles.Count)]" + $testFiles | ForEach-Object { + Write-Host " - $($_.FullName)" } + '::endgroup::' } Describe 'PSModule - SourceCode tests' { @@ -119,7 +119,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:NumberOfProcessors:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping NumberOfProcessors test' + "::warning title=Skipping NumberOfProcessors test:: - $relativePath - $skipReason" } else { $issues += " - $($_.Path):L$($_.LineNumber)" } @@ -136,7 +136,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:Verbose:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping Verbose test' + "::warning title=Skipping Verbose test:: - $relativePath - $skipReason" } else { Select-String -Path $filePath -Pattern '\s(-Verbose(?::\$true)?)\b(?!:\$false)' -AllMatches | ForEach-Object { $issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)" @@ -154,7 +154,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:OutNull:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping OutNull test' + "::warning title=Skipping OutNull test:: - $relativePath - $skipReason" } else { Select-String -Path $filePath -Pattern 'Out-Null' -AllMatches | ForEach-Object { $issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)" @@ -172,7 +172,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:NoTernary:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping NoTernary test' + "::warning title=Skipping NoTernary test:: - $relativePath - $skipReason" } else { Select-String -Path $filePath -Pattern '(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping LowercaseKeywords test' + "::warning title=Skipping LowercaseKeywords test:: - $relativePath - $skipReason" } else { $errors = $null $tokens = $null @@ -246,7 +246,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:FunctionCount:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionCount test' + "::warning title=Skipping FunctionCount test:: - $relativePath - $skipReason" } else { $Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true ) @@ -267,7 +267,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:FunctionName:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionName test' + "::warning title=Skipping FunctionName test:: - $relativePath - $skipReason" } else { $Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true ) @@ -288,7 +288,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:CmdletBinding:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping CmdletBinding test' + "::warning title=Skipping CmdletBinding test:: - $relativePath - $skipReason" } else { $scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $scriptAst.FindAll({ $true }, $true) @@ -314,7 +314,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:ParamBlock:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping ParamBlock test' + "::warning title=Skipping ParamBlock test:: - $relativePath - $skipReason" } else { $scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParamBlockAst] }, $true) @@ -366,7 +366,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:FunctionTest:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionTest test' + "::warning title=Skipping FunctionTest test:: - $relativePath - $skipReason" } else { $Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true ) From aa46af5ab05788adfda97ddf39ea8f1b656ab0a4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 10 Mar 2025 12:13:00 +0100 Subject: [PATCH 156/172] Refactor action.yml to improve environment variable management and enhance readability --- .../SourceCode/PSModule/PSModule.Tests.ps1 | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 index 91e809ea..001ca7f7 100644 --- a/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 +++ b/scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1 @@ -27,85 +27,85 @@ Param( BeforeAll { $scriptFiles = Get-ChildItem -Path $Path -Include *.psm1, *.ps1 -Recurse -File - "::group:: - Script files [$($scriptFiles.Count)]" + Write-Host "::group:: - Script files [$($scriptFiles.Count)]" $scriptFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $functionsPath = Join-Path -Path $Path -ChildPath 'functions' $functionFiles = (Test-Path -Path $functionsPath) ? (Get-ChildItem -Path $functionsPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Function files [$($functionFiles.Count)]" + Write-Host "::group:: - Function files [$($functionFiles.Count)]" $functionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $privateFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'private' $privateFunctionFiles = (Test-Path -Path $privateFunctionsPath) ? (Get-ChildItem -Path $privateFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Private [$($privateFunctionFiles.Count)]" + Write-Host "::group:: - Private [$($privateFunctionFiles.Count)]" $privateFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $publicFunctionsPath = Join-Path -Path $functionsPath -ChildPath 'public' $publicFunctionFiles = (Test-Path -Path $publicFunctionsPath) ? (Get-ChildItem -Path $publicFunctionsPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Public [$($publicFunctionFiles.Count)]" + Write-Host "::group:: - Public [$($publicFunctionFiles.Count)]" $publicFunctionFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $variablesPath = Join-Path -Path $Path -ChildPath 'variables' $variableFiles = (Test-Path -Path $variablesPath) ? (Get-ChildItem -Path $variablesPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Variable files [$($variableFiles.Count)]" + Write-Host "::group:: - Variable files [$($variableFiles.Count)]" $variableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $privateVariablesPath = Join-Path -Path $variablesPath -ChildPath 'private' $privateVariableFiles = (Test-Path -Path $privateVariablesPath) ? (Get-ChildItem -Path $privateVariablesPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Private [$($privateVariableFiles.Count)]" + Write-Host "::group:: - Private [$($privateVariableFiles.Count)]" $privateVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $publicVariablesPath = Join-Path -Path $variablesPath -ChildPath 'public' $publicVariableFiles = (Test-Path -Path $publicVariablesPath) ? (Get-ChildItem -Path $publicVariablesPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Public [$($publicVariableFiles.Count)]" + Write-Host "::group:: - Public [$($publicVariableFiles.Count)]" $publicVariableFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $classPath = Join-Path -Path $Path -ChildPath 'classes' $classFiles = (Test-Path -Path $classPath) ? (Get-ChildItem -Path $classPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Class [$($classFiles.Count)]" + Write-Host "::group:: - Class [$($classFiles.Count)]" $classFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $privateClassPath = Join-Path -Path $classPath -ChildPath 'private' $privateClassFiles = (Test-Path -Path $privateClassPath) ? (Get-ChildItem -Path $privateClassPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Private [$($privateClassFiles.Count)]" + Write-Host "::group:: - Private [$($privateClassFiles.Count)]" $privateClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $publicClassPath = Join-Path -Path $classPath -ChildPath 'public' $publicClassFiles = (Test-Path -Path $publicClassPath) ? (Get-ChildItem -Path $publicClassPath -File -Filter '*.ps1' -Recurse) : $null - "::group:: - Public [$($publicClassFiles.Count)]" + Write-Host "::group:: - Public [$($publicClassFiles.Count)]" $publicClassFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' $testFiles = Get-ChildItem -Path $TestsPath -Include *.Tests.ps1 -Recurse -File - "::group:: - Test files [$($testFiles.Count)]" + Write-Host "::group:: - Test files [$($testFiles.Count)]" $testFiles | ForEach-Object { Write-Host " - $($_.FullName)" } - '::endgroup::' + Write-Host '::endgroup::' } Describe 'PSModule - SourceCode tests' { @@ -119,7 +119,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:NumberOfProcessors:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping NumberOfProcessors test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping NumberOfProcessors test:: - $relativePath - $skipReason" } else { $issues += " - $($_.Path):L$($_.LineNumber)" } @@ -136,7 +136,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:Verbose:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping Verbose test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping Verbose test:: - $relativePath - $skipReason" } else { Select-String -Path $filePath -Pattern '\s(-Verbose(?::\$true)?)\b(?!:\$false)' -AllMatches | ForEach-Object { $issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)" @@ -154,7 +154,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:OutNull:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping OutNull test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping OutNull test:: - $relativePath - $skipReason" } else { Select-String -Path $filePath -Pattern 'Out-Null' -AllMatches | ForEach-Object { $issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)" @@ -172,7 +172,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:NoTernary:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping NoTernary test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping NoTernary test:: - $relativePath - $skipReason" } else { Select-String -Path $filePath -Pattern '(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping LowercaseKeywords test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping LowercaseKeywords test:: - $relativePath - $skipReason" } else { $errors = $null $tokens = $null @@ -246,7 +246,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:FunctionCount:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping FunctionCount test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping FunctionCount test:: - $relativePath - $skipReason" } else { $Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true ) @@ -267,7 +267,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:FunctionName:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping FunctionName test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping FunctionName test:: - $relativePath - $skipReason" } else { $Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true ) @@ -288,7 +288,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:CmdletBinding:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping CmdletBinding test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping CmdletBinding test:: - $relativePath - $skipReason" } else { $scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $scriptAst.FindAll({ $true }, $true) @@ -314,7 +314,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:ParamBlock:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping ParamBlock test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping ParamBlock test:: - $relativePath - $skipReason" } else { $scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParamBlockAst] }, $true) @@ -366,7 +366,7 @@ Describe 'PSModule - SourceCode tests' { $skipTest = Select-String -Path $filePath -Pattern '#SkipTest:FunctionTest:(?.+)' -AllMatches if ($skipTest.Matches.Count -gt 0) { $skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value - "::warning title=Skipping FunctionTest test:: - $relativePath - $skipReason" + Write-Host "::warning title=Skipping FunctionTest test:: - $relativePath - $skipReason" } else { $Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null) $tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true ) From ef7d899a5798923b897231bd077ae8f093c58fb7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 10 Mar 2025 12:22:59 +0100 Subject: [PATCH 157/172] Update README.md to add a blank line for improved formatting --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4ce12cf6..0fa4eaaf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Test-PSModule + Test PowerShell modules with Pester and PSScriptAnalyzer. This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. From d4cfada4f4405b4e19b3f8ef9c50c1ab0bb9472d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 10 Mar 2025 12:37:26 +0100 Subject: [PATCH 158/172] Remove unnecessary blank line in README.md for improved formatting --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 0fa4eaaf..4ce12cf6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Test-PSModule - Test PowerShell modules with Pester and PSScriptAnalyzer. This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. From ef5bbec92d3b68f23c33bcbf2833fca6158f2c1c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 15:24:06 +0100 Subject: [PATCH 159/172] Add TestResult_Enabled flag to action.yml for enhanced test configuration --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 8a29e63c..68edbaba 100644 --- a/action.yml +++ b/action.yml @@ -111,6 +111,7 @@ runs: Verbose: ${{ inputs.Verbose }} Version: ${{ inputs.Version }} WorkingDirectory: ${{ inputs.WorkingDirectory }} + TestResult_Enabled: true TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} CodeCoverage_CoveragePercentTarget: 0 Path: ${{ steps.paths.outputs.TestPath }} From d58009d60cd3165a3ec671b9fadbcb72ca10a22d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 15:30:36 +0100 Subject: [PATCH 160/172] Refactor GitHub Actions workflows by deleting obsolete Action-Test.yml and creating separate workflows for Src-Default, Src-WithManifest, and outputs --- .github/workflows/Action-Test-Src-Default.yml | 35 +++++++++ .../Action-Test-Src-WithManifest.yml | 35 +++++++++ .github/workflows/Action-Test-outputs.yml | 35 +++++++++ .github/workflows/Action-Test.yml | 73 ------------------- 4 files changed, 105 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/Action-Test-Src-Default.yml create mode 100644 .github/workflows/Action-Test-Src-WithManifest.yml create mode 100644 .github/workflows/Action-Test-outputs.yml delete mode 100644 .github/workflows/Action-Test.yml diff --git a/.github/workflows/Action-Test-Src-Default.yml b/.github/workflows/Action-Test-Src-Default.yml new file mode 100644 index 00000000..e87ee9eb --- /dev/null +++ b/.github/workflows/Action-Test-Src-Default.yml @@ -0,0 +1,35 @@ +name: Action-Test + +run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' + +on: + workflow_dispatch: + pull_request: + schedule: + - cron: '0 0 * * *' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +jobs: + ActionTestSrcDefault: + name: Action-Test [Src-Default] - [${{ matrix.os }}] + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + id: action-test + with: + Name: PSModuleTest + WorkingDirectory: tests/srcTestRepo + Settings: SourceCode diff --git a/.github/workflows/Action-Test-Src-WithManifest.yml b/.github/workflows/Action-Test-Src-WithManifest.yml new file mode 100644 index 00000000..0cdcd633 --- /dev/null +++ b/.github/workflows/Action-Test-Src-WithManifest.yml @@ -0,0 +1,35 @@ +name: Action-Test + +run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' + +on: + workflow_dispatch: + pull_request: + schedule: + - cron: '0 0 * * *' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +jobs: + ActionTestsSrcWithManifest: + name: Action-Test [Src-WithManifest] - [${{ matrix.os }}] + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + id: action-test + with: + Name: PSModuleTest + WorkingDirectory: tests/srcWithManifestTestRepo + Settings: SourceCode diff --git a/.github/workflows/Action-Test-outputs.yml b/.github/workflows/Action-Test-outputs.yml new file mode 100644 index 00000000..1c6b645b --- /dev/null +++ b/.github/workflows/Action-Test-outputs.yml @@ -0,0 +1,35 @@ +name: Action-Test + +run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' + +on: + workflow_dispatch: + pull_request: + schedule: + - cron: '0 0 * * *' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +jobs: + ActionTestOutputs: + name: Action-Test [outputs] - [${{ matrix.os }}] + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + id: action-test + with: + Name: PSModuleTest + WorkingDirectory: tests/outputTestRepo + Settings: Module diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml deleted file mode 100644 index 36dee76b..00000000 --- a/.github/workflows/Action-Test.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Action-Test - -run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' - -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '0 0 * * *' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: {} - -jobs: - ActionTestOutputs: - name: Action-Test [outputs] - [${{ matrix.os }}] - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - id: action-test - with: - Name: PSModuleTest - WorkingDirectory: tests/outputTestRepo - Settings: Module - - ActionTestSrcDefault: - name: Action-Test [Src-Default] - [${{ matrix.os }}] - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - id: action-test - with: - Name: PSModuleTest - WorkingDirectory: tests/srcTestRepo - Settings: SourceCode - - ActionTestsSrcWithManifest: - name: Action-Test [Src-WithManifest] - [${{ matrix.os }}] - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - id: action-test - with: - Name: PSModuleTest - WorkingDirectory: tests/srcWithManifestTestRepo - Settings: SourceCode From 77488b7786aa8220c9ffb465373dd8eadedd26da Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 15:32:36 +0100 Subject: [PATCH 161/172] Rename GitHub Actions workflows for clarity: Action-Test to Action-Test-Src-Default, Action-Test-Src-WithManifest, and Action-Test-outputs --- .github/workflows/Action-Test-Src-Default.yml | 4 ++-- .github/workflows/Action-Test-Src-WithManifest.yml | 4 ++-- .github/workflows/Action-Test-outputs.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Action-Test-Src-Default.yml b/.github/workflows/Action-Test-Src-Default.yml index e87ee9eb..5d3301b2 100644 --- a/.github/workflows/Action-Test-Src-Default.yml +++ b/.github/workflows/Action-Test-Src-Default.yml @@ -1,6 +1,6 @@ -name: Action-Test +name: Action-Test-Src-Default -run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' +run-name: 'Action-Test-Src-Default - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' on: workflow_dispatch: diff --git a/.github/workflows/Action-Test-Src-WithManifest.yml b/.github/workflows/Action-Test-Src-WithManifest.yml index 0cdcd633..53dc398a 100644 --- a/.github/workflows/Action-Test-Src-WithManifest.yml +++ b/.github/workflows/Action-Test-Src-WithManifest.yml @@ -1,6 +1,6 @@ -name: Action-Test +name: Action-Test-Src-WithManifest -run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' +run-name: 'Action-Test-Src-WithManifest - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' on: workflow_dispatch: diff --git a/.github/workflows/Action-Test-outputs.yml b/.github/workflows/Action-Test-outputs.yml index 1c6b645b..a13d2beb 100644 --- a/.github/workflows/Action-Test-outputs.yml +++ b/.github/workflows/Action-Test-outputs.yml @@ -1,6 +1,6 @@ -name: Action-Test +name: Action-Test-outputs -run-name: 'Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' +run-name: 'Action-Test-outputs - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}' on: workflow_dispatch: From 71516aa4c93989be1de12ddcd93916b8db53efb7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 15:49:06 +0100 Subject: [PATCH 162/172] Add CodeCoveragePercentTarget input and update related configurations in action.yml and README.md --- README.md | 3 ++- action.yml | 7 +++++-- scripts/tests/SourceCode/SourceCode.Configuration.ps1 | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4ce12cf6..8d53fa14 100644 --- a/README.md +++ b/README.md @@ -95,8 +95,9 @@ jobs: | Name | Description | Required | Default | | ---- | ----------- | -------- | ------- | -| `Settings` | The type of tests to run. Can be either `Module` or `SourceCode`. | `true` | | | `Name` | The name of the module to test. The name of the repository is used if not specified. | `false` | | +| `Settings` | The type of tests to run. Can be either `Module` or `SourceCode`. | `true` | | +| `CodeCoveragePercentTarget` | The target code coverage percentage. | `false` | `'0'` | | `Debug` | Enable debug output. | `false` | `'false'` | | `Verbose` | Enable verbose output. | `false` | `'false'` | | `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | diff --git a/action.yml b/action.yml index 68edbaba..5177efd4 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,10 @@ inputs: Settings: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true + CodeCoveragePercentTarget: + description: The target code coverage percentage. This is used to determine if the code coverage meets the specified threshold. + required: false + default: '0' Debug: description: Enable debug output. required: false @@ -111,8 +115,7 @@ runs: Verbose: ${{ inputs.Verbose }} Version: ${{ inputs.Version }} WorkingDirectory: ${{ inputs.WorkingDirectory }} - TestResult_Enabled: true TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} - CodeCoverage_CoveragePercentTarget: 0 + CodeCoverage_CoveragePercentTarget: ${{ inputs.CodeCoveragePercentTarget }} Path: ${{ steps.paths.outputs.TestPath }} Run_Path: ${{ steps.paths.outputs.CodePath }} diff --git a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 index e4950855..e76f767f 100644 --- a/scripts/tests/SourceCode/SourceCode.Configuration.ps1 +++ b/scripts/tests/SourceCode/SourceCode.Configuration.ps1 @@ -1,5 +1,8 @@ @{ - Output = @{ + TestResult = @{ + Enabled = $true + } + Output = @{ Verbosity = 'Detailed' } } From 3496ea18d386972f0d80dfee2d6c9d0b3242a102 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 16:05:25 +0100 Subject: [PATCH 163/172] Add CodeCoverage_CoveragePercentTarget to workflow and update README.md --- .../Action-Test-Src-WithManifest.yml | 1 + README.md | 45 +++- action.yml | 235 +++++++++++++++++- 3 files changed, 275 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Action-Test-Src-WithManifest.yml b/.github/workflows/Action-Test-Src-WithManifest.yml index 53dc398a..59b6a41b 100644 --- a/.github/workflows/Action-Test-Src-WithManifest.yml +++ b/.github/workflows/Action-Test-Src-WithManifest.yml @@ -33,3 +33,4 @@ jobs: Name: PSModuleTest WorkingDirectory: tests/srcWithManifestTestRepo Settings: SourceCode + CodeCoverage_CoveragePercentTarget: 80 diff --git a/README.md b/README.md index 8d53fa14..b8f4c58a 100644 --- a/README.md +++ b/README.md @@ -97,12 +97,55 @@ jobs: | ---- | ----------- | -------- | ------- | | `Name` | The name of the module to test. The name of the repository is used if not specified. | `false` | | | `Settings` | The type of tests to run. Can be either `Module` or `SourceCode`. | `true` | | -| `CodeCoveragePercentTarget` | The target code coverage percentage. | `false` | `'0'` | | `Debug` | Enable debug output. | `false` | `'false'` | | `Verbose` | Enable verbose output. | `false` | `'false'` | | `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | | `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | | `WorkingDirectory` | The working directory to use for the action. This is the root folder where tests and outputs are expected. | `false` | `'.'` | +| `StepSummary_Mode` | Controls which tests to show in the GitHub step summary. Allows "Full" (all tests), "Failed" (only failed tests), or "None" (disable step summary). | `Failed` | +| `StepSummary_ShowTestOverview` | Controls whether to show the test overview table in the GitHub step summary. | `false` | +| `StepSummary_ShowConfiguration` | Controls whether to show the configuration details in the GitHub step summary. | `false` | +| `Run_ExcludePath` | Directories/files to exclude from the run. | | +| `Run_ScriptBlock` | ScriptBlocks containing tests to be executed. | | +| `Run_Container` | ContainerInfo objects containing tests to be executed. | | +| `Run_TestExtension` | Filter used to identify test files (e.g. `.Tests.ps1`). | | +| `Run_Exit` | Whether to exit with a non-zero exit code on failure. | | +| `Run_Throw` | Whether to throw an exception on test failure. | | +| `Run_SkipRun` | Discovery only, skip actual test run. | | +| `Run_SkipRemainingOnFailure` | Skips remaining tests after the first failure. Options: `None`, `Run`, `Container`, `Block`. | | +| `Filter_Tag` | Tags of Describe/Context/It blocks to run. | | +| `Filter_ExcludeTag` | Tags of Describe/Context/It blocks to exclude. | | +| `Filter_Line` | Filter by file + scriptblock start line (e.g. `C:\tests\file1.Tests.ps1:37`). | | +| `Filter_ExcludeLine` | Exclude by file + scriptblock start line. Precedence over `Filter_Line`. | | +| `Filter_FullName` | Full name of a test with wildcards, joined by dot. E.g. `*.describe Get-Item.test1` | | +| `CodeCoverage_Enabled` | Enable code coverage. | | +| `CodeCoverage_OutputFormat` | Format for the coverage report. Possible values: `JaCoCo`, `CoverageGutters`, `Cobertura`. | | +| `CodeCoverage_OutputPath` | Where to save the code coverage report (relative to the current dir). | | +| `CodeCoverage_OutputEncoding` | Encoding of the coverage file. | | +| `CodeCoverage_Path` | Files/directories to measure coverage on (by default, reuses `Path` from the general settings). | | +| `CodeCoverage_ExcludeTests` | Exclude tests themselves from coverage. | | +| `CodeCoverage_RecursePaths` | Recurse through coverage directories. | | +| `CodeCoverage_CoveragePercentTarget` | Desired minimum coverage percentage. | | +| `CodeCoverage_UseBreakpoints` | **Experimental**: When `false`, use a Profiler-based tracer instead of breakpoints. | | +| `CodeCoverage_SingleHitBreakpoints` | Remove breakpoints after first hit. | | +| `TestResult_Enabled` | Enable test-result output (e.g. NUnitXml, JUnitXml). | | +| `TestResult_OutputFormat` | Possible values: `NUnitXml`, `NUnit2.5`, `NUnit3`, `JUnitXml`. | | +| `TestResult_OutputPath` | Where to save the test-result report (relative path). | | +| `TestResult_OutputEncoding` | Encoding of the test-result file. | | +| `Should_ErrorAction` | Controls if `Should` throws on error. Use `Stop` to throw, or `Continue` to fail at the end. | | +| `Debug_ShowFullErrors` | Show Pester internal stack on errors. (Deprecated – overrides `Output.StackTraceVerbosity` to `Full`). | | +| `Debug_WriteDebugMessages` | Write debug messages to screen. | | +| `Debug_WriteDebugMessagesFrom` | Filter debug messages by source. Wildcards allowed. | | +| `Debug_ShowNavigationMarkers` | Write paths after every block/test for easy navigation in Visual Studio Code. | | +| `Debug_ReturnRawResultObject` | Returns an unfiltered result object, for development only. | | +| `Output_Verbosity` | Verbosity: `None`, `Normal`, `Detailed`, `Diagnostic`. | | +| `Output_StackTraceVerbosity` | Stacktrace detail: `None`, `FirstLine`, `Filtered`, `Full`. | | +| `Output_CIFormat` | CI format of error output: `None`, `Auto`, `AzureDevops`, `GithubActions`. | | +| `Output_CILogLevel` | CI log level: `Error` or `Warning`. | | +| `Output_RenderMode` | How to render console output: `Auto`, `Ansi`, `ConsoleColor`, `Plaintext`. | | +| `TestDrive_Enabled` | Enable `TestDrive`. | | +| `TestRegistry_Enabled` | Enable `TestRegistry`. | | + ### Outputs diff --git a/action.yml b/action.yml index 5177efd4..7acefdb2 100644 --- a/action.yml +++ b/action.yml @@ -12,10 +12,193 @@ inputs: Settings: description: The type of tests to run. Can be either 'Module' or 'SourceCode'. required: true - CodeCoveragePercentTarget: - description: The target code coverage percentage. This is used to determine if the code coverage meets the specified threshold. + StepSummary_Mode: + description: | + Controls which tests to show in the GitHub step summary. Allows "Full" (show all tests), "Failed" (only failed tests), or "None" (disable step summary). + required: false + default: 'Failed' + StepSummary_ShowTestOverview: + description: | + Controls whether to show the test overview table in the GitHub step summary. + required: false + default: 'false' + StepSummary_ShowConfiguration: + description: | + Controls whether to show the configuration details in the GitHub step summary. + required: false + default: 'false' + Run_Path: + description: | + Directories to be searched for tests, paths directly to test files, or combination of both. + required: false + Run_ExcludePath: + description: | + Directories or files to be excluded from the run. + required: false + Run_ScriptBlock: + description: | + ScriptBlocks containing tests to be executed. + required: false + Run_Container: + description: | + ContainerInfo objects containing tests to be executed. + required: false + Run_TestExtension: + description: | + Filter used to identify test files. + required: false + Run_Exit: + description: | + Exit with non-zero exit code when the test run fails. Exit code is always set to `$LASTEXITCODE` even when this option is `$false`. + When used together with Throw, throwing an exception is preferred. + required: false + Run_Throw: + description: | + Throw an exception when test run fails. When used together with Exit, throwing an exception is preferred. + required: false + Run_SkipRun: + description: | + Runs the discovery phase but skips run. Use it with PassThru to get object populated with all tests. + required: false + Run_SkipRemainingOnFailure: + description: | + Skips remaining tests after failure for selected scope, options are None, Run, Container and Block. + required: false + Filter_Tag: + description: | + Tags of Describe, Context or It to be run. + required: false + Filter_ExcludeTag: + description: | + Tags of Describe, Context or It to be excluded from the run. + required: false + Filter_Line: + description: | + Filter by file and scriptblock start line, useful to run parsed tests programmatically to avoid problems with expanded names. + Example: 'C:\tests\file1.Tests.ps1:37' + required: false + Filter_ExcludeLine: + description: | + Exclude by file and scriptblock start line, takes precedence over Line. + required: false + Filter_FullName: + description: | + Full name of test with -like wildcards, joined by dot. Example: '*.describe Get-Item.test1' + required: false + CodeCoverage_Enabled: + description: | + Enable CodeCoverage. + required: false + CodeCoverage_OutputFormat: + description: | + Format to use for code coverage report. Possible values: JaCoCo, CoverageGutters, Cobertura + required: false + CodeCoverage_OutputPath: + description: | + Path relative to the current directory where code coverage report is saved. + required: false + CodeCoverage_OutputEncoding: + description: | + Encoding of the output file. + required: false + CodeCoverage_Path: + description: | + Directories or files to be used for code coverage, by default the Path(s) from general settings are used, unless overridden here. + required: false + CodeCoverage_ExcludeTests: + description: | + Exclude tests from code coverage. This uses the TestFilter from general configuration. + required: false + CodeCoverage_RecursePaths: + description: | + Will recurse through directories in the Path option. + required: false + CodeCoverage_CoveragePercentTarget: + description: | + Target percent of code coverage that you want to achieve. + required: false + CodeCoverage_UseBreakpoints: + description: | + EXPERIMENTAL: When false, use Profiler based tracer to do CodeCoverage instead of using breakpoints. + required: false + CodeCoverage_SingleHitBreakpoints: + description: | + Remove breakpoint when it is hit. + required: false + TestResult_Enabled: + description: | + Enable TestResult. + required: false + TestResult_OutputFormat: + description: | + Format to use for test result report. Possible values: NUnitXml, NUnit2.5, NUnit3 or JUnitXml + required: false + TestResult_OutputPath: + description: | + Path relative to the current directory where test result report is saved. + required: false + TestResult_OutputEncoding: + description: | + Encoding of the output file. + required: false + TestResult_TestSuiteName: + description: | + Set the name assigned to the root 'test-suite' element. + required: false + Should_ErrorAction: + description: | + Controls if Should throws on error. Use 'Stop' to throw on error, or 'Continue' to fail at the end of the test. + required: false + Debug_ShowFullErrors: + description: | + Show full errors including Pester internal stack. This property is deprecated, and if set to true it will override Output.StackTraceVerbosity to 'Full'. + required: false + Debug_WriteDebugMessages: + description: | + Write Debug messages to screen. + required: false + Debug_WriteDebugMessagesFrom: + description: | + Write Debug messages from a given source, WriteDebugMessages must be set to true for this to work. + You can use like wildcards to get messages from multiple sources, as well as * to get everything. + required: false + Debug_ShowNavigationMarkers: + description: | + Write paths after every block and test, for easy navigation in VSCode. + required: false + Debug_ReturnRawResultObject: + description: | + Returns unfiltered result object, this is for development only. Do not rely on this object for additional properties, + non-public properties will be renamed without previous notice. + required: false + Output_Verbosity: + description: | + The verbosity of output, options are None, Normal, Detailed and Diagnostic. + required: false + Output_StackTraceVerbosity: + description: | + The verbosity of stacktrace output, options are None, FirstLine, Filtered and Full. + required: false + Output_CIFormat: + description: | + The CI format of error output in build logs, options are None, Auto, AzureDevops and GithubActions. + required: false + Output_CILogLevel: + description: | + The CI log level in build logs, options are Error and Warning. + required: false + Output_RenderMode: + description: | + The mode used to render console output, options are Auto, Ansi, ConsoleColor and Plaintext. + required: false + TestDrive_Enabled: + description: | + Enable TestDrive. + required: false + TestRegistry_Enabled: + description: | + Enable TestRegistry. required: false - default: '0' Debug: description: Enable debug output. required: false @@ -115,7 +298,49 @@ runs: Verbose: ${{ inputs.Verbose }} Version: ${{ inputs.Version }} WorkingDirectory: ${{ inputs.WorkingDirectory }} - TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} - CodeCoverage_CoveragePercentTarget: ${{ inputs.CodeCoveragePercentTarget }} Path: ${{ steps.paths.outputs.TestPath }} + StepSummary_Mode: ${{ inputs.StepSummary_Mode }} + StepSummary_ShowTestOverview: ${{ inputs.StepSummary_ShowTestOverview }} + StepSummary_ShowConfiguration: ${{ inputs. Run_Path: ${{ steps.paths.outputs.CodePath }} + Run_ExcludePath: ${{ inputs.Run_ExcludePath }} + Run_ScriptBlock: ${{ inputs.Run_ScriptBlock }} + Run_Container: ${{ inputs.Run_Container }} + Run_TestExtension: ${{ inputs.Run_TestExtension }} + Run_Exit: ${{ inputs.Run_Exit }} + Run_Throw: ${{ inputs.Run_Throw }} + Run_SkipRun: ${{ inputs.Run_SkipRun }} + Run_SkipRemainingOnFailure: ${{ inputs.Run_SkipRemainingOnFailure }} + Filter_Tag: ${{ inputs.Filter_Tag }} + Filter_ExcludeTag: ${{ inputs.Filter_ExcludeTag }} + Filter_Line: ${{ inputs.Filter_Line }} + Filter_ExcludeLine: ${{ inputs.Filter_ExcludeLine }} + Filter_FullName: ${{ inputs.Filter_FullName }} + CodeCoverage_Enabled: ${{ inputs.CodeCoverage_Enabled }} + CodeCoverage_OutputFormat: ${{ inputs.CodeCoverage_OutputFormat }} + CodeCoverage_OutputPath: ${{ inputs.CodeCoverage_OutputPath }} + CodeCoverage_OutputEncoding: ${{ inputs.CodeCoverage_OutputEncoding }} + CodeCoverage_Path: ${{ inputs.CodeCoverage_Path }} + CodeCoverage_ExcludeTests: ${{ inputs.CodeCoverage_ExcludeTests }} + CodeCoverage_RecursePaths: ${{ inputs.CodeCoverage_RecursePaths }} + CodeCoverage_CoveragePercentTarget: ${{ inputs.CodeCoverage_CoveragePercentTarget }} + CodeCoverage_UseBreakpoints: ${{ inputs.CodeCoverage_UseBreakpoints }} + CodeCoverage_SingleHitBreakpoints: ${{ inputs.CodeCoverage_SingleHitBreakpoints }} + TestResult_Enabled: ${{ inputs.TestResult_Enabled }} + TestResult_OutputFormat: ${{ inputs.TestResult_OutputFormat }} + TestResult_OutputPath: ${{ inputs.TestResult_OutputPath }} + TestResult_OutputEncoding: ${{ inputs.TestResult_OutputEncoding }} + TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} + Should_ErrorAction: ${{ inputs.Should_ErrorAction }} + Debug_ShowFullErrors: ${{ inputs.Debug_ShowFullErrors }} + Debug_WriteDebugMessages: ${{ inputs.Debug_WriteDebugMessages }} + Debug_WriteDebugMessagesFrom: ${{ inputs.Debug_WriteDebugMessagesFrom }} + Debug_ShowNavigationMarkers: ${{ inputs.Debug_ShowNavigationMarkers }} + Debug_ReturnRawResultObject: ${{ inputs.Debug_ReturnRawResultObject }} + Output_Verbosity: ${{ inputs.Output_Verbosity }} + Output_StackTraceVerbosity: ${{ inputs.Output_StackTraceVerbosity }} + Output_CIFormat: ${{ inputs.Output_CIFormat }} + Output_CILogLevel: ${{ inputs.Output_CILogLevel }} + Output_RenderMode: ${{ inputs.Output_RenderMode }} + TestDrive_Enabled: ${{ inputs.TestDrive_Enabled }} + TestRegistry_Enabled: ${{ inputs.TestRegistry_Enabled }} From 25bb734a961e5c15edae688e92ed529914edfa61 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 16:06:49 +0100 Subject: [PATCH 164/172] Fix typo in action.yml for StepSummary_ShowConfiguration input --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7acefdb2..772ada17 100644 --- a/action.yml +++ b/action.yml @@ -301,7 +301,7 @@ runs: Path: ${{ steps.paths.outputs.TestPath }} StepSummary_Mode: ${{ inputs.StepSummary_Mode }} StepSummary_ShowTestOverview: ${{ inputs.StepSummary_ShowTestOverview }} - StepSummary_ShowConfiguration: ${{ inputs. + StepSummary_ShowConfiguration: ${{ inputs.StepSummary_ShowConfiguration }} Run_Path: ${{ steps.paths.outputs.CodePath }} Run_ExcludePath: ${{ inputs.Run_ExcludePath }} Run_ScriptBlock: ${{ inputs.Run_ScriptBlock }} From 2af630013386abd9c5df40b505fc568f15c5e9f6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 16:08:40 +0100 Subject: [PATCH 165/172] Update CodeCoverage_CoveragePercentTarget in workflows and action.yml --- .github/workflows/Action-Test-Src-WithManifest.yml | 1 - .github/workflows/Action-Test-outputs.yml | 1 + action.yml | 3 --- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/Action-Test-Src-WithManifest.yml b/.github/workflows/Action-Test-Src-WithManifest.yml index 59b6a41b..53dc398a 100644 --- a/.github/workflows/Action-Test-Src-WithManifest.yml +++ b/.github/workflows/Action-Test-Src-WithManifest.yml @@ -33,4 +33,3 @@ jobs: Name: PSModuleTest WorkingDirectory: tests/srcWithManifestTestRepo Settings: SourceCode - CodeCoverage_CoveragePercentTarget: 80 diff --git a/.github/workflows/Action-Test-outputs.yml b/.github/workflows/Action-Test-outputs.yml index a13d2beb..59afbb3c 100644 --- a/.github/workflows/Action-Test-outputs.yml +++ b/.github/workflows/Action-Test-outputs.yml @@ -33,3 +33,4 @@ jobs: Name: PSModuleTest WorkingDirectory: tests/outputTestRepo Settings: Module + CodeCoverage_CoveragePercentTarget: 80 diff --git a/action.yml b/action.yml index 772ada17..f66b6573 100644 --- a/action.yml +++ b/action.yml @@ -16,17 +16,14 @@ inputs: description: | Controls which tests to show in the GitHub step summary. Allows "Full" (show all tests), "Failed" (only failed tests), or "None" (disable step summary). required: false - default: 'Failed' StepSummary_ShowTestOverview: description: | Controls whether to show the test overview table in the GitHub step summary. required: false - default: 'false' StepSummary_ShowConfiguration: description: | Controls whether to show the configuration details in the GitHub step summary. required: false - default: 'false' Run_Path: description: | Directories to be searched for tests, paths directly to test files, or combination of both. From ee510fdc16ab79302927332ad14371e5254ff050 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 16:11:09 +0100 Subject: [PATCH 166/172] Add CoveragePercentTarget to CodeCoverage configuration in Module.Configuration.ps1 --- scripts/tests/Module/Module.Configuration.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index e21afb2e..5d91237a 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -3,9 +3,10 @@ Enabled = $true } CodeCoverage = @{ - Enabled = $true - OutputFormat = 'JaCoCo' - OutputEncoding = 'UTF8' + Enabled = $true + OutputFormat = 'JaCoCo' + OutputEncoding = 'UTF8' + CoveragePercentTarget = 80 } Output = @{ Verbosity = 'Detailed' From 0790471439be8e3cd70d60c0dcadde675056ed8e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 16:11:27 +0100 Subject: [PATCH 167/172] Update CodeCoverage_CoveragePercentTarget to 30 in Action-Test-outputs.yml --- .github/workflows/Action-Test-outputs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test-outputs.yml b/.github/workflows/Action-Test-outputs.yml index 59afbb3c..b47e5116 100644 --- a/.github/workflows/Action-Test-outputs.yml +++ b/.github/workflows/Action-Test-outputs.yml @@ -33,4 +33,4 @@ jobs: Name: PSModuleTest WorkingDirectory: tests/outputTestRepo Settings: Module - CodeCoverage_CoveragePercentTarget: 80 + CodeCoverage_CoveragePercentTarget: 30 From 257424646f0da131eb73cb80a0e317597f817af1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 18:00:57 +0100 Subject: [PATCH 168/172] Update TestResult_TestSuiteName format in action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f66b6573..df080d23 100644 --- a/action.yml +++ b/action.yml @@ -327,7 +327,7 @@ runs: TestResult_OutputFormat: ${{ inputs.TestResult_OutputFormat }} TestResult_OutputPath: ${{ inputs.TestResult_OutputPath }} TestResult_OutputEncoding: ${{ inputs.TestResult_OutputEncoding }} - TestResult_TestSuiteName: ${{ inputs.Settings }}-${{ runner.os }} + TestResult_TestSuiteName: Test-${{ inputs.Settings }}-${{ runner.os }} Should_ErrorAction: ${{ inputs.Should_ErrorAction }} Debug_ShowFullErrors: ${{ inputs.Debug_ShowFullErrors }} Debug_WriteDebugMessages: ${{ inputs.Debug_WriteDebugMessages }} From c54aff57901c57b4a4319f8a23d30a0877bc5784 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Mar 2025 18:01:41 +0100 Subject: [PATCH 169/172] Update TestResult_TestSuiteName format in action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index df080d23..74936e66 100644 --- a/action.yml +++ b/action.yml @@ -327,7 +327,7 @@ runs: TestResult_OutputFormat: ${{ inputs.TestResult_OutputFormat }} TestResult_OutputPath: ${{ inputs.TestResult_OutputPath }} TestResult_OutputEncoding: ${{ inputs.TestResult_OutputEncoding }} - TestResult_TestSuiteName: Test-${{ inputs.Settings }}-${{ runner.os }} + TestResult_TestSuiteName: PSModuleTest-${{ inputs.Settings }}-${{ runner.os }} Should_ErrorAction: ${{ inputs.Should_ErrorAction }} Debug_ShowFullErrors: ${{ inputs.Debug_ShowFullErrors }} Debug_WriteDebugMessages: ${{ inputs.Debug_WriteDebugMessages }} From 305abf70e63bcaa97ae89de9d843400430a14116 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 17 Apr 2025 17:14:08 +0200 Subject: [PATCH 170/172] Refactor README.md for clarity and detail on testing framework and outputs --- README.md | 76 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index b8f4c58a..d2a75295 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,34 @@ # Test-PSModule -Test PowerShell modules with Pester and PSScriptAnalyzer. +Tests PowerShell module repos using PSModule framework rules. -This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. +This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the +[Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. ## Specifications and practices Test-PSModule enables: -- [Test-Driven Development](https://testdriven.io/test-driven-development/) using [Pester](https://pester.dev) and [PSScriptAnalyzer](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules) +- [Test-Driven Development](https://testdriven.io/test-driven-development/) using [Pester](https://pester.dev) via [Invoke-Pester](https://github.com/PSModule/Invoke-Pester). ## How it works -The action runs the following the Pester test framework: -- [PSScriptAnalyzer tests](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/rules/readme?view=ps-modules) -- [PSModule framework tests](#psmodule-tests) -- If `Settings` is set to `Module`: - - The module manifest is tested using [Test-ModuleManifest](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/test-modulemanifest). - - The module is imported. - - Custom module tests from the `tests` directory in the module repository are run. - - CodeCoverage is calculated. -- If `Settings` is set to `SourceCode`: - - The source code is tested with: - - `PSScriptAnalyzer` for best practices, using custom settings. - - `PSModule.SourceCode` for other PSModule standards. -- The action returns a `passed` output that is `true` if all tests pass, else `false`. -- The following reports are calculated and uploaded as artifacts: - - Test suite results. - - Code coverage results. +- The action runs test on the module repository based on `Settings`: + - `SourceCode` - Tests source code style and standards based on PSModule framework rules. + - `Module` - Tests the module build module style and standards based on PSModule framework rules. + - The module is imported in its own context to avoid conflicts with other modules. +- The action returns the test results as action [outputs](#outputs). +- The following reports are calculated and uploaded as artifacts. This is done to support the action being run in matrix jobs. + - Test suite results. In [Process-PSModule](https://github.com/PSModule/Process-PSModule) this is evaluated in a later job by [Get-PesterTestResults](https://github.com/PSModule/Get-PesterTestResults) + - Code coverage results. In [Process-PSModule](https://github.com/PSModule/Process-PSModule) this is evaluated in a later job by [Get-PesterCodeCoverage](https://github.com/PSModule/Get-PesterCodeCoverage) The action fails if any of the tests fail or it fails to run the tests. This is mitigated by the `continue-on-error` option in the workflow. ## How to use it +It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. + To use the action, create a new file in the `.github/workflows` directory of the module repository and add the following content.
Workflow suggestion - before module is built @@ -146,23 +141,42 @@ jobs: | `TestDrive_Enabled` | Enable `TestDrive`. | | | `TestRegistry_Enabled` | Enable `TestRegistry`. | | - ### Outputs -| Name | Description | Possible values | -| ---- | ----------- | --------------- | -| `passed` | If the tests passed. | `true`, `false` | +| Output | Description | +|---------------|--------------------------------------| +| `Outcome` | Outcome of the test run. | +| `Conclusion` | Conclusion status of test execution. | +| `Executed` | Indicates if tests were executed. | +| `Result` | Overall result (`Passed`, `Failed`). | +| `FailedCount` | Number of failed tests. | +| `PassedCount` | Number of passed tests. | +| `TotalCount` | Total tests executed. | ## PSModule tests -The [PSModule framework tests](https://github.com/PSModule/Test-PSModule/blob/main/scripts/tests/PSModule/PSModule.Tests.ps1) verifies the following coding practices that the framework enforces: +### SourceCode tests + +The [PSModule - SourceCode tests](./scripts/tests/SourceCode/PSModule/PSModule.Tests.ps1) verifies the following coding practices that the framework enforces: + +| ID | Category | Description | +|---------------------|---------------------|--------------------------------------------------------------------------------------------| +| NumberOfProcessors | General | Should use `[System.Environment]::ProcessorCount` instead of `$env:NUMBER_OF_PROCESSORS`. | +| Verbose | General | Should not contain `-Verbose` unless it is explicitly disabled with `:$false`. | +| OutNull | General | Should use `$null = ...` instead of piping output to `Out-Null`. | +| NoTernary | General | Should not use ternary operations to maintain compatibility with PowerShell 5.1 and below. | +| LowercaseKeywords | General | All PowerShell keywords should be written in lowercase. | +| FunctionCount | Functions (Generic) | Each script file should contain exactly one function or filter. | +| FunctionName | Functions (Generic) | Script filenames should match the name of the function or filter they contain. | +| CmdletBinding | Functions (Generic) | Functions should include the `[CmdletBinding()]` attribute. | +| ParamBlock | Functions (Generic) | Functions should have a parameter block (`param()`). | +| FunctionTest | Functions (Public) | All public functions/filters should have corresponding tests. | -- Script filename and function/filter name should match. +### Module tests -## Tools +The [PSModule - Module tests](./scripts/tests/Module/PSModule/PSModule.Tests.ps1) verifies the following coding practices that the framework enforces: -- Pester | [Docs](https://www.pester.dev) | [GitHub](https://github.com/Pester/Pester) | [PS Gallery](https://www.powershellgallery.com/packages/Pester/) -- PSScriptAnalyzer [Docs](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules) | [GitHub](https://github.com/PowerShell/PSScriptAnalyzer) | [PS Gallery](https://www.powershellgallery.com/packages/PSScriptAnalyzer/) -- PSResourceGet | [Docs](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.psresourceget/?view=powershellget-3.x) | [GitHub](https://github.com/PowerShell/PSResourceGet) | [PS Gallery](https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet/) -- [Test-ModuleManifest | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/test-modulemanifest) -- [PowerShellGet | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/PowerShellGet/test-scriptfileinfo) +| Name | Description | +| ------ | ----------- | +| Module Manifest exists | Verifies that a module manifest file is present. | +| Module Manifest is valid | Verifies that the module manifest file is valid. | From 7b0d5ff965315abaa6a7fe121cca8cc8f95d4180 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 17 Apr 2025 17:19:01 +0200 Subject: [PATCH 171/172] Update README.md to include additional configuration options for test execution and reporting --- README.md | 86 +++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index d2a75295..cea76fcd 100644 --- a/README.md +++ b/README.md @@ -97,49 +97,49 @@ jobs: | `Version` | Specifies the version of the GitHub module to be installed. The value must be an exact version. | `false` | | | `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` | | `WorkingDirectory` | The working directory to use for the action. This is the root folder where tests and outputs are expected. | `false` | `'.'` | -| `StepSummary_Mode` | Controls which tests to show in the GitHub step summary. Allows "Full" (all tests), "Failed" (only failed tests), or "None" (disable step summary). | `Failed` | -| `StepSummary_ShowTestOverview` | Controls whether to show the test overview table in the GitHub step summary. | `false` | -| `StepSummary_ShowConfiguration` | Controls whether to show the configuration details in the GitHub step summary. | `false` | -| `Run_ExcludePath` | Directories/files to exclude from the run. | | -| `Run_ScriptBlock` | ScriptBlocks containing tests to be executed. | | -| `Run_Container` | ContainerInfo objects containing tests to be executed. | | -| `Run_TestExtension` | Filter used to identify test files (e.g. `.Tests.ps1`). | | -| `Run_Exit` | Whether to exit with a non-zero exit code on failure. | | -| `Run_Throw` | Whether to throw an exception on test failure. | | -| `Run_SkipRun` | Discovery only, skip actual test run. | | -| `Run_SkipRemainingOnFailure` | Skips remaining tests after the first failure. Options: `None`, `Run`, `Container`, `Block`. | | -| `Filter_Tag` | Tags of Describe/Context/It blocks to run. | | -| `Filter_ExcludeTag` | Tags of Describe/Context/It blocks to exclude. | | -| `Filter_Line` | Filter by file + scriptblock start line (e.g. `C:\tests\file1.Tests.ps1:37`). | | -| `Filter_ExcludeLine` | Exclude by file + scriptblock start line. Precedence over `Filter_Line`. | | -| `Filter_FullName` | Full name of a test with wildcards, joined by dot. E.g. `*.describe Get-Item.test1` | | -| `CodeCoverage_Enabled` | Enable code coverage. | | -| `CodeCoverage_OutputFormat` | Format for the coverage report. Possible values: `JaCoCo`, `CoverageGutters`, `Cobertura`. | | -| `CodeCoverage_OutputPath` | Where to save the code coverage report (relative to the current dir). | | -| `CodeCoverage_OutputEncoding` | Encoding of the coverage file. | | -| `CodeCoverage_Path` | Files/directories to measure coverage on (by default, reuses `Path` from the general settings). | | -| `CodeCoverage_ExcludeTests` | Exclude tests themselves from coverage. | | -| `CodeCoverage_RecursePaths` | Recurse through coverage directories. | | -| `CodeCoverage_CoveragePercentTarget` | Desired minimum coverage percentage. | | -| `CodeCoverage_UseBreakpoints` | **Experimental**: When `false`, use a Profiler-based tracer instead of breakpoints. | | -| `CodeCoverage_SingleHitBreakpoints` | Remove breakpoints after first hit. | | -| `TestResult_Enabled` | Enable test-result output (e.g. NUnitXml, JUnitXml). | | -| `TestResult_OutputFormat` | Possible values: `NUnitXml`, `NUnit2.5`, `NUnit3`, `JUnitXml`. | | -| `TestResult_OutputPath` | Where to save the test-result report (relative path). | | -| `TestResult_OutputEncoding` | Encoding of the test-result file. | | -| `Should_ErrorAction` | Controls if `Should` throws on error. Use `Stop` to throw, or `Continue` to fail at the end. | | -| `Debug_ShowFullErrors` | Show Pester internal stack on errors. (Deprecated – overrides `Output.StackTraceVerbosity` to `Full`). | | -| `Debug_WriteDebugMessages` | Write debug messages to screen. | | -| `Debug_WriteDebugMessagesFrom` | Filter debug messages by source. Wildcards allowed. | | -| `Debug_ShowNavigationMarkers` | Write paths after every block/test for easy navigation in Visual Studio Code. | | -| `Debug_ReturnRawResultObject` | Returns an unfiltered result object, for development only. | | -| `Output_Verbosity` | Verbosity: `None`, `Normal`, `Detailed`, `Diagnostic`. | | -| `Output_StackTraceVerbosity` | Stacktrace detail: `None`, `FirstLine`, `Filtered`, `Full`. | | -| `Output_CIFormat` | CI format of error output: `None`, `Auto`, `AzureDevops`, `GithubActions`. | | -| `Output_CILogLevel` | CI log level: `Error` or `Warning`. | | -| `Output_RenderMode` | How to render console output: `Auto`, `Ansi`, `ConsoleColor`, `Plaintext`. | | -| `TestDrive_Enabled` | Enable `TestDrive`. | | -| `TestRegistry_Enabled` | Enable `TestRegistry`. | | +| `StepSummary_Mode` | Controls which tests to show in the GitHub step summary. Allows "Full" (all tests), "Failed" (only failed tests), or "None" (disable step summary). | `false` | `Failed` | +| `StepSummary_ShowTestOverview` | Controls whether to show the test overview table in the GitHub step summary. | `false` | `false` | +| `StepSummary_ShowConfiguration` | Controls whether to show the configuration details in the GitHub step summary. | `false` | `false` | +| `Run_ExcludePath` | Directories/files to exclude from the run. | `false` | | +| `Run_ScriptBlock` | ScriptBlocks containing tests to be executed. | `false` | | +| `Run_Container` | ContainerInfo objects containing tests to be executed. | `false` | | +| `Run_TestExtension` | Filter used to identify test files (e.g. `.Tests.ps1`). | `false` | | +| `Run_Exit` | Whether to exit with a non-zero exit code on failure. | `false` | | +| `Run_Throw` | Whether to throw an exception on test failure. | `false` | | +| `Run_SkipRun` | Discovery only, skip actual test run. | `false` | | +| `Run_SkipRemainingOnFailure` | Skips remaining tests after the first failure. Options: `None`, `Run`, `Container`, `Block`. | `false` | | +| `Filter_Tag` | Tags of Describe/Context/It blocks to run. | `false` | | +| `Filter_ExcludeTag` | Tags of Describe/Context/It blocks to exclude. | `false` | | +| `Filter_Line` | Filter by file + scriptblock start line (e.g. `C:\tests\file1.Tests.ps1:37`). | `false` | | +| `Filter_ExcludeLine` | Exclude by file + scriptblock start line. Precedence over `Filter_Line`. | `false` | | +| `Filter_FullName` | Full name of a test with wildcards, joined by dot. E.g. `*.describe Get-Item.test1` | `false` | | +| `CodeCoverage_Enabled` | Enable code coverage. | `false` | | +| `CodeCoverage_OutputFormat` | Format for the coverage report. Possible values: `JaCoCo`, `CoverageGutters`, `Cobertura`. | `false` | | +| `CodeCoverage_OutputPath` | Where to save the code coverage report (relative to the current dir). | `false` | | +| `CodeCoverage_OutputEncoding` | Encoding of the coverage file. | `false` | | +| `CodeCoverage_Path` | Files/directories to measure coverage on (by default, reuses `Path` from the general settings). | `false` | | +| `CodeCoverage_ExcludeTests` | Exclude tests themselves from coverage. | `false` | | +| `CodeCoverage_RecursePaths` | Recurse through coverage directories. | `false` | | +| `CodeCoverage_CoveragePercentTarget` | Desired minimum coverage percentage. | `false` | | +| `CodeCoverage_UseBreakpoints` | **Experimental**: When `false`, use a Profiler-based tracer instead of breakpoints. | `false` | | +| `CodeCoverage_SingleHitBreakpoints` | Remove breakpoints after first hit. | `false` | | +| `TestResult_Enabled` | Enable test-result output (e.g. NUnitXml, JUnitXml). | `false` | | +| `TestResult_OutputFormat` | Possible values: `NUnitXml`, `NUnit2.5`, `NUnit3`, `JUnitXml`. | `false` | | +| `TestResult_OutputPath` | Where to save the test-result report (relative path). | `false` | | +| `TestResult_OutputEncoding` | Encoding of the test-result file. | `false` | | +| `Should_ErrorAction` | Controls if `Should` throws on error. Use `Stop` to throw, or `Continue` to fail at the end. | `false` | | +| `Debug_ShowFullErrors` | Show Pester internal stack on errors. (Deprecated – overrides `Output.StackTraceVerbosity` to `Full`). | `false` | | +| `Debug_WriteDebugMessages` | Write debug messages to screen. | `false` | | +| `Debug_WriteDebugMessagesFrom` | Filter debug messages by source. Wildcards allowed. | `false` | | +| `Debug_ShowNavigationMarkers` | Write paths after every block/test for easy navigation in Visual Studio Code. | `false` | | +| `Debug_ReturnRawResultObject` | Returns an unfiltered result object, for development only. | `false` | | +| `Output_Verbosity` | Verbosity: `None`, `Normal`, `Detailed`, `Diagnostic`. | `false` | | +| `Output_StackTraceVerbosity` | Stacktrace detail: `None`, `FirstLine`, `Filtered`, `Full`. | `false` | | +| `Output_CIFormat` | CI format of error output: `None`, `Auto`, `AzureDevops`, `GithubActions`. | `false` | | +| `Output_CILogLevel` | CI log level: `Error` or `Warning`. | `false` | | +| `Output_RenderMode` | How to render console output: `Auto`, `Ansi`, `ConsoleColor`, `Plaintext`. | `false` | | +| `TestDrive_Enabled` | Enable `TestDrive`. | `false` | | +| `TestRegistry_Enabled` | Enable `TestRegistry`. | `false` | | ### Outputs From 466446efb3b4515dbdd635d99ac1d8c8d24388b2 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 17 Apr 2025 17:37:58 +0200 Subject: [PATCH 172/172] Update README.md outputs section and simplify Module.Configuration.ps1 --- README.md | 23 +++++++++++-------- scripts/tests/Module/Module.Configuration.ps1 | 10 ++------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index cea76fcd..8a9f1ba5 100644 --- a/README.md +++ b/README.md @@ -143,15 +143,20 @@ jobs: ### Outputs -| Output | Description | -|---------------|--------------------------------------| -| `Outcome` | Outcome of the test run. | -| `Conclusion` | Conclusion status of test execution. | -| `Executed` | Indicates if tests were executed. | -| `Result` | Overall result (`Passed`, `Failed`). | -| `FailedCount` | Number of failed tests. | -| `PassedCount` | Number of passed tests. | -| `TotalCount` | Total tests executed. | +| Output | Description | +|-------------------------|--------------------------------------| +| `Outcome` | Outcome of the test run. | +| `Conclusion` | Conclusion status of test execution. | +| `Executed` | Indicates if tests were executed. | +| `Result` | Overall result (`Passed`, `Failed`). | +| `FailedCount` | Number of failed tests. | +| `FailedBlocksCount` | Number of failed blocks. | +| `FailedContainersCount` | Number of failed containers. | +| `PassedCount` | Number of passed tests. | +| `SkippedCount` | Number of skipped tests. | +| `InconclusiveCount` | Number of inconclusive tests. | +| `NotRunCount` | Number of tests not run. | +| `TotalCount` | Total tests executed. | ## PSModule tests diff --git a/scripts/tests/Module/Module.Configuration.ps1 b/scripts/tests/Module/Module.Configuration.ps1 index 5d91237a..e76f767f 100644 --- a/scripts/tests/Module/Module.Configuration.ps1 +++ b/scripts/tests/Module/Module.Configuration.ps1 @@ -1,14 +1,8 @@ @{ - TestResult = @{ + TestResult = @{ Enabled = $true } - CodeCoverage = @{ - Enabled = $true - OutputFormat = 'JaCoCo' - OutputEncoding = 'UTF8' - CoveragePercentTarget = 80 - } - Output = @{ + Output = @{ Verbosity = 'Detailed' } }