forked from AtlassianPS/ConfluencePS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfluencePS.build.ps1
230 lines (200 loc) · 8.49 KB
/
ConfluencePS.build.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
[CmdletBinding()]
param()
$DebugPreference = "SilentlyContinue"
$WarningPreference = "Continue"
if ($PSBoundParameters.ContainsKey('Verbose')) {
$VerbosePreference = "Continue"
}
if (!($env:releasePath)) {
$releasePath = "$BuildRoot\Release"
}
elseif ($env:releasePath) {
$releasePath = $env:releasePath
}
else {
$releasePath = "$($pwd.Path)\Release"
}
$env:PSModulePath = "$($env:PSModulePath);$releasePath"
Import-Module BuildHelpers
# Ensure Invoke-Build works in the most strict mode.
Set-StrictMode -Version Latest
# region debug information
task ShowDebug {
Write-Build Gray
Write-Build Gray ('Project name: {0}' -f $env:APPVEYOR_PROJECT_NAME)
Write-Build Gray ('Project root: {0}' -f $env:APPVEYOR_BUILD_FOLDER)
Write-Build Gray ('Repo name: {0}' -f $env:APPVEYOR_REPO_NAME)
Write-Build Gray ('Branch: {0}' -f $env:APPVEYOR_REPO_BRANCH)
Write-Build Gray ('Commit: {0}' -f $env:APPVEYOR_REPO_COMMIT)
Write-Build Gray (' - Author: {0}' -f $env:APPVEYOR_REPO_COMMIT_AUTHOR)
Write-Build Gray (' - Time: {0}' -f $env:APPVEYOR_REPO_COMMIT_TIMESTAMP)
Write-Build Gray (' - Message: {0}' -f $env:APPVEYOR_REPO_COMMIT_MESSAGE)
Write-Build Gray (' - Extended message: {0}' -f $env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED)
Write-Build Gray ('Pull request number: {0}' -f $env:APPVEYOR_PULL_REQUEST_NUMBER)
Write-Build Gray ('Pull request title: {0}' -f $env:APPVEYOR_PULL_REQUEST_TITLE)
Write-Build Gray ('AppVeyor build ID: {0}' -f $env:APPVEYOR_BUILD_ID)
Write-Build Gray ('AppVeyor build number: {0}' -f $env:APPVEYOR_BUILD_NUMBER)
Write-Build Gray ('AppVeyor build version: {0}' -f $env:APPVEYOR_BUILD_VERSION)
Write-Build Gray ('AppVeyor job ID: {0}' -f $env:APPVEYOR_JOB_ID)
Write-Build Gray ('Build triggered from tag? {0}' -f $env:APPVEYOR_REPO_TAG)
Write-Build Gray (' - Tag name: {0}' -f $env:APPVEYOR_REPO_TAG_NAME)
Write-Build Gray ('PowerShell version: {0}' -f $PSVersionTable.PSVersion.ToString())
Write-Build Gray
}
# Synopsis: Install pandoc to .\Tools\
task InstallPandoc -If (-not (Test-Path Tools\pandoc.exe)) {
# Setup
if (-not (Test-Path "$BuildRoot\Tools")) {
$null = New-Item -Path "$BuildRoot\Tools" -ItemType Directory
}
# Get latest bits
$latestRelease = "https://github.com/jgm/pandoc/releases/download/1.19.2.1/pandoc-1.19.2.1-windows.msi"
Invoke-WebRequest -Uri $latestRelease -OutFile "$($env:temp)\pandoc.msi"
# Extract bits
$null = New-Item -Path $env:temp\pandoc -ItemType Directory -Force
Start-Process -Wait -FilePath msiexec.exe -ArgumentList " /qn /a `"$($env:temp)\pandoc.msi`" targetdir=`"$($env:temp)\pandoc\`""
# Move to Tools folder
Copy-Item -Path "$($env:temp)\pandoc\Pandoc\pandoc.exe" -Destination "$BuildRoot\Tools\"
Copy-Item -Path "$($env:temp)\pandoc\Pandoc\pandoc-citeproc.exe" -Destination "$BuildRoot\Tools\"
# Clean
Remove-Item -Path "$($env:temp)\pandoc" -Recurse -Force
}
# endregion
# region test
task Test {
assert { Test-Path "Release/" -PathType Container }
try {
$result = Invoke-Pester -PassThru -OutputFile "$BuildRoot\TestResult.xml" -OutputFormat "NUnitXml"
if ($env:APPVEYOR_PROJECT_NAME) {
Add-TestResultToAppveyor -TestFile "$BuildRoot\TestResult.xml"
Remove-Item "$BuildRoot\TestResult.xml" -Force
}
assert ($result.FailedCount -eq 0) "$($result.FailedCount) Pester test(s) failed."
}
catch {
throw
}
}
# endregion
# region build
# Synopsis: Build shippable release
task Build GenerateRelease, ConvertMarkdown, UpdateManifest
task CreateHelp {
Import-Module platyPS -Force
New-ExternalHelp -Path "$BuildRoot\docs\commands" -OutputPath "$BuildRoot\ConfluencePS\en-US" -Force
Remove-Module ConfluencePS, platyPS
}
# Synopsis: Generate .\Release structure
task GenerateRelease CreateHelp, {
# Setup
if (-not (Test-Path "$releasePath\ConfluencePS")) {
$null = New-Item -Path "$releasePath\ConfluencePS" -ItemType Directory
}
# Copy module
Copy-Item -Path "$BuildRoot\ConfluencePS\*" -Destination "$releasePath\ConfluencePS" -Recurse -Force
# Copy additional files
$additionalFiles = @(
"$BuildRoot\CHANGELOG.md"
"$BuildRoot\LICENSE"
"$BuildRoot\README.md"
)
Copy-Item -Path $additionalFiles -Destination "$releasePath\ConfluencePS" -Force
}
# Synopsis: Update the manifest of the module
task UpdateManifest GetVersion, {
Update-Metadata -Path "$releasePath\ConfluencePS\ConfluencePS.psd1" -PropertyName ModuleVersion -Value $script:Version
# Update-Metadata -Path "$releasePath\ConfluencePS\ConfluencePS.psd1" -PropertyName FileList -Value (Get-ChildItem $releasePath\ConfluencePS -Recurse).Name
$functionsToExport = Get-ChildItem "$BuildRoot\ConfluencePS\Public" | ForEach-Object {$_.BaseName}
Set-ModuleFunctions -Name "$releasePath\ConfluencePS\ConfluencePS.psd1" -FunctionsToExport $functionsToExport
}
task GetVersion {
$manifestContent = Get-Content -Path "$releasePath\ConfluencePS\ConfluencePS.psd1" -Raw
if ($manifestContent -notmatch '(?<=ModuleVersion\s+=\s+'')(?<ModuleVersion>.*)(?='')') {
throw "Module version was not found in manifest file,"
}
$currentVersion = [Version] $Matches.ModuleVersion
if ($env:APPVEYOR_BUILD_NUMBER) {
$newRevision = $env:APPVEYOR_BUILD_NUMBER
}
else {
$newRevision = 0
}
$script:Version = New-Object -TypeName System.Version -ArgumentList $currentVersion.Major,
$currentVersion.Minor,
$newRevision
}
# Synopsis: Convert markdown files to HTML.
# <http://johnmacfarlane.net/pandoc/>
$ConvertMarkdown = @{
Inputs = { Get-ChildItem "$releasePath\ConfluencePS\*.md" -Recurse }
Outputs = {process {
[System.IO.Path]::ChangeExtension($_, 'htm')
}
}
}
# Synopsis: Converts *.md and *.markdown files to *.htm
task ConvertMarkdown -Partial @ConvertMarkdown InstallPandoc, {process {
exec { Tools\pandoc.exe $_ --standalone --from=markdown_github "--output=$2" }
}
}, RemoveMarkdownFiles
# endregion
# region publish
task Deploy -If (
# Only deploy if the master branch changes
$env:APPVEYOR_REPO_BRANCH -eq 'master' -and
# Do not deploy if this is a pull request (because it hasn't been approved yet)
(-not ($env:APPVEYOR_PULL_REQUEST_NUMBER)) -and
# Do not deploy if the commit contains the string "skip-deploy"
# Meant for major/minor version publishes with a .0 build/patch version (like 2.1.0)
$env:APPVEYOR_REPO_COMMIT_MESSAGE -notlike '*skip-deploy*'
) PublishToGallery, UpdateHomepage
task PublishToGallery {
assert ($env:PSGalleryAPIKey) "No key for the PSGallery"
Remove-Module ConfluencePS -ErrorAction SilentlyContinue
Import-Module $releasePath\ConfluencePS\ConfluencePS.psd1 -ErrorAction Stop
Publish-Module -Name ConfluencePS -NuGetApiKey $env:PSGalleryAPIKey
}
task UpdateHomepage {
try {
# Get the repo of the homepage
exec { git clone https://github.com/AtlassianPS/AtlassianPS.github.io --recursive } -ErrorAction SilentlyContinue
Write-Host "Cloned"
Set-Location "AtlassianPS.github.io/"
# Update all submodules
exec { git submodule foreach git pull origin master } -ErrorAction SilentlyContinue
Write-Host "Fetched"
# Check if this repo was changed
$status = exec { git status -s }
if ($status -contains " M modules/ConfluencePS") {
Write-Host "Has changes"
# Update the repo in the homepage repo
exec { git add modules/ConfluencePS }
Write-Host "Added"
exec { git commit -m "Update module ConfluencePS" } -ErrorAction SilentlyContinue
Write-Host "Commited"
exec { git push }
Write-Host "Pushed"
}
}
catch {
throw "Failed to updated the website"
}
}
# endregion
#region Cleaning tasks
task Clean RemoveGeneratedFiles
# Synopsis: Remove generated and temp files.
task RemoveGeneratedFiles {
$itemsToRemove = @(
'Release'
'*.htm'
'TestResult.xml'
'ConfluencePS\en-US\*'
)
Remove-Item $itemsToRemove -Force -Recurse -ErrorAction 0
}
task RemoveMarkdownFiles {
Remove-Item "$releasePath\ConfluencePS\*.md" -Force -ErrorAction 0
}
# endregion
task . ShowDebug, Clean, Build, Test, Deploy