-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
psake.ps1
49 lines (39 loc) · 1.51 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
properties {
$projectRoot = $ENV:BHProjectPath
if(-not $projectRoot) {
$projectRoot = $PSScriptRoot
}
$sut = "$projectRoot\$env:BHProjectName"
$tests = "$projectRoot\Tests"
$psVersion = $PSVersionTable.PSVersion.Major
}
task default -depends Test
task Init {
"`nSTATUS: Testing with PowerShell $psVersion"
"Build System Details:"
Get-Item ENV:BH*
$modules = 'Pester', 'PSScriptAnalyzer'
Install-Module $modules -Repository PSGallery -Confirm:$false
Import-Module $modules -Verbose:$false -Force
} -description 'Initialize build environment'
task Test -Depends Init, Analyze, Pester -description 'Run test suite'
task Analyze -Depends Init {
$saResults = Invoke-ScriptAnalyzer -Path $sut -Severity Error -Recurse -Verbose:$false
if ($saResults) {
$saResults | Format-Table
Write-Error -Message 'One or more Script Analyzer errors/warnings where found. Build cannot continue!'
}
} -description 'Run PSScriptAnalyzer'
task Pester -Depends Init {
if(-not $ENV:BHProjectPath) {
Set-BuildEnvironment -Path $PSScriptRoot\..
}
Remove-Module $ENV:BHProjectName -ErrorAction SilentlyContinue
Import-Module (Join-Path $ENV:BHProjectPath $ENV:BHProjectName) -Force
if (Test-Path -Path $tests) {
Invoke-Pester -Path $tests -PassThru -EnableExit
}
} -description 'Run Pester tests'
task Publish -depends Test {
Publish-Module -Path $env:BHModulePath -Repository PSGallery -NuGetApiKey $env:PSGALLERY_API_KEY -Verbose
}