-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickpath.build.ps1
More file actions
102 lines (78 loc) · 3.09 KB
/
quickpath.build.ps1
File metadata and controls
102 lines (78 loc) · 3.09 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
98
99
100
101
102
param(
[ValidateSet('Patch', 'Minor', 'Major')]
[string]$Increment = "Patch",
[string]$Output = "Normal"
)
. $PSScriptRoot/private/Update-QuickPath.ps1
function Update-Version {
$psd1Path = 'quickpath.psd1'
if (-not (Test-Path $psd1Path)) {
throw "Manifest file not found at $psd1Path"
}
# Load the .psd1 manifest file
$moduleManifest = Import-PowerShellDataFile -Path $psd1Path
# Extract the current version
$versionString = $moduleManifest.ModuleVersion
$version = [Version]$versionString
# Increment the version based on the input
switch ($Increment) {
"major" { $newVersion = [Version]::new(($version.Major + 1), 0, 0) }
"minor" { $newVersion = [Version]::new($version.Major, ($version.Minor + 1), 0) }
default { $newVersion = [Version]::new($version.Major, $version.Minor, ($version.Build + 1)) }
}
Write-Host "Updating module version from $versionString to $newVersion"
# Replace the version in the manifest file
(Get-Content $psd1Path) -replace "ModuleVersion\s*=\s*'[^']+'", "ModuleVersion = '$newVersion'" |
Set-Content $psd1Path
}
task Clean {
Write-Host 'Cleaning output...'
Remove-Item -Force -Recurse -Path './output' -ErrorAction Ignore
}
task Build -Jobs Clean, {
Write-Host 'Building module...'
Update-Version
New-Item -Path './output/quickpath' -ItemType Directory -Force | Out-Null
Copy-Item -Path './quickpath.psd1' -Destination './output/quickpath/'
Copy-Item -Path './quickpath.psm1' -Destination './output/quickpath/'
New-Item -Path './output/quickpath/private' -ItemType Directory -Force | Out-Null
New-Item -Path './output/quickpath/classes' -ItemType Directory -Force | Out-Null
Copy-Item -Path './private/*' -Destination './output/quickpath/private/'
Copy-Item -Path './classes/*' -Destination './output/quickpath/classes/'
}
task Test {
Write-Host 'Running tests...'
$config = New-PesterConfiguration
$config.Run.Path = "."
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.OutputPath = "coverage.xml"
$config.CodeCoverage.OutputFormat = "JaCoCo"
$config.Output.Verbosity = $Output
$testResults = Invoke-Pester -Configuration $config
if ($testResults.Result.FailedCount -gt 0) {
Write-Error "Pester tests failed!"
Exit 1
}
}
task Package -Jobs Build, {
Write-Host 'Packaging module...'
Compress-Archive -Path './output/quickpath/*' -DestinationPath './output/quickpath.zip'
}
task Publish -Jobs Package, {
Write-Host 'Publish module...'
$apiKey = $env:NUGET_API_KEY
if (-not $apiKey) {
throw "NuGet API Key is not set. Please set the NUGET_API_KEY environment variable."
}
Publish-Module -Path '.\output\quickpath' -NuGetApiKey $apiKey
}
task Refresh -Jobs Build, {
Write-Host 'Refreshing module...'
Remove-Module quickpath -Force -ErrorAction SilentlyContinue
Import-Module './output/quickpath/quickpath.psd1' -Force
}
task Update -Jobs Build, Test, {
Write-Host 'Updating module...'
Update-QuickPath
}
task . Clean, Build, Test, Package