-
Notifications
You must be signed in to change notification settings - Fork 5
/
ModuleFast.build.ps1
104 lines (90 loc) · 3.57 KB
/
ModuleFast.build.ps1
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
#requires -version 7.2
[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 'Build'),
$ModuleOutFolderPath = (Join-Path $Destination 'ModuleFast'),
$TempPath = (Resolve-Path temp:).ProviderPath + '\ModuleFastBuild',
$LibPath = (Join-Path $ModuleOutFolderPath 'lib' 'netstandard2.0'),
$NugetVersioning = '6.8.0',
$NugetOutFolderPath = $Destination
)
$ErrorActionPreference = 'Stop'
# 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 {
foreach ($Path in $Destination, $NugetOutFolderPath, $ModuleOutFolderPath, $TempPath, $LibPath) {
if (Test-Path $Path) {
Remove-Item @c -Recurse -Force -Path $Path/*
} else {
New-Item @c -Type Directory -Path $Path | Out-Null
}
}
}
Task CopyFiles {
Copy-Item @c -Path @(
'ModuleFast.psd1'
'ModuleFast.psm1'
'LICENSE'
) -Destination $ModuleOutFolderPath
Copy-Item @c -Path 'ModuleFast.ps1' -Destination $Destination
}
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 GetNugetVersioningAssembly {
PackageManagement\Install-Package @c -Name Nuget.Versioning -RequiredVersion $NuGetVersioning -Destination $tempPath -Force | Out-Null
Copy-Item @c -Path "$tempPath/NuGet.Versioning.$NuGetVersioning/lib/netstandard2.0/NuGet.Versioning.dll" -Destination $libPath -Recurse -Force
}
Task AddNugetVersioningAssemblyRequired {
(Get-Content -Raw -Path $ModuleOutFolderPath\ModuleFast.psd1) -replace [Regex]::Escape('# RequiredAssemblies = @()'), 'RequiredAssemblies = @(".\lib\netstandard2.0\NuGet.Versioning.dll")' | Set-Content -Path $ModuleOutFolderPath\ModuleFast.psd1
}
Task Package.Nuget {
[string]$repoName = 'ModuleFastBuild-' + (New-Guid)
Get-ChildItem $ModuleOutFolderPath -Recurse -Include '*.nupkg' | Remove-Item @c -Force
try {
Register-PSResourceRepository -Name $repoName -Uri $NugetOutFolderPath -ApiVersion local
Publish-PSResource -Repository $repoName -Path $ModuleOutFolderPath
} finally {
Unregister-PSResourceRepository -Name $repoName
}
}
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.
Start-Job {
Invoke-Pester
} | Receive-Job -Wait -AutoRemoveJob
}
Task Package Package.Nuget, Package.Zip
#Supported High Level Tasks
Task Build @(
'Clean'
'CopyFiles'
'Version'
'GetNugetVersioningAssembly'
'AddNugetVersioningAssemblyRequired'
)
Task Test Build, Pester
Task . Build, Test, Package
Task BuildNoTest Build, Package