1 changed file
Build | ||
build.psake.ps1 | ||
Add comment 5 $ProjectRoot = $PSScriptRoot
Add comment 6 }
Add comment 7
Add comment 8 Minus $Timestamp = Get-Date -UFormat "%Y%m%d-%H%M%S"
Add comment 8 Plus $Timestamp = Get-Date -UFormat '%Y%m%d-%H%M%S'
Add comment 9 $PSVersion = $PSVersionTable.PSVersion.Major
Add comment 10 $lines = '----------------------------------------------------------------------'
Add comment 11
Add comment 12 Minus $Verbose = @{}
Add comment 13 Minus if ($ENV:BHCommitMessage -match "!verbose") {
Add comment 14 Minus $Verbose = @{Verbose = $True}
Add comment 15 Minus }
Add comment 16 Minus
Add comment 17 12 # Pester
Add comment 18 Minus $TestRootDir = "$ProjectRoot\Tests"
Add comment 19 13 $TestScripts = Get-ChildItem "$ProjectRoot\Tests\*\*Tests.ps1"
Add comment 20 14 $TestFile = "$($TimeStamp)_UnitTestResults.xml"
Add comment 21 15
Add comment 26 20
Add comment 27 21 # Documentation
Add comment 28 22 $DocumentationPath = Join-Path -Path $ProjectRoot -ChildPath 'Documentation'
Add comment 23 Plus
Add comment 24 Plus # Build
Add comment 25 Plus $ArtifactFolder = Join-Path -Path $ProjectRoot -ChildPath 'Artifacts'
Add comment 26 Plus
Add comment 27 Plus # Staging
Add comment 28 Plus $StagingFolder = Join-Path -Path $projectRoot -ChildPath 'Staging'
Add comment 29 Plus $StagingModulePath = Join-Path -Path $StagingFolder -ChildPath $env:BHProjectName
Add comment 29 30 }
Add comment 30 31
Add comment 32 Plus
Add comment 33 Plus # Define top-level tasks
Add comment 31 34 Task 'Default' -Depends 'Test'
Add comment 35 Plus Task 'Release' -Depends 'Clean', 'Test', 'UpdateDocumentation', 'CombineFunctionsAndStage', 'CreateReleaseArtifact' #'UpdateManifest', 'UpdateTag',
Add comment 32 36
Add comment 37 Plus
Add comment 38 Plus # Main tasks
Add comment 33 39 Task 'Init' {
Add comment 34 40 $lines
Add comment 35 41 Set-Location $ProjectRoot
Add comment 38 44 "`n"
Add comment 39 45 }
Add comment 40 46
Add comment 47 Plus
Add comment 41 48 Task 'Analyze' -Depends 'Init' {
Add comment 42 49
Add comment 43 50 $Results = Invoke-ScriptAnalyzer -Path $ENV:BHModulePath -Recurse -Settings $ScriptAnalyzerSettingsPath -Verbose:$VerbosePreference
Add comment 67 74
Add comment 68 75 }
Add comment 69 76
Add comment 77 Plus
Add comment 70 78 Task 'Test' -Depends 'Analyze' {
Add comment 71 79 $lines
Add comment 72 80 "`nSTATUS: Testing with PowerShell $PSVersion"
Add comment 73 81
Add comment 74 82 # Gather test results. Store them in a variable and file
Add comment 75 Minus $TestFilePath = Join-Path -Path $ProjectRoot -ChildPath $TestFile
Add comment 83 Plus $TestFilePath = Join-Path -Path $ArtifactFolder -ChildPath $TestFile
Add comment 76 84 $TestResults = Invoke-Pester -Script $TestScripts -PassThru -OutputFormat 'NUnitXml' -OutputFile $TestFilePath -PesterOption @{IncludeVSCodeMarker = $true}
Add comment 77 85
Add comment 78 86 # Upload test results to Appveyor
Add comment 89 97 "`n"
Add comment 90 98 }
Add comment 91 99
Add comment 100 Plus
Add comment 92 101 Task 'Build' -Depends 'Test' {
Add comment 93 102 $lines
Add comment 94 103
Add comment 105 114 }
Add comment 106 115 }
Add comment 107 116
Add comment 117 Plus
Add comment 108 118 Task 'Deploy' -Depends 'Build' {
Add comment 109 119 $lines
Add comment 110 120
Add comment 116 126 Invoke-PSDeploy @Verbose @Params
Add comment 117 127 }
Add comment 118 128
Add comment 129 Plus
Add comment 119 130 Task 'UpdateDocumentation' -Depends 'Test' {
Add comment 120 131 $lines
Add comment 121 132
Add comment 142 153
Add comment 143 154 Write-Output "`nFINISHED: Updating Markdown help."
Add comment 144 155 }
Add comment 156 Plus
Add comment 157 Plus
Add comment 158 Plus Task 'Clean' {
Add comment 159 Plus $lines
Add comment 160 Plus
Add comment 161 Plus $foldersToClean = @(
Add comment 162 Plus $ArtifactFolder
Add comment 163 Plus $StagingFolder
Add comment 164 Plus )
Add comment 165 Plus
Add comment 166 Plus # Remove folders
Add comment 167 Plus foreach ($folderPath in $foldersToClean) {
Add comment 168 Plus Remove-Item -Path $folderPath -Recurse -Force -ErrorAction 'SilentlyContinue'
Add comment 169 Plus New-Item -Path $folderPath -ItemType 'Directory' -Force | Out-String | Write-Verbose
Add comment 170 Plus }
Add comment 171 Plus }
Add comment 172 Plus
Add comment 173 Plus Task 'CombineFunctionsAndStage' {
Add comment 174 Plus $lines
Add comment 175 Plus
Add comment 176 Plus # Create folders
Add comment 177 Plus New-Item -Path $StagingFolder -ItemType 'Directory' -Force | Out-String | Write-Verbose
Add comment 178 Plus New-Item -Path $StagingModulePath -ItemType 'Directory' -Force | Out-String | Write-Verbose
Add comment 179 Plus
Add comment 180 Plus # Get public and private function files
Add comment 181 Plus $publicFunctions = @( Get-ChildItem -Path "$env:BHModulePath\Public\*.ps1" -Recurse -ErrorAction 'SilentlyContinue' )
Add comment 182 Plus $privateFunctions = @( Get-ChildItem -Path "$env:BHModulePath\Private\*.ps1" -Recurse -ErrorAction 'SilentlyContinue' )
Add comment 183 Plus
Add comment 184 Plus # Combine functions into a single .psm1 module
Add comment 185 Plus $combinedModulePath = Join-Path -Path $StagingModulePath -ChildPath "$($env:BHProjectName).psm1"
Add comment 186 Plus @($publicFunctions + $privateFunctions) | Get-Content | Add-Content -Path $combinedModulePath
Add comment 187 Plus
Add comment 188 Plus # Copy other required folders and files
Add comment 189 Plus $pathsToCopy = @(
Add comment 190 Plus Join-Path -Path $ProjectRoot -ChildPath 'Documentation'
Add comment 191 Plus Join-Path -Path $ProjectRoot -ChildPath 'Examples'
Add comment 192 Plus # Join-Path -Path $ProjectRoot -ChildPath 'CHANGELOG.md'
Add comment 193 Plus Join-Path -Path $ProjectRoot -ChildPath 'README.md'
Add comment 194 Plus )
Add comment 195 Plus Copy-Item -Path $pathsToCopy -Destination $StagingFolder -Recurse
Add comment 196 Plus
Add comment 197 Plus # Copy existing manifest
Add comment 198 Plus Copy-Item -Path $env:BHPSModuleManifest -Destination $StagingModulePath -Recurse
Add comment 199 Plus }
Add comment 200 Plus
Add comment 201 Plus
Add comment 202 Plus Task 'CreateReleaseArtifact' {
Add comment 203 Plus $lines
Add comment 204 Plus
Add comment 205 Plus # Create /Release folder
Add comment 206 Plus New-Item -Path $ArtifactFolder -ItemType 'Directory' -Force | Out-String | Write-Verbose
Add comment 207 Plus
Add comment 208 Plus # Get current manifest version
Add comment 209 Plus try {
Add comment 210 Plus $manifest = Test-ModuleManifest -Path $env:BHPSModuleManifest -ErrorAction 'Stop'
Add comment 211 Plus [Version]$manifestVersion = $manifest.Version
Add comment 212 Plus
Add comment 213 Plus }
Add comment 214 Plus catch {
Add comment 215 Plus throw "Could not get manifest version from [$env:BHPSModuleManifest]"
Add comment 216 Plus }
Add comment 217 Plus
Add comment 218 Plus # Create zip file
Add comment 219 Plus try {
Add comment 220 Plus $releaseFilename = "$env:BHProjectName-v$($manifestVersion.ToString()).zip"
Add comment 221 Plus $releasePath = Join-Path -Path $ArtifactFolder -ChildPath $releaseFilename
Add comment 222 Plus Write-Host "Creating release artifact [$releasePath] using manifest version [$manifestVersion]" -ForegroundColor 'Yellow'
Add comment 223 Plus Compress-Archive -Path "$StagingFolder/*" -DestinationPath $releasePath -Force -Verbose -ErrorAction 'Stop'
Add comment 224 Plus }
Add comment 225 Plus catch {
Add comment 226 Plus throw "Could not create release artifact [$releasePath] using manifest version [$manifestVersion]"
Add comment 227 Plus }
Add comment 228 Plus
Add comment 229 Plus Write-Output "`nFINISHED: Release artifact creation."
Add comment 230 Plus }
Add comment 145 231