-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpsake.ps1
270 lines (230 loc) · 8.06 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# PSake makes variables declared here available in other scriptblocks
# Init some things
Properties {
# Find the build folder based on build system
$ProjectRoot = $ENV:BHProjectPath
if (-not $ProjectRoot)
{
$ProjectRoot = $PSScriptRoot
}
$ProjectRoot = Convert-Path $ProjectRoot
try
{
$script:IsWindows = (-not (Get-Variable -Name IsWindows -ErrorAction Ignore)) -or $IsWindows
$script:IsLinux = (Get-Variable -Name IsLinux -ErrorAction Ignore) -and $IsLinux
$script:IsMacOS = (Get-Variable -Name IsMacOS -ErrorAction Ignore) -and $IsMacOS
$script:IsCoreCLR = $PSVersionTable.ContainsKey('PSEdition') -and $PSVersionTable.PSEdition -eq 'Core'
}
catch { }
$Timestamp = Get-date -uformat "%Y%m%d-%H%M%S"
$PSVersion = $PSVersionTable.PSVersion.Major
$TestFile = "TestResults_PS$PSVersion`_$TimeStamp.xml"
$lines = '----------------------------------------------------------------------'
$Verbose = @{}
if ($ENV:BHCommitMessage -match "!verbose")
{
$Verbose = @{Verbose = $True}
}
$DefaultLocale = 'en-US'
$DocsRootDir = Join-Path $PSScriptRoot docs
$ModuleName = "aws-toolbox"
$ModuleOutDir = Join-Path $PSScriptRoot aws-toolbox
}
Task Default -Depends BuildHelp
Task Init {
$lines
Set-Location $ProjectRoot
"Build System Details:"
Get-Item ENV:BH*
"`n"
if ($script:IsWindows)
{
"Checking for NuGet"
$psgDir = Join-Path ${env:LOCALAPPDATA} "Microsoft\Windows\PowerShell\PowerShellGet"
$nugetPath = $(
$nuget = Get-Command nuget.exe -ErrorAction SilentlyContinue
if ($nuget)
{
$nuget.Path
}
else
{
if (Test-Path -Path (Join-Path $psgDir 'nuget.exe'))
{
Join-Path $psgDir 'nuget.exe'
}
}
)
if ($nugetPath)
{
"NuGet.exe found at '$nugetPath"
}
else
{
if (-not (Test-Path -Path $psgDir -PathType Container))
{
New-Item -Path $psgDir -ItemType Directory | Out-Null
}
"Installing NuGet to '$psgDir'"
Invoke-WebRequest -Uri https://nuget.org/nuget.exe -OutFile (Join-Path $psgDir 'nuget.exe')
}
}
}
Task Test -Depends Init {
$lines
"`n`tSTATUS: Testing with PowerShell $PSVersion"
# Gather test results. Store them in a variable and file
$pesterParameters = @{
Path = Join-Path $ProjectRoot tests
PassThru = $true
OutputFormat = "NUnitXml"
OutputFile = Join-Path $ProjectRoot $TestFile
}
if (-Not $IsWindows) { $pesterParameters["ExcludeTag"] = "WindowsOnly" }
$TestResults = Invoke-Pester @pesterParameters
# In Appveyor? Upload our tests! #Abstract this into a function?
If ($ENV:BHBuildSystem -eq 'AppVeyor')
{
(New-Object 'System.Net.WebClient').UploadFile(
"https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)",
(Join-Path $ProjectRoot $TestFile) )
}
Remove-Item (Join-Path $ProjectRoot $TestFile) -Force -ErrorAction SilentlyContinue
# Failed tests?
# Need to tell psake or it will proceed to the deployment. Danger!
if ($TestResults.FailedCount -gt 0)
{
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
}
"`n"
}
Task Build -Depends Test {
$lines
# Load the module, read the exported functions, update the psd1 FunctionsToExport
#Set-ModuleFunctions
# Bump the module version if we didn't already
Try
{
[version]$GalleryVersion = Get-NextNugetPackageVersion -Name $env:BHProjectName -ErrorAction Stop
[version]$GithubVersion = Get-MetaData -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -ErrorAction Stop
if ($GalleryVersion -ge $GithubVersion)
{
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $GalleryVersion -ErrorAction stop
}
}
Catch
{
"Failed to update version for '$env:BHProjectName': $_.`nContinuing with existing version"
}
}
Task Deploy -Depends Init {
$lines
$deployParams = $(
if ($ENV:BHBuildSystem -ieq 'AppVeyor')
{
# We will deploy _something_
Write-Host '- Deploying to'
Write-Host ' - AppVeyor Artifact'
$params = @{
Path = $ProjectRoot
Force = $true
Tags = @('Development') # Push AppVeyor artifact
}
if ($ENV:BHBranchName -eq "master" -and $ENV:APPVEYOR_REPO_TAG -ieq 'true')
{
# Tag push in master is a release, so we want to also push to PSGallery
$params['Tags'] += 'Production'
Write-Host ' - PowerShell Gallery'
}
# Emit parameters
$params
}
else
{
$null
}
)
# Gate deployment
if ($null -ne $deployParams)
{
Invoke-PSDeploy @Verbose @deployParams
}
else
{
"Skipping deployment: To deploy, ensure that...`n" +
"`t* You are in AppVeyor (Current: $ENV:BHBuildSystem)`n" +
"`t* For Gallery deployment`n" +
"`t * You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
"`t * You have pushed a tag (i.e. created a release in GitHub)"
}
}
Task BuildHelp -Depends Build, GenerateMarkdown {}
Task GenerateMarkdown -requiredVariables DefaultLocale, DocsRootDir {
if ($ENV:BHBuildSystem -ine 'Unknown')
{
"Only updating help when building locally"
return
}
if (!(Get-Module platyPS -ListAvailable))
{
"platyPS module is not installed. Skipping $($psake.context.currentTaskName) task."
return
}
$moduleInfo = Import-Module $ENV:BHPSModuleManifest -Global -Force -PassThru
try
{
if ($moduleInfo.ExportedCommands.Count -eq 0)
{
"No commands have been exported. Skipping $($psake.context.currentTaskName) task."
return
}
if (!(Test-Path -LiteralPath $DocsRootDir))
{
New-Item $DocsRootDir -ItemType Directory > $null
}
else
{
# Force regeneration of all function documentation
Get-ChildItem -LiteralPath $DocsRootDir -Filter *.md -Recurse |
Where-Object {
$_.Name -ine "${env:BHProjectName}.md"
} |
Remove-Item -Force
}
<#
if (Get-ChildItem -LiteralPath $DocsRootDir -Filter *.md -Recurse)
{
Get-ChildItem -LiteralPath $DocsRootDir -Directory |
ForEach-Object {
Update-MarkdownHelp -Path $_.FullName -Verbose:$VerbosePreference > $null
}
}
#>
# ErrorAction set to SilentlyContinue so this command will not overwrite an existing MD file.
New-MarkdownHelp -Module $ModuleName -Locale $DefaultLocale -OutputFolder $DocsRootDir\$DefaultLocale `
-WithModulePage -ErrorAction SilentlyContinue -Verbose:$VerbosePreference > $null
}
finally
{
Remove-Module $ModuleName
}
}
Task GenerateHelpFiles -requiredVariables DocsRootDir, ModuleName, ModuleOutDir {
if (!(Get-Module platyPS -ListAvailable))
{
"platyPS module is not installed. Skipping $($psake.context.currentTaskName) task."
return
}
if (!(Get-ChildItem -LiteralPath $DocsRootDir -Filter *.md -Recurse -ErrorAction SilentlyContinue))
{
"No markdown help files to process. Skipping $($psake.context.currentTaskName) task."
return
}
$helpLocales = (Get-ChildItem -Path $DocsRootDir -Directory).Name
# Generate the module's primary MAML help file.
foreach ($locale in $helpLocales)
{
New-ExternalHelp -Path $DocsRootDir\$locale -OutputPath $ModuleOutDir\$locale -Force `
-ErrorAction SilentlyContinue -Verbose:$VerbosePreference > $null
}
}