forked from hjorslev/SteamPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteamPS.build.ps1
168 lines (151 loc) · 7.7 KB
/
SteamPS.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
Set-BuildEnvironment -ErrorAction SilentlyContinue
# Synopsis: Initializing
Add-BuildTask Init {
# Line break for readability in AppVeyor console
Write-Host -Object ''
Write-Host -Object 'Build System Details:'
Write-Output -InputObject $PSVersionTable
Write-Host -Object "`n"
Get-Item env:BH*
Write-Host -Object "`n"
}
# Synopsis: Pester Tests
Add-BuildTask Test {
Remove-Module -Name $env:BHProjectName -Force -ErrorAction SilentlyContinue
Import-Module $env:BHPSModuleManifest -Force -Global
# Invoke Pester to run all of the unit tests, then save the results into XML in order to populate the AppVeyor tests section
# If any of the tests fail, consider the pipeline failed
$PesterResults = Invoke-Pester -Path "$env:BHProjectPath\Tests" -CI -Output Detailed
if ($env:BHBuildSystem -eq 'AppVeyor') {
Add-TestResultToAppveyor -TestFile "$env:BHProjectPath\testResults.xml"
}
if ($PesterResults.FailedCount -gt 0) {
throw "$($PesterResults.FailedCount) tests failed."
}
}
# Synopsis: Build manifest
Add-BuildTask BuildManifest {
# We're going to add 1 to the revision value since a new commit has been merged to Master
# This means that the major / minor / build values will be consistent across GitHub and the Gallery
try {
# Get current module version from Manifest.
$Manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
[version]$Version = $Manifest.ModuleVersion
Write-Output -InputObject "Old Version: $Version"
# Update module version in Manifest.
switch -Wildcard ($env:BHCommitMessage) {
'*!ver:MAJOR*' {
New-Variable -Name NewVersion -Value $(Step-Version -Version $Version -By Major) -Scope Global
Step-ModuleVersion -Path $env:BHPSModuleManifest -By Major
}
'*!ver:MINOR*' {
New-Variable -Name NewVersion -Value $(Step-Version -Version $Version -By Minor) -Scope Global
Step-ModuleVersion -Path $env:BHPSModuleManifest -By Minor
}
# Default is just changed build
Default {
New-Variable -Name NewVersion -Value $(Step-Version -Version $Version) -Scope Global
Step-ModuleVersion -Path $env:BHPSModuleManifest -By Patch
}
}
Write-Output -InputObject "New Version: $NewVersion"
# Update yaml file with new version information.
$AppVeyor = ConvertFrom-Yaml -Yaml $(Get-Content "$env:BHProjectPath\appveyor.yml" | Out-String)
$UpdateAppVeyor = $AppVeyor.GetEnumerator() | Where-Object { $_.Name -eq 'version' }
$UpdateAppVeyor | ForEach-Object { $AppVeyor[$_.Key] = "$($NewVersion).{build}" }
ConvertTo-Yaml -Data $AppVeyor -OutFile "$env:BHProjectPath\appveyor.yml" -Force
# Populate FunctionsToExport with BaseNames found within the Public and Private folders.
$PublicFunctions = ((Get-ChildItem -Path "$env:BHModulePath\Public\*.ps1" -Recurse).BaseName) | Sort-Object
Set-ModuleFunction -FunctionsToExport $PublicFunctions
Get-ModuleFunction
# Update copyright notice.
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName Copyright -Value "(c) 2019-$((Get-Date).Year) $(Get-Metadata -Path $env:BHPSModuleManifest -PropertyName Author). All rights reserved."
} catch {
throw $_
}
}
# Synopsis: Build docs
Add-BuildTask BuildDocs {
if ($env:BHBuildSystem -ne 'Unknown' -and $env:BHBranchName -eq 'master' ) {
# Create new markdown and XML help files.
Write-Host -Object 'Building new function documentation' -ForegroundColor Yellow
if ((Test-Path -Path "$env:BHProjectPath\docs") -eq $false) {
New-Item -Path $env:BHProjectPath -Name 'docs' -ItemType Directory
}
Import-Module $env:BHPSModuleManifest -Force -Global
New-MarkdownHelp -Module $env:BHProjectName -OutputFolder "$env:BHProjectPath\docs" -Force
New-ExternalHelp -Path "$($env:BHProjectPath)\docs" -OutputPath "$env:BHModulePath\en-US\" -Force
Copy-Item -Path '.\README.md' -Destination 'docs\index.md'
Copy-Item -Path '.\CHANGELOG.md' -Destination 'docs\CHANGELOG.md'
} else {
Write-Host -Object "Skipping building docs because `n" +
Write-Host -Object "`t* You are on $env:BHBranchName and not master branch.`n"
}
}
# Synopsis: Deploy to PSGallery
Add-BuildTask DeployPSGallery {
# Publish the new version to the PowerShell Gallery
try {
Invoke-PSDeploy -Force -ErrorAction Stop
Write-Host -Object "$env:BHProjectName PowerShell Module version $NewVersion published to the PowerShell Gallery." -ForegroundColor Cyan
} catch {
# Sad panda; it broke
Write-Warning -Message "Publishing update $NewVersion to the PowerShell Gallery failed."
throw $_
}
}
# Synopsis: Deploy to Github Releases
Add-BuildTask DeployGHRelease {
# Get latest changelog and publish it to GitHub Releases.
$ChangeLog = Get-Content -Path '.\CHANGELOG.md'
# Expect that the latest changelog info is located at line 8.
$ChangeLog = $ChangeLog.Where( { $_ -eq $ChangeLog[7] }, 'SkipUntil')
# Grab all text until next heading that starts with ## [.
$ChangeLog = $ChangeLog.Where( { $_ -eq ($ChangeLog | Select-String -Pattern "## \[" | Select-Object -Skip 1 -First 1) }, 'Until')
# Publish GitHub Release
$GHReleaseSplat = @{
AccessToken = $env:GitHubKey
RepositoryOwner = $(Get-Metadata -Path $env:BHPSModuleManifest -PropertyName CompanyName)
TagName = "v$NewVersion"
Name = "v$NewVersion Release of $env:BHProjectName"
ReleaseText = $ChangeLog | Out-String
}
Publish-GithubRelease @GHReleaseSplat
}
# Synopsis: Push changes to GitHub
Add-BuildTask PushChangesGitHub {
# Remove files we don't want to be pushed to GitHub
Remove-Item -Path "$env:BHProjectPath\coverage.xml" -Force
Remove-Item -Path "$env:BHProjectPath\testResults.xml" -Force
# Publish the new version back to Master on GitHub
try {
$ErrorActionPreference = 'Continue'
# Set up a path to the git.exe cmd, import posh-git to give us control over git, and then push changes to GitHub
# Note that "update version" is included in the appveyor.yml file's "skip a build" regex to avoid a loop
$env:Path += "; $env:ProgramFiles\Git\cmd"
Import-Module -Name 'posh-git'
git checkout master
git add --all
git status
git commit -s -m ":rocket: [skip ci] Update version to $NewVersion"
git push origin master
$ErrorActionPreference = 'Stop'
Write-Host -Object "$env:BHProjectName PowerShell Module version $NewVersion published to GitHub." -ForegroundColor Cyan
} catch {
# Sad panda; it broke
Write-Warning "Publishing update $NewVersion to GitHub failed."
throw $_
}
}
if ($env:BHBuildSystem -eq 'AppVeyor' -and $env:BHBranchName -eq 'master' -and $env:BHCommitMessage -like "*!deploy*") {
# Synopsis: Entire build pipeline
#TODO: DeployGHRelease not working atm.
# Add-BuildTask . Init, Test, BuildManifest, BuildDocs, DeployPSGallery, DeployGHRelease, PushChangesGitHub
Add-BuildTask . Init, Test, BuildManifest, BuildDocs, DeployPSGallery, PushChangesGitHub
} else {
Add-BuildTask . Init, Test
Write-Host -Object "Skipping deployment: To deploy, ensure that...`n"
Write-Host -Object "`t* You are in build system 'AppVeyor' (Current: $env:BHBuildSystem)`n"
Write-Host -Object "`t* You are committing to the master branch (Current: $env:BHBranchName) `n"
Write-Host -Object "`t* Your commit message includes '!deploy' (Current: $env:BHCommitMessage) `n"
}