-
Notifications
You must be signed in to change notification settings - Fork 27
/
psake.ps1
165 lines (96 loc) · 4.78 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
properties {
$projectRoot = $ENV:BHProjectPath
if(-not $projectRoot) {
$projectRoot = $PSScriptRoot
}
$tests = "$projectRoot/tests"
$outputDir = Join-Path -Path $projectRoot -ChildPath 'out'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$psVersion = $PSVersionTable.PSVersion.Major
$pathSeperator = [IO.Path]::PathSeparator
$dirSeperator = [IO.Path]::DirectorySeparatorChar
}
task default -depends Test
task Init {
Write-Output @"
STATUS: Testing with PowerShell $psVersion
Build System Details:
$($(Get-Item ENV:BH*) | Out-String)
"@
'Pester', 'PSScriptAnalyzer' | Foreach-Object {
if (-not (Get-Module -Name $_ -ListAvailable -Verbose:$false -ErrorAction SilentlyContinue)) {
Install-Module -Name $_ -Repository PSGallery -Scope CurrentUser -AllowClobber -Confirm:$false -ErrorAction Stop
}
Import-Module -Name $_ -Verbose:$false -Force -ErrorAction Stop
}
} -description 'Initialize build environment'
task Test -Depends Init, Analyze, Pester -description 'Run test suite'
task Analyze -Depends Build {
$analysis = Invoke-ScriptAnalyzer -Path "$($ENV:BHPSModulePath)\Functions" -Verbose:$false -Recurse
$errors = $analysis | Where-Object {$_.Severity -eq 'Error'}
$warnings = $analysis | Where-Object {$_.Severity -eq 'Warning'}
if (($errors.Count -eq 0) -and ($warnings.Count -eq 0)) {
Write-Output 'PSScriptAnalyzer passed without errors or warnings'
}
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 Build {
if(-not $ENV:BHProjectPath) {
Set-BuildEnvironment -Path $PSScriptRoot\..
}
#Remove and import module for testing
Write-Output "Importing module from [$($ENV:BHPSModulePath)]..."
Remove-Module $ENV:BHProjectName -ErrorAction SilentlyContinue -Verbose:$false
Import-Module -Name $ENV:BHPSModulePath -Force -Verbose:$false
$testResultsXml = Join-Path -Path "$($projectRoot)\tests\artifacts\" -ChildPath 'testResults.xml'
$testResults = Invoke-Pester -Path $tests -PassThru -OutputFile $testResultsXml -OutputFormat NUnitXml
#Upload test artifacts to AppVeyor
if ($env:APPVEYOR_JOB_ID) {
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $testResultsXml)
}
if ($testResults.FailedCount -gt 0) {
$testResults | Format-List
Write-Error -Message 'One or more Pester tests failed. Build cannot continue!'
}
$env:PSModulePath = $origModulePath
Remove-Item -Path $testResultsXml -Force
} -description 'Run Pester tests'
task CreateMarkdownHelp {
#Get functions
Import-Module -Name $ENV:BHPSModulePath -Force -Verbose:$false -Global
$mdHelpPath = Join-Path -Path $projectRoot -ChildPath 'docs/reference/functions'
$mdFiles = New-MarkdownHelp -Module $env:BHProjectName -OutputFolder $mdHelpPath -WithModulePage -Force
Write-Output "Module markdown help created at [$mdHelpPath]"
@($env:BHProjectName).ForEach({
Remove-Module -Name $_ -Verbose:$false
})
} -description 'Create initial markdown help files'
task UpdateMarkdownHelp {
Import-Module -Name $ENV:BHPSModulePath -Force -Verbose:$false
$mdHelpPath = Join-Path -Path $projectRoot -ChildPath 'docs/reference/functions'
$mdFiles = Update-MarkdownHelpModule -Path $mdHelpPath -Verbose:$false
Write-Output `t"Markdown help updated at [$mdHelpPath]"
} -description 'Update markdown help files'
task CreateExternalHelp -Depends CreateMarkdownHelp {
New-ExternalHelp "$projectRoot\docs\reference\functions" -OutputPath "$($ENV:BHPSModulePath)\en-US" -Force
} -description 'Create module help from markdown files'
Task RegenerateHelp -Depends UpdateMarkdownHelp, CreateExternalHelp
#CreateMarkdownHelp (add back to build)
task Build {
# External help
#$helpXml = New-ExternalHelp "$projectRoot\docs\reference\functions" -OutputPath (Join-Path -Path $ENV:BHPSModulePath -ChildPath 'en-US') -Force
Write-Output "Module XML help created at [.helpXml]"
}
Task Publish -Depends Test {
Write-Output "Running PSDeploy for version [$($manifest.ModuleVersion)]..."
Invoke-PSDeploy -Path $projectRoot -Force
}