-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathYster.DesktopCentral.build.ps1
91 lines (76 loc) · 3.12 KB
/
Yster.DesktopCentral.build.ps1
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
82
83
84
85
86
87
88
89
90
91
#Requires -Modules @{ModuleName='InvokeBuild';ModuleVersion='5.8.8'}
#Requires -Modules @{ModuleName='PowerShellGet';ModuleVersion='2.2.5'}
#Requires -Modules @{ModuleName='Pester';ModuleVersion='5.3.1'}
#Requires -Modules @{ModuleName='ModuleBuilder';ModuleVersion='2.0.0'}
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[ValidateSet('Development', 'Release')]
[string]
$Configuration = 'Development'
)
$Script:IsAppveyor = $null -ne $env:APPVEYOR
$Script:ModuleName = Get-Item -Path $BuildRoot | Select-Object -ExpandProperty Name
Get-Module -Name $ModuleName | Remove-Module -Force
task Clean {
Remove-Item -Path ".\Bin" -Recurse -Force -ErrorAction SilentlyContinue
}
task TestCode {
Write-Build Yellow "`n`nTesting dev code before build"
$PesterConfiguration = New-PesterConfiguration
$PesterConfiguration.Run.Path = "$PSScriptRoot\Test\Unit"
$PesterConfiguration.Output.Verbosity = 'None'
$PesterConfiguration.Run.PassThru = $true
$PesterConfiguration.Filter.Tag = 'Unit'
$TestResult = Invoke-Pester -Configuration $PesterConfiguration
if ($TestResult.FailedCount -gt 0) {
Write-Warning -Message "Failing Tests:"
$TestResult.Tests | Where-Object { $_.Result -eq 'Failed' } | ForEach-Object {
Write-Verbose -Message $_.Name -Verbose
}
throw 'Tests failed'
}
}
task CompilePSM {
Write-Build Yellow "`n`nCompiling all code into single psm1"
$BuildParams = @{}
$ModuleDefinition = Import-PowerShellDataFile -Path "$BuildRoot\Source\*.psd1"
$BuildParams['SemVer'] = $ModuleDefinition.ModuleVersion
Push-Location -Path "$BuildRoot\Source" -StackName 'InvokeBuildTask'
$Script:CompileResult = Build-Module @BuildParams -Passthru
Get-ChildItem -Path "$BuildRoot\license*" | Copy-Item -Destination $Script:CompileResult.ModuleBase
Pop-Location -StackName 'InvokeBuildTask'
}
task MakeHelp -if (Test-Path -Path "$PSScriptRoot\Docs") {
}
task TestBuild {
Write-Build Yellow "`n`nTesting compiled module"
$PesterConfiguration = New-PesterConfiguration
$PesterConfiguration.Run.Path = "$PSScriptRoot\Test\Unit"
$PesterConfiguration.Output.Verbosity = 'None'
$PesterConfiguration.Run.PassThru = $true
$TestResult = Invoke-Pester -Configuration $PesterConfiguration
if ($TestResult.FailedCount -gt 0) {
Write-Warning -Message "Failing Tests:"
$TestResult.Tests | Where-Object { $_.Result -eq 'Failed' } | ForEach-Object {
Write-Verbose -Message $_.Name -Verbose
}
throw 'Tests failed'
}
}
task PublishModule -if ($Configuration -eq 'Release') {
Write-Build Yellow "`n`nPublishing module to PSGallery"
try {
$Parameters = @{
Path = $Script:CompileResult.ModuleBase
NuGetApiKey = $env:NugetApiKey
ErrorAction = 'Stop'
Verbose = $true
}
Publish-Module @Parameters
} catch {
throw $_
}
}
task . Clean, TestCode, Build
task Build CompilePSM, MakeHelp, TestBuild, PublishModule