forked from psake/PowerShellBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsakeFile.ps1
More file actions
159 lines (141 loc) · 5.23 KB
/
psakeFile.ps1
File metadata and controls
159 lines (141 loc) · 5.23 KB
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
properties {
# Load in build settings
. (Join-Path -Path $PSScriptRoot -ChildPath build.properties.ps1)
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$scriptAnalysisEnabled = $true
$CompileModule = $true
$convertReadMeToAboutHelp = $true
}
FormatTaskName {
param($taskName)
Write-Host 'Task: ' -ForegroundColor Cyan -NoNewline
Write-Host $taskName.ToUpper() -ForegroundColor Blue
}
# This psake file is meant to be referenced from another
# Can't have two 'default' tasks
# Task default -depends Test
task Init {
Initialize-PSBuild -UseBuildHelpers
}
task Clean -depends Init -requiredVariables moduleOutDir {
Clear-PSBuildOutputFolder -Path $moduleOutDir
}
task StageFiles -depends Clean -requiredVariables moduleOutDir, srcRootDir {
$buildParams = @{
Path = $srcRootDir
DestinationPath = $moduleOutDir
ModuleName = $moduleName
Exclude = $Exclude
Compile = $compileModule
Culture = $defaultLocale
}
if ($convertReadMeToAboutHelp) {
$readMePath = Get-ChildItem -Path $projectRoot -Include 'readme.md', 'readme.markdown', 'readme.txt' -Depth 1 |
Select-Object -First 1
if ($readMePath) {
$buildParams.ReadMePath = $readMePath
}
}
Build-PSBuildModule @buildParams
}
task Build -depends Init, Clean, StageFiles {
}
$reqVars = @(
'moduleOutDir', 'scriptAnalysisEnabled', 'scriptAnalysisFailBuildOnSeverityLevel', 'scriptAnalyzerSettingsPath'
)
$analyzePreReqs = {
$result = $true
if (-not $scriptAnalysisEnabled) {
Write-Warning 'Script analysis is not enabled.'
$result = $false
}
if (-not (Get-Module -Name PSScriptAnalyzer -ListAvailable)) {
Write-Warning 'PSScriptAnalyzer module is not installed'
$result = $false
}
$result
}
task Analyze -depends Build -requiredVariables $reqVars -precondition $analyzePreReqs {
$analyzeParams = @{
Path = $moduleOutDir
SeverityThreshold = $scriptAnalysisFailBuildOnSeverityLevel
SettingsPath = $scriptAnalyzerSettingsPath
}
Test-PSBuildScriptAnalysis @analyzeParams
} -description 'Execute PSScriptAnalyzer tests'
$pesterReqVars = @(
'testRootDir', 'moduleName', 'testOutputFormat', 'codeCoverageEnabled', 'codeCoverageThreshold', 'codeCoverageFiles'
)
$pesterPreReqs = {
$result = $true
if (-not $testingEnabled) {
Write-Warning 'Pester testing is not enabled.'
$result = $false
}
if (-not (Get-Module -Name Pester -ListAvailable)) {
Write-Warning 'Pester module is not installed'
$result = $false
}
if (-not (Test-Path -Path $testRootDir)) {
Write-Warning "Test directory [$testRootDir] not found"
$result = $false
}
return $result
}
task Pester -depends Build -requiredVariables $pesterReqVars -precondition $pesterPreReqs {
$pesterParams = @{
Path = $testRootDir
ModuleName = $moduleName
OutputPath = $testOutputFile
OutputFormat = $testOutputFormat
CodeCoverage = $codeCoverageEnabled
CodeCoverageThreshold = $codeCoverageThreshold
CodeCoverageFiles = $codeCoverageFiles
}
Test-PSBuildPester @pesterParams
} -description 'Execute Pester tests'
task Test -depends Pester, Analyze {
} -description 'Execute Pester and ScriptAnalyzer tests'
task BuildHelp -depends Build, GenerateMarkdown, GenerateMAML {}
$genMarkdownVars = @(
'docsRootDir', 'defaultLocale', 'moduleName', 'moduleOutDir')
$genMarkdownPreReqs = {
$result = $true
if (-not (Get-Module platyPS -ListAvailable)) {
Write-Warning "platyPS module is not installed. Skipping [$($psake.context.currentTaskName)] task."
$result = $false
}
$result
}
task GenerateMarkdown -depends Build -requiredVariables $genMarkdownVars -precondition $genMarkdownPreReqs {
Build-PSBuildMarkdown -ModulePath $moduleOutDir -ModuleName $moduleName -DocsPath $docsRootDir -Locale $defaultLocale
}
$genHelpFilesPreReqs = {
$result = $true
if (-not (Get-Module platyPS -ListAvailable)) {
Write-Warning "platyPS module is not installed. Skipping [$($psake.context.currentTaskName)] task."
$result = $false
}
$result
}
task GenerateMAML -depends GenerateMarkdown -requiredVariables docsRootDir, moduleOutDir -precondition $genHelpFilesPreReqs {
Build-PSBuildMAMLHelp -Path $docsRootDir -DestinationPath $moduleOutDir
}
$genUpdatableHelpVars = @(
'docsRootDir', 'moduleName', 'updatableHelpOutDir'
)
$genUpdatableHelpPreReqs = {
$result = $true
if (-not (Get-Module platyPS -ListAvailable)) {
Write-Warning "platyPS module is not installed. Skipping [$($psake.context.currentTaskName)] task."
$result = $false
}
$result
}
task GenerateUpdatableHelp -depends BuildHelp -requiredVariables $genUpdatableHelpVars -precondition $genUpdatableHelpPreReqs {
Build-PSBuildUpdatableHelp -DocsPath $docsRootDir -OutputPath $updatableHelpOutDir
}
task ? -description 'Lists the available tasks' {
'Available tasks:'
$psake.context.Peek().Tasks.Keys | Sort-Object
}