forked from devblackops/NetScaler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psake.ps1
94 lines (81 loc) · 3.41 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
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
92
93
94
properties {
$projectRoot = $ENV:BHProjectPath
if(-not $projectRoot) {
$projectRoot = $PSScriptRoot
}
$sut = Join-Path -Path $projectRoot -ChildPath $ENV:BHProjectName
$testDir = Join-Path $projectRoot -ChildPath 'Tests'
$metaTests = Join-Path $testDir -ChildPath 'Meta'
$unitTests = Join-Path $testDir -ChildPath 'Unit'
$integrationTests = Join-Path $testDir -ChildPath 'Integration'
$psVersion = $PSVersionTable.PSVersion.Major
}
task default -depends Test
task Init {
"`nSTATUS: Testing with PowerShell $psVersion"
"Build System Details:"
Get-Item ENV:BH*
Write-Host $sut
}
task Test -Depends Init, Analyze, Pester-Meta, Pester-Module
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!'
}
}
task Pester-Meta -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
$testResultsFile = "$projectRoot\TestResults-Meta.xml"
$testResults = Invoke-Pester -Path $metaTests -PassThru -OutputFormat NUnitXml -OutputFile $testResultsFile
# If in AppVeyor, upload test results
if ($env:BHBuildSystem -eq 'AppVeyor') {
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $testResultsFile)
}
if ($testResults.FailedCount -gt 0) {
$testResults | Format-List
Write-Error -Message 'One or more Pester tests failed. Build cannot continue!'
}
}
task Pester-Module -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
$testResultsFile = "$projectRoot\TestResults-Module.xml"
$testResults = Invoke-Pester -Path $unitTests -PassThru -OutputFormat NUnitXml -OutputFile $testResultsFile
# If in AppVeyor, upload test results
if ($env:BHBuildSystem -eq 'AppVeyor') {
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $testResultsFile)
}
if ($testResults.FailedCount -gt 0) {
$testResults | Format-List
Write-Error -Message 'One or more Pester tests failed. Build cannot continue!'
}
Remove-Module $ENV:BHProjectName -ErrorAction SilentlyContinue
}
task Deploy -depends Test, GenerateHelp {
# Gate deployment
if( $ENV:BHBuildSystem -ne 'Unknown' -and
$ENV:BHBranchName -eq "master" -and
$ENV:BHCommitMessage -match '!deploy'
) {
$params = @{
Path = "$projectRoot\module.psdeploy.ps1"
Force = $true
Recurse = $false
}
Invoke-PSDeploy @Params
} else {
"Skipping deployment: To deploy, ensure that...`n" +
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" +
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)"
}
}