-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathModuleFast.build.ps1
More file actions
111 lines (91 loc) · 3.52 KB
/
Copy pathModuleFast.build.ps1
File metadata and controls
111 lines (91 loc) · 3.52 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
103
104
105
106
107
108
109
110
111
#requires -version 7.6
[CmdletBinding(ConfirmImpact = 'High')]
param(
#Specify this to explicitly specify the version of the package
[Management.Automation.SemanticVersion]$Version = '0.0.0-SOURCE',
#You Generally do not need to modify these
$Destination = (Join-Path $PSScriptRoot 'Artifacts'),
$ModuleOutFolderPath = (Join-Path $Destination 'Module'),
$TempPath = (Resolve-Path temp:).ProviderPath + '\ModuleFastBuild',
# Build for release (don't include debug headers)
[switch]$Release,
$PowerShellProjectPath = (Join-Path $PSScriptRoot 'Source' 'PowerShell' 'PowerShell.csproj'),
# Filter for test names
$TestName
)
$ErrorActionPreference = 'Stop'
$buildMode = $Release ? 'release' : 'debug'
# Short for common Parameters, we are using a short name here to keep the commands short
$c = @{
ErrorAction = 'Stop'
Verbose = $VerbosePreference -eq 'Continue'
Debug = $DebugPreference -eq 'Continue'
}
if ($DebugPreference -eq 'Continue') {
$c.Confirm = $false
}
Task Clean {
Write-Build -Color DarkCyan "Cleaning $Destination"
exec { git clean -fdX $Destination }
}
Task BuildCSharp {
# Build the PowerShell module project (which depends on Core)
exec { dotnet build $PowerShellProjectPath --nologo -c $buildMode }
}
Task Publish {
exec { & dotnet publish $PowerShellProjectPath -c $buildMode }
}
Task CopyFiles {
New-Item -ItemType Directory -Path $ModuleOutFolderPath -Force | Out-Null
Copy-Item @c -Path @(
'ModuleFast.psd1'
'ModuleFast.psm1'
'ModuleFast.Format.ps1xml'
'LICENSE'
) -Destination $ModuleOutFolderPath
Copy-Item @c -Path 'ModuleFast.ps1' -Destination $Destination
# Copy DLL and its dependencies from Artifacts Output to the module bin folder
$artifactsBinPath = Join-Path $Destination 'publish' 'PowerShell' $buildMode
Copy-Item @c -Path (Join-Path $artifactsBinPath '*') -Destination $ModuleOutFolderPath -Recurse -Force
}
Task Version {
#This task only runs if a custom version is needed
if (-not $Version) { return }
$moduleVersion, $prerelease = $Version -split '-'
$manifestPath = Join-Path $ModuleOutFolderPath 'ModuleFast.psd1'
$manifestContent = (Get-Content -Raw $manifestPath) -replace [regex]::Escape('ModuleVersion = ''0.0.0'''), "ModuleVersion = '$moduleVersion'" -replace [regex]::Escape('Prerelease = ''SOURCE'''), ($Prerelease ? "Prerelease = '$prerelease'" : '')
$manifestContent | Set-Content -Path $manifestPath
}
Task Package.Nuget {
Compress-PSResource @c -Path $ModuleOutFolderPath -DestinationPath $Destination
}
Task Package.Zip {
$zipPath = Join-Path $Destination "ModuleFast.${Version}.zip"
if (Test-Path $zipPath) {
Remove-Item @c -Path $zipPath
}
Compress-Archive @c -Path $ModuleOutFolderPath -DestinationPath $zipPath
}
Task Pester {
#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.
$result = Start-Job {
$TestFilter = $using:TestName
if ($TestFilter) {
Write-Host -ForegroundColor DarkCyan "Only Running Tests Containing: $TestFilter"
$TestFilter = '*' + $TestFilter + '*'
}
$ProgressPreference = 'SilentlyContinue'
Invoke-Pester -PassThru -FullNameFilter $TestFilter
} | Receive-Job -Wait -AutoRemoveJob
assert ($result.FailedCount -eq 0) "$($result.FailedCount) Pester tests failed."
}
Task Package Package.Nuget, Package.Zip
#Supported High Level Tasks
Task Build @(
'Publish'
'CopyFiles'
'Version'
)
Task Test Build, Pester
Task . Build, Test, Package
Task BuildNoTest Build, Package