-
Notifications
You must be signed in to change notification settings - Fork 24
/
build.ps1
67 lines (57 loc) · 2.15 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
#requires -version 5
using namespace System.IO
<#
.SYNOPSIS
Bootstraps Invoke-Build and starts it with supplied parameters.
.NOTES
If you already have Invoke-Build installed, just use Invoke-Build instead of this script. This is for CI/CD environments like Appveyor, Jenkins, or Azure DevOps pipelines.
.EXAMPLE
.\build.ps1
Starts Invoke-Build with the default parameters
#>
$ErrorActionPreference = 'Stop'
#Add TLS 1.2 to potential security protocols on Windows Powershell. This is now required for powershell gallery
if ($PSEdition -eq 'Desktop') {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 'Tls12'
}
function BootstrapModule {
param (
$ModuleSpecification,
$Path = (Join-Path ([Environment]::GetFolderPath('LocalApplicationData')) 'Press')
)
$vEnvDir = New-Item -ItemType Directory -Force -Path $Path
$env:PSModulePath = $vEnvDir,$env:PSModulePath -join [io.path]::PathSeparator
#This is done for performance. If the module is found loaded it won't try to search filesystem
$existingModule = (Get-Module -FullyQualifiedName $moduleSpecification -ErrorAction SilentlyContinue)
if (-not $existingModule) {
$existingModule = (Get-Module -ListAvailable -FullyQualifiedName $moduleSpecification -ErrorAction SilentlyContinue)
}
if ($existingModule) {
Write-Verbose "Module $($moduleSpecification.ModuleName) was detected. Skipping bootstrap."
return
}
$moduleParams = @{
Name = $moduleSpecification.ModuleName
MinimumVersion = $moduleSpecification.ModuleVersion
MaximumVersion = $moduleSpecification.MaximumVersion
Force = $true
ErrorAction = 'Stop'
}
Write-Verbose "$($ModuleSpecification.ModuleName) not found locally. Bootstrapping..."
Save-Module @moduleParams -Path $vEnvDir
Import-Module @moduleParams
}
BootstrapModule @{
ModuleName = 'InvokeBuild'
ModuleVersion = '5.5.7'
MaximumVersion = '5.99.99'
}
#Passthrough Invoke-Build
Push-Location $PSScriptRoot
try {
Invoke-Expression "Invoke-Build $($args -join ' ')"
} catch {
throw $PSItem
} finally {
Pop-Location
}