-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsakefile.ps1
More file actions
97 lines (85 loc) · 2.76 KB
/
psakefile.ps1
File metadata and controls
97 lines (85 loc) · 2.76 KB
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
Properties {
$ProjectRoot = Resolve-Path $PSScriptRoot
$ModuleRoot = (Get-ChildItem -Recurse -Filter *.psm1 | Select-Object -First 1).DirectoryName
}
TaskSetup {
Write-Output "".PadRight(70, '-')
}
Task Default -depends Test
Task Init {
Set-Location $ProjectRoot
Set-BuildEnvironment
"Build System Details:"
Get-Item ENV:BH*
}
Task Test -depends Init {
# Pester
Import-Module Pester
$PesterConf = [PesterConfiguration]@{
Run = @{
Path = "$ProjectRoot\Tests"
PassThru = $true
}
TestResult = @{
Enabled = $true
OutputPath = ("{0}\Unit.Tests.xml" -f $ProjectRoot)
OutputFormat = "NUnitXml"
}
}
$TestResults = Invoke-Pester -Configuration $PesterConf
If ($TestResults.FailedCount -gt 0) {
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed" -ErrorAction Stop
}
# PSScriptAnalyzer
Invoke-ScriptAnalyzer -Path (Join-Path $ModuleRoot *.ps1) -Recurse -OutVariable issues
$errors = $issues.Where({ $_.Severity -eq 'Error' })
$warnings = $issues.Where({ $_.Severity -eq 'Warning' })
if ($errors) {
Write-Error "There were $($errors.Count) errors and $($warnings.Count) warnings total." -ErrorAction Stop
} else {
Write-Output "There were $($errors.Count) errors and $($warnings.Count) warnings total."
}
}
Task Build -depends Test {
Write-Output "Updating Module Manifest:"
$ManifestData = Import-PowerShellDataFile -Path (Get-ChildItem -Path $ModuleRoot -Filter '*.psd1').FullName
# FunctionsToExport, AliasesToExport; from BuildHelpers
Write-Output "-Functions"
Set-ModuleFunction
Write-Output "-Aliases"
Set-ModuleAlias
# Version from Tag/CI
$pattern = '(\d+(\.\d+)+)?$'
if ($env:BHBranchName -match $pattern) {
[Version] $Ver = $Matches[0]
} else {
[Version] $Ver = Get-Metadata -Path $env:BHPSModuleManifest -PropertyName 'ModuleVersion'
}
if ($env:GITHUB_RUNNUMBER) {
$Build = $env:GITHUB_RUNNUMBER
} else {
$Build = $Env:BHBuildNumber
}
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName 'ModuleVersion' -Value (@($Ver.Major, $Ver.Minor, $Build) -join '.')
Write-Output ("-Version {0}" -f $Ver.ToString())
# Prerelease
If ($env:BHBranchName -match 'tags') {
Write-Output "-Release Metadata"
# Remove "Prerelease" from Manifest
Set-Content -Path $env:BHPSModuleManifest -Value (Get-Content -Path $env:BHPSModuleManifest | Select-String -Pattern 'Prerelease' -NotMatch)
} else {
Write-Output "-Prerelease Metadata"
# Update Prerelease Version
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName Prerelease -Value "PRE$(($env:BHCommitHash).Substring(0,7))"
}
}
Task Publish -depends Build {
$publishParams = @{
Path = $ModuleRoot
NuGetApiKey = $env:NuGetApiKey
}
if ($Repository) {
$publishParams['Repository'] = $Repository
}
Publish-Module @publishParams
}