Skip to content

Commit 03e745f

Browse files
committed
fix(#260): enhance Nova module validation commands and logging
- Introduced new functions for command generation and execution - Improved error handling for validation command failures - Updated logging to capture command execution details
1 parent 2a8fba7 commit 03e745f

2 files changed

Lines changed: 74 additions & 37 deletions

File tree

scripts/build/ci/Invoke-NovaModuleToolsCI.ps1

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,58 @@ function Copy-NovaModuleToolsArtifactIfPresent {
1616
}
1717
}
1818

19+
function ConvertTo-NovaSingleQuotedPowerShellLiteral {
20+
param(
21+
[Parameter(Mandatory)][string]$Value
22+
)
23+
24+
return "'$($Value.Replace("'", "''") )'"
25+
}
26+
27+
function Get-NovaModuleToolsValidationCommand {
28+
param(
29+
[Parameter(Mandatory)][string]$BuiltModulePath,
30+
[Parameter(Mandatory)][string]$CommandName,
31+
[string[]]$ExcludeTag = @()
32+
)
33+
34+
$commandLine = $CommandName
35+
if (@($ExcludeTag).Count -gt 0) {
36+
$excludeTagLiteral = @($ExcludeTag | ForEach-Object {ConvertTo-NovaSingleQuotedPowerShellLiteral -Value ([string]$_)}) -join ', '
37+
$commandLine += " -ExcludeTagFilter @($excludeTagLiteral)"
38+
}
39+
40+
return "Import-Module $( ConvertTo-NovaSingleQuotedPowerShellLiteral -Value $BuiltModulePath ) -Force -ErrorAction Stop; $commandLine"
41+
}
42+
43+
function Invoke-NovaModuleToolsFreshValidationCommand {
44+
param(
45+
[Parameter(Mandatory)][string]$Command
46+
)
47+
48+
& pwsh -NoLogo -NoProfile -Command $Command
49+
if ($LASTEXITCODE -ne 0) {
50+
throw "Validation command failed: $Command"
51+
}
52+
}
53+
1954
$repoRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..' '..' '..')).Path
2055
Set-Location $repoRoot
2156
New-Item -ItemType Directory -Path $OutputDirectory -Force | Out-Null
2257

2358
Import-Module NovaModuleTools -ErrorAction Stop
2459

25-
Invoke-NovaBuild
26-
27-
$projectInfo = Get-NovaProjectInfo
28-
$builtModulePath = $projectInfo.OutputModuleDir
29-
Remove-Module $projectInfo.ProjectName -ErrorAction SilentlyContinue
30-
Import-Module $builtModulePath -Force
3160
$projectInfo = Get-NovaProjectInfo
61+
Invoke-NovaBuild
62+
$builtModulePath = Join-Path $projectInfo.OutputModuleDir "$( $projectInfo.ProjectName ).psd1"
3263

3364
$novaModuleToolsTestFailed = $false
3465
try {
35-
if (@($ExcludeTag).Count -gt 0) {
36-
Invoke-NovaTest -ExcludeTagFilter $ExcludeTag
37-
Test-NovaBuild -ExcludeTagFilter $ExcludeTag
38-
} else {
39-
Invoke-NovaTest
40-
Test-NovaBuild
41-
}
66+
$unitTestCommand = Get-NovaModuleToolsValidationCommand -BuiltModulePath $builtModulePath -CommandName 'Invoke-NovaTest' -ExcludeTag $ExcludeTag
67+
Invoke-NovaModuleToolsFreshValidationCommand -Command $unitTestCommand
68+
69+
$buildValidationCommand = Get-NovaModuleToolsValidationCommand -BuiltModulePath $builtModulePath -CommandName 'Test-NovaBuild' -ExcludeTag $ExcludeTag
70+
Invoke-NovaModuleToolsFreshValidationCommand -Command $buildValidationCommand
4271
} catch {
4372
$novaModuleToolsTestFailed = $true
4473
Write-Warning "Nova test workflow failed: $( $_.Exception.Message )"

tests/Invoke-NovaModuleToolsCI.Tests.ps1

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Describe 'Invoke-NovaModuleToolsCI' {
3737
$projectRoot = Join-Path $TestDrive 'project'
3838
$outputDirectory = Join-Path $TestDrive 'artifacts-out'
3939
$callLogPath = Join-Path $TestDrive 'call-log.txt'
40-
$excludeTagLogPath = Join-Path $TestDrive 'exclude-tags.txt'
40+
$commandLogPath = Join-Path $TestDrive 'commands.txt'
4141
$unitResultPath = Join-Path $projectRoot 'artifacts/UnitTestResults.xml'
4242
$integrationResultPath = Join-Path $projectRoot 'artifacts/TestResults.xml'
4343

@@ -64,24 +64,24 @@ function Get-NovaProjectInfo {
6464
}
6565
}
6666
67-
function Remove-Module {
67+
function pwsh {
6868
[CmdletBinding()]
69-
param([string]`$Name)
70-
}
71-
72-
function Invoke-NovaTest {
73-
[CmdletBinding()]
74-
param([string[]]`$ExcludeTagFilter)
69+
param(
70+
[switch]`$NoLogo,
71+
[switch]`$NoProfile,
72+
[string]`$Command
73+
)
7574
76-
Add-Content -LiteralPath '$callLogPath' -Value 'Invoke-NovaTest'
77-
Set-Content -LiteralPath '$excludeTagLogPath' -Value (`$ExcludeTagFilter -join ',') -Encoding utf8
78-
}
75+
Add-Content -LiteralPath '$commandLogPath' -Value `$Command
76+
if (`$Command -match 'Invoke-NovaTest') {
77+
Add-Content -LiteralPath '$callLogPath' -Value 'Invoke-NovaTest'
78+
}
7979
80-
function Test-NovaBuild {
81-
[CmdletBinding()]
82-
param([string[]]`$ExcludeTagFilter)
80+
if (`$Command -match 'Test-NovaBuild') {
81+
Add-Content -LiteralPath '$callLogPath' -Value 'Test-NovaBuild'
82+
}
8383
84-
Add-Content -LiteralPath '$callLogPath' -Value 'Test-NovaBuild'
84+
`$global:LASTEXITCODE = 0
8585
}
8686
8787
& '$script:novaModuleToolsCiScriptPath' -OutputDirectory '$outputDirectory' -ExcludeTag 'slow','integration'
@@ -90,7 +90,10 @@ function Test-NovaBuild {
9090

9191
$result.ExitCode | Should -Be 0 -Because ($result.Output -join [Environment]::NewLine)
9292
(Get-Content -LiteralPath $callLogPath) | Should -Be @('Invoke-NovaTest', 'Test-NovaBuild')
93-
(Get-Content -LiteralPath $excludeTagLogPath -Raw).Trim() | Should -Be 'slow,integration'
93+
$commands = Get-Content -LiteralPath $commandLogPath
94+
$commands | Should -HaveCount 2
95+
$commands[0] | Should -Match "Import-Module '.*/dist/NovaModuleTools/NovaModuleTools\.psd1' -Force -ErrorAction Stop; Invoke-NovaTest -ExcludeTagFilter @\('slow', 'integration'\)"
96+
$commands[1] | Should -Match "Import-Module '.*/dist/NovaModuleTools/NovaModuleTools\.psd1' -Force -ErrorAction Stop; Test-NovaBuild -ExcludeTagFilter @\('slow', 'integration'\)"
9497
(Get-Content -LiteralPath (Join-Path $outputDirectory 'novamoduletools-unit-nunit.xml') -Raw).Trim() | Should -Be '<unit-test-results />'
9598
(Get-Content -LiteralPath (Join-Path $outputDirectory 'novamoduletools-integration-nunit.xml') -Raw).Trim() | Should -Be '<integration-test-results />'
9699
}
@@ -122,24 +125,29 @@ function Get-NovaProjectInfo {
122125
}
123126
}
124127
125-
function Remove-Module {
128+
function pwsh {
126129
[CmdletBinding()]
127-
param([string]`$Name)
128-
}
130+
param(
131+
[switch]`$NoLogo,
132+
[switch]`$NoProfile,
133+
[string]`$Command
134+
)
129135
130-
function Invoke-NovaTest {
131-
throw 'boom'
132-
}
136+
if (`$Command -match 'Invoke-NovaTest') {
137+
`$global:LASTEXITCODE = 1
138+
return
139+
}
133140
134-
function Test-NovaBuild {}
141+
`$global:LASTEXITCODE = 0
142+
}
135143
136144
& '$script:novaModuleToolsCiScriptPath' -OutputDirectory '$outputDirectory'
137145
"@
138146
$result = Invoke-NovaModuleToolsCIRunner -RunnerContent $runnerContent
139147
$outputText = $result.Output -join [Environment]::NewLine
140148

141149
$result.ExitCode | Should -Be 1
142-
$outputText | Should -Match 'Nova test workflow failed: boom'
150+
$outputText | Should -Match 'Nova test workflow failed: Validation command failed: .*Invoke-NovaTest'
143151
(Get-Content -LiteralPath (Join-Path $outputDirectory 'novamoduletools-unit-nunit.xml') -Raw).Trim() | Should -Be '<failed-unit-test-results />'
144152
Test-Path -LiteralPath (Join-Path $outputDirectory 'novamoduletools-integration-nunit.xml') | Should -BeFalse
145153
}

0 commit comments

Comments
 (0)