-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoke-NovaModuleToolsCI.ps1
More file actions
81 lines (65 loc) · 2.89 KB
/
Copy pathInvoke-NovaModuleToolsCI.ps1
File metadata and controls
81 lines (65 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
param(
[string]$OutputDirectory = './artifacts',
[string[]]$ExcludeTag = @()
)
Set-StrictMode -Version Latest
function Copy-NovaModuleToolsArtifactIfPresent {
param(
[Parameter(Mandatory)][string]$SourcePath,
[Parameter(Mandatory)][string]$DestinationPath
)
if (Test-Path -LiteralPath $SourcePath) {
Copy-Item -LiteralPath $SourcePath -Destination $DestinationPath -Force
}
}
function ConvertTo-NovaSingleQuotedPowerShellLiteral {
param(
[Parameter(Mandatory)][string]$Value
)
return "'$($Value.Replace("'", "''") )'"
}
function Get-NovaModuleToolsValidationCommand {
param(
[Parameter(Mandatory)][string]$BuiltModulePath,
[Parameter(Mandatory)][string]$CommandName,
[string[]]$ExcludeTag = @()
)
$commandLine = $CommandName
if (@($ExcludeTag).Count -gt 0) {
$excludeTagLiteral = @($ExcludeTag | ForEach-Object {ConvertTo-NovaSingleQuotedPowerShellLiteral -Value ([string]$_)}) -join ', '
$commandLine += " -ExcludeTagFilter @($excludeTagLiteral)"
}
return "Import-Module $( ConvertTo-NovaSingleQuotedPowerShellLiteral -Value $BuiltModulePath ) -Force -ErrorAction Stop; $commandLine"
}
function Invoke-NovaModuleToolsFreshValidationCommand {
param(
[Parameter(Mandatory)][string]$Command
)
& pwsh -NoLogo -NoProfile -Command $Command
if ($LASTEXITCODE -ne 0) {
throw "Validation command failed: $Command"
}
}
$repoRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..' '..' '..')).Path
Set-Location $repoRoot
New-Item -ItemType Directory -Path $OutputDirectory -Force | Out-Null
Import-Module NovaModuleTools -ErrorAction Stop
$projectInfo = Get-NovaProjectInfo
Invoke-NovaBuild
$builtModulePath = Join-Path $projectInfo.OutputModuleDir "$( $projectInfo.ProjectName ).psd1"
$novaModuleToolsTestFailed = $false
try {
$unitTestCommand = Get-NovaModuleToolsValidationCommand -BuiltModulePath $builtModulePath -CommandName 'Invoke-NovaTest' -ExcludeTag $ExcludeTag
Invoke-NovaModuleToolsFreshValidationCommand -Command $unitTestCommand
$buildValidationCommand = Get-NovaModuleToolsValidationCommand -BuiltModulePath $builtModulePath -CommandName 'Test-NovaBuild' -ExcludeTag $ExcludeTag
Invoke-NovaModuleToolsFreshValidationCommand -Command $buildValidationCommand
} catch {
$novaModuleToolsTestFailed = $true
Write-Warning "Nova test workflow failed: $( $_.Exception.Message )"
} finally {
Copy-NovaModuleToolsArtifactIfPresent -SourcePath (Join-Path $projectInfo.ProjectRoot 'artifacts/UnitTestResults.xml') -DestinationPath (Join-Path $OutputDirectory 'novamoduletools-unit-nunit.xml')
Copy-NovaModuleToolsArtifactIfPresent -SourcePath (Join-Path $projectInfo.ProjectRoot 'artifacts/TestResults.xml') -DestinationPath (Join-Path $OutputDirectory 'novamoduletools-integration-nunit.xml')
}
if ($novaModuleToolsTestFailed) {
exit 1
}