-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psake.ps1
51 lines (41 loc) · 1.69 KB
/
psake.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
properties {
$projectRoot = $ENV:BHProjectPath
if(-not $projectRoot) {
$projectRoot = $PSScriptRoot
}
$sut = "$projectRoot\$env:BHProjectName"
$tests = "$projectRoot\Tests"
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$psVersion = $PSVersionTable.PSVersion.Major
}
task default -depends Test
task Init {
"`nSTATUS: Testing with PowerShell $psVersion"
"Build System Details:"
Get-Item ENV:BH*
} -description 'Initialize build environment'
task Test -Depends Init, Analyze, Pester -description 'Run test suite'
task Analyze -Depends Init {
$analysis = Invoke-ScriptAnalyzer -Path $sut -Recurse -Verbose:$false
$errors = $analysis | Where-Object {$_.Severity -eq 'Error'}
$warnings = $analysis | Where-Object {$_.Severity -eq 'Warning'}
if (@($errors).Count -gt 0) {
Write-Error -Message 'One or more Script Analyzer errors were found. Build cannot continue!'
$errors | Format-Table
}
if (@($warnings).Count -gt 0) {
Write-Warning -Message 'One or more Script Analyzer warnings were found. These should be corrected.'
$warnings | Format-Table
}
} -description 'Run PSScriptAnalyzer'
task Pester -Depends Init {
Remove-Module $ENV:BHProjectName -ErrorAction SilentlyContinue -Verbose:$false
Import-Module -Name $env:BHPSModuleManifest -Force -Verbose:$false
if (Test-Path -Path $tests) {
Invoke-Pester -Path $tests -PassThru -EnableExit
}
} -description 'Run Pester tests'
Task Publish -Depends Build {
" Publishing version [$($manifest.ModuleVersion)] to PSGallery..."
Publish-Module -Path $sut -NuGetApiKey $env:PSGalleryApiKey -Repository PSGallery
}