Skip to content

Commit 286c5bb

Browse files
authored
🚀 Refactor CI Pipeline (#362)
* 🚀 Refactor pipeline yml * ♻️ 🚀 Remove PSake Refactored pipeline to handle steps on its own, so we can drop PSake. Also moved the build module steps to their own job so it's not tied to one of the test run jobs and is clearly marked in pipeline runs * 🚀 Skip whole changelog stage If the changelog stage doesn't need to run, skip it entirely so it displays in the Azure UI as being skipped. * 🚀 Move gallery publish to separate job
1 parent 78637a0 commit 286c5bb

File tree

8 files changed

+277
-222
lines changed

8 files changed

+277
-222
lines changed

Build/Build-Module.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Grab nuget bits, set build variables, start build.
2+
Get-PackageProvider -Name NuGet -ForceBootstrap > $null
3+
4+
Set-BuildEnvironment
5+
6+
$Lines = '-' * 70
7+
8+
Write-Host $Lines
9+
Write-Host "STATUS: Generating External Help and Building Module"
10+
Write-Host $Lines
11+
12+
# Load the module, read the exported functions, update the psd1 FunctionsToExport
13+
Set-ModuleFunction
14+
15+
# Bump the module version if we didn't already
16+
try {
17+
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
18+
19+
$GalleryVersion = Get-NextNugetPackageVersion -Name $env:BHProjectName -ErrorAction Stop
20+
$GithubVersion = Get-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -ErrorAction Stop
21+
22+
if ($GalleryVersion -ge $GithubVersion) {
23+
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $GalleryVersion -ErrorAction Stop
24+
}
25+
}
26+
catch {
27+
Write-Host "Failed to update version for '$env:BHProjectName': $_."
28+
Write-Host "Continuing with existing version."
29+
}
30+
31+
# Build external help files from Platyps MD files
32+
New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en-us"
33+
34+
$BuiltModuleFolder = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/Module/"
35+
Write-Host "##vso[task.setvariable variable=BuiltModuleFolder]$BuiltModuleFolder"
36+
37+
New-Item -Path $BuiltModuleFolder -ItemType Directory
38+
Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModuleFolder -Recurse -PassThru

Build/Build.ps1

Lines changed: 0 additions & 15 deletions
This file was deleted.

Build/Initialize-Environment.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Get-PackageProvider -Name NuGet -ForceBootstrap > $null
2+
3+
Set-BuildEnvironment
4+
5+
$ProjectRoot = Resolve-Path -Path "$PSScriptRoot/.."
6+
Write-Host "##vso[task.setvariable variable=ProjectRoot]$ProjectRoot"
7+
8+
$Lines = '-' * 70
9+
10+
Write-Host $Lines
11+
Write-Host "Repository Branch: $env:BUILD_SOURCEBRANCHNAME ($env:BUILD_SOURCEBRANCH)"
12+
Write-Host "Build System Details:"
13+
Get-Item 'Env:BH*' | Out-String | Write-Host
14+
Write-Host $Lines

Build/Invoke-ModuleTests.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
$Lines = '-' * 70
2+
$PSVersion = $PSVersionTable.PSVersion
3+
4+
Write-Host $Lines
5+
Write-Host "STATUS: Testing with PowerShell v$($PSVersionTable.PSVersion)"
6+
Write-Host $Lines
7+
8+
# Import the module and add temporary entry to PSModulePath for build/test purposes
9+
$env:PSModulePath = @(
10+
$env:PROJECTROOT
11+
$env:PSModulePath
12+
) -join [IO.Path]::PathSeparator
13+
14+
Import-Module 'PSKoans'
15+
16+
$Timestamp = Get-Date -Format "yyyyMMdd-hhmmss"
17+
$TestFile = "PS${PSVersion}_${TimeStamp}_PSKoans.TestResults.xml"
18+
$CodeCoverageFile = "PS${PSVersion}_${TimeStamp}_PSKoans.CodeCoverage.xml"
19+
20+
$ModuleFolders = @(
21+
Get-Item -Path "$env:PROJECTROOT/PSKoans"
22+
Get-ChildItem -Path "$env:PROJECTROOT/PSKoans" -Directory -Recurse |
23+
Where-Object { 'Koans' -notin $_.Parent.Name, $_.Parent.Parent.Name }
24+
).FullName -join ';'
25+
26+
# Tell Azure where the test results & code coverage files will be
27+
Write-Host "##vso[task.setvariable variable=TestResults]$TestFile"
28+
Write-Host "##vso[task.setvariable variable=CodeCoverageFile]$CodeCoverageFile"
29+
Write-Host "##vso[task.setvariable variable=SourceFolders]$ModuleFolders"
30+
31+
# Gather test results. Store them in a variable and file
32+
$PesterParams = @{
33+
Path = "$env:PROJECTROOT/Tests"
34+
PassThru = $true
35+
OutputFormat = 'NUnitXml'
36+
OutputFile = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$TestFile"
37+
Show = "Header", "Failed", "Summary"
38+
CodeCoverage = (Get-ChildItem -Recurse -Path "$env:PROJECTROOT/PSKoans" -Filter '*.ps*1' -Exclude '*.Koans.ps1').FullName
39+
CodeCoverageOutputFile = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$CodeCoverageFile"
40+
}
41+
$TestResults = Invoke-Pester @PesterParams
42+
43+
# If tests failed, write errors and exit
44+
if ($TestResults.FailedCount -gt 0) {
45+
Write-Error "Failed $($TestResults.FailedCount) tests; build failed!"
46+
exit $TestResults.FailedCount
47+
}

Build/Psake.ps1

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)