-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.ps1
90 lines (75 loc) · 2.69 KB
/
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
using namespace System.IO
using namespace System.Runtime.InteropServices
#Requires -Version 7.2
[CmdletBinding()]
param(
[Parameter()]
[ValidateSet('Debug', 'Release')]
[string]
$Configuration = 'Debug',
[Parameter()]
[ValidateSet('Build', 'Test')]
[string]
$Task = 'Build',
[Parameter()]
[Version]
$PowerShellVersion = $PSVersionTable.PSVersion,
[Parameter()]
[Architecture]
$PowerShellArch = [RuntimeInformation]::ProcessArchitecture,
[Parameter()]
[string]
$ModuleNupkg,
[Parameter()]
[Switch]
$Elevated
)
$ErrorActionPreference = 'Stop'
. ([Path]::Combine($PSScriptRoot, "tools", "common.ps1"))
$manifestPath = ([Path]::Combine($PSScriptRoot, 'manifest.psd1'))
$Manifest = [Manifest]::new($Configuration, $PowerShellVersion, $PowerShellArch, $manifestPath)
if ($ModuleNupkg) {
Write-Host "Expanding module nupkg to '$($Manifest.ReleasePath)'" -ForegroundColor Cyan
Expand-Nupkg -Path $ModuleNupkg -DestinationPath $Manifest.ReleasePath
}
Write-Host "Installing PowerShell dependencies" -ForegroundColor Cyan
$deps = $Task -eq 'Build' ? $Manifest.BuildRequirements : $Manifest.TestRequirements
$deps | Install-BuildDependencies
if ($Elevated) {
# To avoid the parent runner locking these files on build, copy them to a temporary location.
$moduleSource = [Path]::Combine($PSScriptRoot, "output", "ProcessEx")
$tempModulePath = [Path]::Combine($PSScriptRoot, "output", "Modules", "ProcessEx")
if ((Test-Path -LiteralPath $moduleSource) -and (Test-Path -LiteralPath $tempModulePath)) {
Remove-Item -LiteralPath $tempModulePath -Recurse -Force
}
if (-not (Test-Path -Literal $moduleSource)) {
throw "Cannot elevate build runner without building project first"
}
Copy-Item -LiteralPath $moduleSource -Destination $tempModulePath -Recurse
Import-Module -Name $tempModulePath
Import-Module -Name ([Path]::Combine($PSScriptRoot, "output", "Modules", "PSPrivilege"))
$elevatedArguments = @(
'-File', $PSCommandPath,
'-Configuration', $Configuration
'-Task', $Task
'-PowerShellVersion', $PowerShellVersion
'-PowerShellArch', $PowerShellArch
if ($ModuleNupkg) {
'-ModuleNupkg', $ModuleNupkg
}
)
$invokeSubProcessBuildSplat = @{
Executable = (Get-Process -Id $pid).Path
ArgumentList = $elevatedArguments
}
./tools/ElevatePrivileges.ps1 @invokeSubProcessBuildSplat
}
else {
$buildScript = [Path]::Combine($PSScriptRoot, "tools", "InvokeBuild.ps1")
$invokeBuildSplat = @{
Task = $Task
File = $buildScript
Manifest = $manifest
}
Invoke-Build @invokeBuildSplat
}