-
-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathJiraPS.build.ps1
More file actions
218 lines (183 loc) · 8.48 KB
/
JiraPS.build.ps1
File metadata and controls
218 lines (183 loc) · 8.48 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
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
[CmdletBinding()]
param(
[ValidateSet('None', 'Normal' , 'Detailed', 'Diagnostic')]
[String] $PesterVerbosity = 'Normal',
[Parameter()]
[String] $VersionToPublish,
[Parameter()]
[String] $PSGalleryAPIKey
)
Import-Module "$PSScriptRoot/Tools/BuildTools.psm1" -Force
Remove-Item -Path env:\BH* -ErrorAction SilentlyContinue
Set-BuildEnvironment -BuildOutput '$ProjectPath/Release' -ErrorAction SilentlyContinue
#region HarmonizeVariables
switch ($true) {
{ $IsWindows } {
$OS = "Windows"
if (-not ($IsCoreCLR)) {
$OSVersion = $PSVersionTable.BuildVersion.ToString()
}
}
{ $IsLinux } {
$OS = "Linux"
}
{ $IsMacOs } {
$OS = "OSX"
}
{ $IsCoreCLR } {
$OSVersion = $PSVersionTable.OS
}
}
#endregion HarmonizeVariables
if ($VersionToPublish) {
$VersionToPublish = $VersionToPublish.TrimStart('v')
}
$builtManifestPath = "$env:BHBuildOutput/$env:BHProjectName/$env:BHProjectName.psd1"
Task ShowDebugInfo {
Write-Build Gray
Write-Build Gray ('BHBuildSystem: {0}' -f $env:BHBuildSystem)
Write-Build Gray '-------------------------------------------------------'
Write-Build Gray ('BHProjectName {0}' -f $env:BHProjectName)
Write-Build Gray ('BHProjectPath: {0}' -f $env:BHProjectPath)
Write-Build Gray ('BHModulePath: {0}' -f $env:BHModulePath)
Write-Build Gray ('BHPSModuleManifest: {0}' -f $env:BHPSModuleManifest)
Write-Build Gray ('BHBuildOutput: {0}' -f $env:BHBuildOutput)
Write-Build Gray ('builtManifestPath: {0}' -f $builtManifestPath)
Write-Build Gray '-------------------------------------------------------'
Write-Build Gray ('BHBranchName: {0}' -f $env:BHBranchName)
Write-Build Gray ('BHCommitHash: {0}' -f $env:BHCommitHash)
Write-Build Gray ('BHCommitMessage: {0}' -f $env:BHCommitMessage)
Write-Build Gray ('BHBuildNumber {0}' -f $env:BHBuildNumber)
Write-Build Gray ('VersionToPublish {0}' -f $VersionToPublish)
Write-Build Gray '-------------------------------------------------------'
Write-Build Gray ('PowerShell version: {0}' -f $PSVersionTable.PSVersion.ToString())
Write-Build Gray ('OS: {0}' -f $OS)
Write-Build Gray ('OS Version: {0}' -f $OSVersion)
Write-Build Gray
}
Task Clean {
Remove-Item $env:BHBuildOutput -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item "Test*.xml" -Force -ErrorAction SilentlyContinue
Remove-Item "$env:BHModulePath/en-US" -Recurse -Force -ErrorAction SilentlyContinue
}
Task Build Clean, {
if (-not (Test-Path "$env:BHBuildOutput/$env:BHProjectName")) {
$null = New-Item -Path "$env:BHBuildOutput", "$env:BHBuildOutput/$env:BHProjectName" -ItemType Directory
}
}, GenerateExternalHelp, CopyModuleFiles, CompileModule, UpdateManifest
# Synopsis: Generate ./Release structure
Task CopyModuleFiles {
Copy-Item -Path "$env:BHModulePath/*" -Destination "$env:BHBuildOutput/$env:BHProjectName" -Recurse -Force
Copy-Item -Path @(
"$env:BHProjectPath/CHANGELOG.md"
"$env:BHProjectPath/LICENSE"
"$env:BHProjectPath/README.md"
) -Destination "$env:BHBuildOutput/$env:BHProjectName" -Force
$null = New-Item -Path "$env:BHBuildOutput/Tests" -ItemType Directory -ErrorAction SilentlyContinue
Copy-Item -Path "$env:BHProjectPath/Tests" -Destination $env:BHBuildOutput -Recurse -Force
Copy-Item -Path "$env:BHProjectPath/PSScriptAnalyzerSettings.psd1" -Destination $env:BHBuildOutput -Force
}
# Synopsis: Compile all functions into the .psm1 file
Task CompileModule {
$regionsToKeep = @('Dependencies', 'Configuration')
$targetFile = "$env:BHBuildOutput/$env:BHProjectName/$env:BHProjectName.psm1"
$content = Get-Content -Encoding UTF8 -LiteralPath $targetFile
$capture = $false
$compiled = ""
foreach ($line in $content) {
if ($line -match "^#region ($($regionsToKeep -join "|"))$") {
$capture = $true
}
if (($capture -eq $true) -and ($line -match "^#endregion")) {
$capture = $false
}
if ($capture) {
$compiled += "$line`r`n"
}
}
$PublicFunctions = @( Get-ChildItem -Path "$env:BHBuildOutput/$env:BHProjectName/Public/*.ps1" -ErrorAction SilentlyContinue )
$PrivateFunctions = @( Get-ChildItem -Path "$env:BHBuildOutput/$env:BHProjectName/Private/*.ps1" -ErrorAction SilentlyContinue )
foreach ($function in @($PublicFunctions + $PrivateFunctions)) {
$compiled += (Get-Content -Path $function.FullName -Raw)
$compiled += "`r`n"
}
Set-Content -LiteralPath $targetFile -Value $compiled -Encoding UTF8 -Force
Remove-Utf8Bom -Path $targetFile
"Private", "Public" | ForEach-Object { Remove-Item -Path "$env:BHBuildOutput/$env:BHProjectName/$_" -Recurse -Force }
}
# Synopsis: Use PlatyPS to generate External-Help
Task GenerateExternalHelp {
Import-Module platyPS -Force
foreach ($locale in (Get-ChildItem "$env:BHProjectPath/docs" -Attribute Directory)) {
New-ExternalHelp -Path "$($locale.FullName)" -OutputPath "$env:BHModulePath/$($locale.Basename)" -Force
New-ExternalHelp -Path "$($locale.FullName)/commands" -OutputPath "$env:BHModulePath/$($locale.Basename)" -Force
}
Remove-Module platyPS
}
# Synopsis: Update the manifest of the module
Task UpdateManifest {
Remove-Module $env:BHProjectName -ErrorAction SilentlyContinue
Import-Module $env:BHPSModuleManifest -Force
$moduleAlias = Get-Alias | Where-Object { $_.ModuleName -eq "$env:BHProjectName" }
$moduleFunctions = (Get-ChildItem "$env:BHModulePath/Public/*.ps1").BaseName
Metadata\Update-Metadata -Path $builtManifestPath -PropertyName "FunctionsToExport" -Value @($moduleFunctions)
Metadata\Update-Metadata -Path $builtManifestPath -PropertyName "AliasesToExport" -Value ''
if ($moduleAlias) {
Metadata\Update-Metadata -Path $builtManifestPath -PropertyName "AliasesToExport" -Value @($moduleAlias.Name)
}
}
Task SetVersion {
[System.Management.Automation.SemanticVersion]$versionToPublish = $VersionToPublish
$latestPublished = Get-LatestPublishedVersion -Name $env:BHProjectName
Write-Build Gray "Latest published version: $latestPublished"
Assert-True { $versionToPublish -gt $latestPublished } "Version must be greater than latest published version: $latestPublished"
$versionString = "{0}.{1}.{2}" -f $versionToPublish.Major, $versionToPublish.Minor, $versionToPublish.Patch
Metadata\Update-Metadata -Path $builtManifestPath -PropertyName "ModuleVersion" -Value $versionString
if ($versionToPublish.PreReleaseLabel) {
Write-Build Gray "Setting Prerelease label: $($versionToPublish.PreReleaseLabel)"
Metadata\Update-Metadata -Path $builtManifestPath -PropertyName "Prerelease" -Value $versionToPublish.PreReleaseLabel
}
else {
Write-Build Gray "Removing Prerelease label (stable release)"
Metadata\Update-Metadata -Path $builtManifestPath -PropertyName "Prerelease" -Value ''
}
}
Task Test {
$pesterConfig = New-PesterConfiguration -Hashtable @{
Run = @{
PassThru = $true
Path = "$env:BHBuildOutput/Tests"
}
TestResult = @{
Enabled = $true
OutputFormat = 'NUnitXml'
OutputPath = "Test-$OS-$($PSVersionTable.PSVersion.ToString()).xml"
}
Output = @{
Verbosity = $PesterVerbosity
}
<# CodeCoverage = @{
Path = $codeCoverageFiles
} #>
}
$testResults = Invoke-Pester -Configuration $pesterConfig
Assert-True ($testResults.FailedCount -eq 0) "$($testResults.FailedCount) Pester test(s) failed."
}
Task Publish SetVersion, SignCode, Package, {
Assert-True (-not [String]::IsNullOrEmpty($PSGalleryAPIKey)) "No key for the PSGallery"
Publish-Module -Path "$env:BHBuildOutput/$env:BHProjectName" -NuGetApiKey $PSGalleryAPIKey
}, UpdateHomepage
Task UpdateHomepage {
# TODO:
}
Task SignCode {
# TODO: waiting for certificates
}
Task Package {
$source = "$env:BHBuildOutput\$env:BHProjectName"
$destination = "$env:BHBuildOutput\$env:BHProjectName.zip"
Assert-True { Test-Path $source } "Missing files to package"
Remove-Item $destination -ErrorAction SilentlyContinue
$null = Compress-Archive -Path $source -DestinationPath $destination
}
Task . Clean, Build, Test