1
+ # requires -version 7.2
1
2
[CmdletBinding (ConfirmImpact = ' High' )]
2
3
param (
4
+ # Specify this to explicitly specify the version of the package
5
+ [Management.Automation.SemanticVersion ]$Version = ' 0.0.0-SOURCE' ,
6
+ # You Generally do not need to modify these
3
7
$Destination = (Join-Path $PSScriptRoot ' Build' ),
4
8
$ModuleOutFolderPath = (Join-Path $Destination ' ModuleFast' ),
5
9
$TempPath = (Resolve-Path temp:).ProviderPath + ' \ModuleFastBuild' ,
@@ -36,8 +40,17 @@ Task CopyFiles {
36
40
' ModuleFast.psm1'
37
41
' LICENSE'
38
42
) - Destination $ModuleOutFolderPath
43
+ Copy-Item @c - Path ' ModuleFast.ps1' - Destination $Destination
44
+ }
45
+
46
+ Task Version {
47
+ # This task only runs if a custom version is needed
48
+ if (-not $Version ) { return }
39
49
40
- Copy-Item ' ModuleFast.ps1' - Destination $Destination - Force
50
+ $moduleVersion , $prerelease = $Version -split ' -'
51
+ $manifestPath = Join-Path $ModuleOutFolderPath ' ModuleFast.psd1'
52
+ $manifestContent = (Get-Content - Raw $manifestPath ) -replace [regex ]::Escape(' ModuleVersion = '' 0.0.0'' ' ), " ModuleVersion = '$moduleVersion '" -replace [regex ]::Escape(' Prerelease = '' SOURCE'' ' ), ($Prerelease ? " Prerelease = '$prerelease '" : ' ' )
53
+ $manifestContent | Set-Content - Path $manifestPath
41
54
}
42
55
43
56
Task GetNugetVersioningAssembly {
@@ -63,8 +76,8 @@ Task Build @(
63
76
' AddNugetVersioningAssemblyRequired'
64
77
)
65
78
66
- Task Package {
67
- [string ]$repoName = " ModuleFastBuild-" + (New-Guid )
79
+ Task Package.Nuget {
80
+ [string ]$repoName = ' ModuleFastBuild-' + (New-Guid )
68
81
Get-ChildItem $ModuleOutFolderPath - Recurse - Include ' *.nupkg' | Remove-Item @c - Force
69
82
try {
70
83
Register-PSResourceRepository - Name $repoName - Uri $NugetOutFolderPath - ApiVersion local
@@ -74,5 +87,32 @@ Task Package {
74
87
}
75
88
}
76
89
90
+ Task Package.Zip {
91
+ $zipPath = Join-Path $Destination " ModuleFast.${Version} .zip"
92
+ if (Test-Path $zipPath ) {
93
+ Remove-Item @c - Path $zipPath
94
+ }
95
+ Compress-Archive @c - Path $ModuleOutFolderPath - DestinationPath $zipPath
96
+ }
97
+
98
+ Task Pester {
99
+ # Run this in a separate job so as not to lock any NuGet DLL packages for future runs. Runspace would lock the package to this process still.
100
+ Start-Job {
101
+ Invoke-Pester
102
+ } | Receive-Job - Wait - AutoRemoveJob
103
+ }
104
+
105
+ Task Package Package.Nuget, Package.Zip
106
+
107
+ # Supported High Level Tasks
108
+ Task Build @ (
109
+ ' Clean'
110
+ ' CopyFiles'
111
+ ' Version'
112
+ ' GetNugetVersioningAssembly'
113
+ ' AddNugetVersioningAssemblyRequired'
114
+ )
115
+
116
+ Task Test Build, Pester
77
117
Task . Build, Test, Package
78
118
Task BuildNoTest Build, Package
0 commit comments