Skip to content

🪲 [Fix]: Test results outputs #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/Action-Test-Src-Default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ jobs:

- name: Action-Test
uses: ./
id: action-test
env:
GITHUB_TOKEN: ${{ github.token }}
with:
Name: PSModuleTest
Path: tests/src
TestType: SourceCode

- name: Status
shell: pwsh
run: |
$passed = '${{ steps.action-test.outputs.passed }}'
Write-Host "Passed: [$Passed]"
if ($passed -eq 'False') {
exit 1
}
10 changes: 10 additions & 0 deletions .github/workflows/Action-Test-Src-WithManifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ jobs:

- name: Action-Test
uses: ./
id: action-test
env:
GITHUB_TOKEN: ${{ github.token }}
with:
Name: PSModuleTest
Path: tests/srcWithManifest
TestType: SourceCode

- name: Status
shell: pwsh
run: |
$passed = '${{ steps.action-test.outputs.passed }}'
Write-Host "Passed: [$Passed]"
if ($passed -eq 'False') {
exit 1
}
10 changes: 10 additions & 0 deletions .github/workflows/Action-Test-outputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ jobs:

- name: Action-Test
uses: ./
id: action-test
env:
GITHUB_TOKEN: ${{ github.token }}
with:
Name: PSModuleTest
Path: tests/outputs/modules
TestType: Module

- name: Status
shell: pwsh
run: |
$passed = '${{ steps.action-test.outputs.passed }}'
Write-Host "Passed: [$Passed]"
if ($passed -eq 'False') {
exit 1
}
24 changes: 12 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ inputs:
description: The path to the tests to run.
required: false
default: tests
Shell:
description: The shell to use for running the tests.
required: false
default: pwsh

outputs:
passed:
Expand All @@ -34,21 +30,25 @@ runs:
steps:
- name: Run Test-PSModule
uses: PSModule/GitHub-Script@v1

- name: Run Test-PSModule
shell: pwsh
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 }}
with:
Script: |
# Test-PSModule
$passed = . "${{ github.action_path }}\scripts\main.ps1" -Verbose
"passed=$passed" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
run: |
# Test-PSModule
$passed = . "${{ github.action_path }}\scripts\main.ps1" -Verbose
"passed=$passed" | Out-File -FilePath $env:GITHUB_OUTPUT -Append

Write-Host "Passed: [$passed]"

if (-not $passed) {
exit 1
}
if (-not $passed) {
exit 1
}

- name: Upload test results
uses: actions/upload-artifact@v4
Expand Down
206 changes: 94 additions & 112 deletions scripts/helpers/Test-PSModule.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#REQUIRES -Modules Utilities, PSScriptAnalyzer, Pester

function Test-PSModule {
function Test-PSModule {
<#
.SYNOPSIS
Performs tests on a module.
Expand All @@ -27,156 +25,140 @@ function Test-PSModule {
$testModule = $TestType -eq 'Module'
$moduleTestsPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $TestsPath

#region Get test kit versions
Start-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

Write-Verbose 'Testing with:'
Write-Verbose " PowerShell $($PSVersionTable.PSVersion.ToString())"
Write-Verbose " Pester $($pesterModule.version)"
Write-Verbose " PSScriptAnalyzer $($PSSAModule.version)"
Stop-LogGroup
#endregion

#region Add test - Common - PSScriptAnalyzer
Start-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
Verbose = $true
}
}
Write-Verbose 'ContainerParams:'
Write-Verbose "$($containerParams | ConvertTo-Json)"
$containers += New-PesterContainer @containerParams
Stop-LogGroup
#endregion
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

#region Add test - Common - PSModule
Start-LogGroup 'Add test - Common - PSModule'
$containerParams = @{
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Common.Tests.ps1'
Data = @{
Path = $Path
Verbose = $true
}
Write-Verbose 'Testing with:'
Write-Verbose " PowerShell $($PSVersionTable.PSVersion.ToString())"
Write-Verbose " Pester $($pesterModule.version)"
Write-Verbose " PSScriptAnalyzer $($PSSAModule.version)"
}
Write-Verbose 'ContainerParams:'
Write-Verbose "$($containerParams | ConvertTo-Json)"
$containers += New-PesterContainer @containerParams
Stop-LogGroup
#endregion

#region Add test - Module - PSModule
if ($testModule) {
Start-LogGroup 'Add test - Module - PSModule'
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 -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Module.Tests.ps1'
Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1'
Data = @{
Path = $Path
Verbose = $true
Path = $Path
SettingsFilePath = $settingsFilePath
Verbose = $true
}
}
Write-Verbose 'ContainerParams:'
Write-Verbose "$($containerParams | ConvertTo-Json)"
$containers += New-PesterContainer @containerParams
Stop-LogGroup
}
#endregion

#region Add test - SourceCode - PSModule
if ($testSourceCode) {
Start-LogGroup 'Add test - SourceCode - PSModule'
LogGroup 'Add test - Common - PSModule' {
$containerParams = @{
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\SourceCode.Tests.ps1'
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Common.Tests.ps1'
Data = @{
Path = $Path
TestsPath = $moduleTestsPath
Verbose = $true
Path = $Path
Verbose = $true
}
}
Write-Verbose 'ContainerParams:'
Write-Verbose "$($containerParams | ConvertTo-Json)"
$containers += New-PesterContainer @containerParams
Stop-LogGroup
}
#endregion

#region Add test - Module - $moduleName
if ($testModule) {
if (Test-Path -Path $moduleTestsPath) {
Start-LogGroup "Add test - Module - $moduleName"
LogGroup 'Add test - Module - PSModule' {
$containerParams = @{
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Module.Tests.ps1'
Data = @{
Path = $Path
Verbose = $true
}
}
Write-Verbose 'ContainerParams:'
Write-Verbose "$($containerParams | ConvertTo-Json)"
$containers += New-PesterContainer @containerParams
}
}

if ($testSourceCode) {
LogGroup 'Add test - SourceCode - PSModule' {
$containerParams = @{
Path = $moduleTestsPath
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\SourceCode.Tests.ps1'
Data = @{
Path = $Path
Path = $Path
TestsPath = $moduleTestsPath
Verbose = $true
}
}
Write-Verbose 'ContainerParams:'
Write-Verbose "$($containerParams | ConvertTo-Json)"
$containers += New-PesterContainer @containerParams
Stop-LogGroup
}
}

if ($testModule) {
if (Test-Path -Path $moduleTestsPath) {
LogGroup "Add test - Module - $moduleName" {
$containerParams = @{
Path = $moduleTestsPath
Data = @{
Path = $Path
}
}
Write-Verbose 'ContainerParams:'
Write-Verbose "$($containerParams | ConvertTo-Json)"
$containers += New-PesterContainer @containerParams
}
} else {
Write-Warning "⚠️ No tests found - [$moduleTestsPath]"
}
}
#endregion

#region Import module
if ((Test-Path -Path $moduleTestsPath) -and $testModule) {
Start-LogGroup 'Install module dependencies'
$moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1"
Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath
Stop-LogGroup
LogGroup 'Install module dependencies' {
$moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1"
Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath
}

Start-LogGroup "Importing module: $moduleName"
Add-PSModulePath -Path (Split-Path $Path -Parent)
Get-Module -Name $moduleName -ListAvailable | Remove-Module -Force
Import-Module -Name $moduleName -Force -RequiredVersion '999.0.0' -Global
Stop-LogGroup
LogGroup "Importing module: $moduleName" {
Add-PSModulePath -Path (Split-Path $Path -Parent)
Get-Module -Name $moduleName -ListAvailable | Remove-Module -Force
Import-Module -Name $moduleName -Force -RequiredVersion '999.0.0' -Global
}
}
#endregion

#region Pester config
Start-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 = 'None'
Verbosity = 'Detailed'
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 = 'None'
Verbosity = 'Detailed'
}
}
}
Write-Verbose 'PesterParams:'
Write-Verbose "$($pesterParams | ConvertTo-Json -Depth 4 -WarningAction SilentlyContinue)"
}
Write-Verbose 'PesterParams:'
Write-Verbose "$($pesterParams | ConvertTo-Json -Depth 4 -WarningAction SilentlyContinue)"
Stop-LogGroup
#endregion

#region Run tests
$verbosepref = $VerbosePreference
Expand Down
Loading