-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
psake.ps1
88 lines (73 loc) · 2.72 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
properties {
$projectRoot = $ENV:BHProjectPath
if(-not $projectRoot) {
$projectRoot = $PSScriptRoot
}
$sut = "$projectRoot\Watchmen"
$tests = "$projectRoot\Tests"
$psVersion = $PSVersionTable.PSVersion.Major
}
task default -depends Test
task Init {
"`nSTATUS: Testing with PowerShell $psVersion"
"Build System Details:"
Get-Item ENV:BH*
$modules = 'Pester', 'PSDeploy', 'PSScriptAnalyzer', 'platyPS', 'PSSlack', 'Posh-SYSLOG'
Install-Module $modules -Repository PSGallery -Confirm:$false
Import-Module $modules -Verbose:$false -Force
}
task Test -Depends Init, Analyze, Pester
task Analyze -Depends Init {
$saResults = Invoke-ScriptAnalyzer -Path $sut -Severity Error -Recurse -Verbose:$false
if ($saResults) {
$saResults | Format-Table
Write-Error -Message 'One or more Script Analyzer errors/warnings where found. Build cannot continue!'
}
}
task Pester -Depends Init {
if(-not $ENV:BHProjectPath) {
Set-BuildEnvironment -Path $PSScriptRoot\..
}
Remove-Module $ENV:BHProjectName -ErrorAction SilentlyContinue
Import-Module (Join-Path $ENV:BHProjectPath $ENV:BHProjectName) -Force
$testResults = Invoke-Pester -Path $tests -PassThru
if ($testResults.FailedCount -gt 0) {
$testResults | Format-List
Write-Error -Message 'One or more Pester tests failed. Build cannot continue!'
}
}
task UpdateHelpMarkdown -Depends Init {
Import-Module -Name $sut -Force
Update-MarkdownHelp -Path "$projectRoot\docs\functions" -Encoding ([System.Text.Encoding]::UTF8)
}
task GenerateHelp -Depends Init {
New-ExternalHelp -OutputPath "$sut\en-US" -Path "$projectRoot\docs\functions" -Force -Encoding ([System.Text.Encoding]::UTF8)
}
task ExportFunctions {
$files = Get-ChildItem -Path $sut\Public | Select-Object -ExpandProperty Name
$functions = @()
foreach ($file in $files) {
$functions += $file.Split('.')[0]
}
Update-ModuleManifest -Path $sut\Watchmen.psd1 -FunctionsToExport $functions
}
task Deploy -depends Test, GenerateHelp {
# Gate deployment
if(
$ENV:BHBuildSystem -ne 'Unknown' -and
$ENV:BHBranchName -eq "master" -and
$ENV:BHCommitMessage -match '!deploy'
) {
$params = @{
Path = "$projectRoot\module.psdeploy.ps1"
Force = $true
Recurse = $false
}
Invoke-PSDeploy @Params
} else {
"Skipping deployment: To deploy, ensure that...`n" +
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" +
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)"
}
}