1+ properties {
2+ $settings = . (Join-Path - path $PSScriptRoot - ChildPath build.settings.ps1)
3+ }
4+
5+ task default - depends Test
6+
7+ task Init {
8+ " STATUS: Testing with PowerShell $ ( $settings.PSVersion ) "
9+ ' Build System Details:'
10+ Get-Item ENV:BH*
11+ } - description ' Initialize build environment'
12+
13+ task Test - Depends Init, Analyze, Pester - description ' Run test suite'
14+
15+ task Analyze - depends Init {
16+ $analysis = Invoke-ScriptAnalyzer - Path $settings.SUT - Recurse - Verbose:$false
17+ $errors = $analysis | Where-Object {$_.Severity -eq ' Error' }
18+ $warnings = $analysis | Where-Object {$_.Severity -eq ' Warning' }
19+ if (@ ($errors ).Count -gt 0 ) {
20+ Write-Error - Message ' One or more Script Analyzer errors were found. Build cannot continue!'
21+ $errors | Format-Table
22+ }
23+
24+ if (@ ($warnings ).Count -gt 0 ) {
25+ Write-Warning - Message ' One or more Script Analyzer warnings were found. These should be corrected.'
26+ $warnings | Format-Table
27+ }
28+ } - description ' Run PSScriptAnalyzer'
29+
30+ task Pester - depends Init {
31+ Remove-Module $settings.ProjectName - ErrorAction SilentlyContinue - Verbose:$false
32+ Import-Module - Name $settings.ManifestPath - Force - Verbose:$false
33+
34+ if (Test-Path - Path $settings.Tests ) {
35+ Invoke-Pester - Path $settings.Tests - PassThru - EnableExit
36+ }
37+ } - description ' Run Pester tests'
38+
39+ task Publish - depends Init {
40+ " Publishing version [$ ( $settings.Manifest.ModuleVersion ) ] to PSGallery..."
41+ if ($settings.PSGalleryApiKey ) {
42+ Publish-Module - Path $settings.SUT - NuGetApiKey $settings.PSGalleryApiKey - Repository PSGallery
43+ } else {
44+ throw ' Did not find PSGallery API key!'
45+ }
46+ } - description ' Publish to PowerShellGallery'
0 commit comments