-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
66 lines (52 loc) · 2.57 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
[cmdletbinding()]
param(
[ValidateSet('Default', 'Build', 'Analyze', 'Test', 'WinZip')]
$Task = 'Default'
)
Write-Host "Importing Modules:" -ForegroundColor Yellow
$Modules = @('Psake', 'BuildHelpers', 'Pester', 'PSScriptAnalyzer', 'PSDeploy')
function Resolve-Module {
[Cmdletbinding()]
param
(
[Parameter(Mandatory)]
[string[]]$Name
)
Process {
foreach ($ModuleName in $Name) {
$Module = Get-Module -Name $ModuleName -ListAvailable
Write-Verbose -Message "Resolving Module $($ModuleName)"
if ($Module) {
$Version = $Module | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum
$GalleryVersion = Find-Module -Name $ModuleName -Repository PSGallery | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum
if ($Version -lt $GalleryVersion) {
if ((Get-PSRepository -Name PSGallery).InstallationPolicy -ne 'Trusted') { Set-PSRepository -Name PSGallery -InstallationPolicy Trusted }
Write-Verbose -Message "$($ModuleName) Installed Version [$($Version.tostring())] is outdated. Installing Gallery Version [$($GalleryVersion.tostring())]"
Install-Module -Name $ModuleName -Force -Scope CurrentUser -SkipPublisherCheck
Import-Module -Name $ModuleName -Force -RequiredVersion $GalleryVersion
}
else {
Write-Verbose -Message "Module Installed, Importing $($ModuleName)"
Import-Module -Name $ModuleName -Force -RequiredVersion $Version
}
}
else {
Write-Verbose -Message "$($ModuleName) Missing, installing Module"
Install-Module -Name $ModuleName -Force -Scope CurrentUser -SkipPublisherCheck
Import-Module -Name $ModuleName -Force -RequiredVersion $Version
}
}
}
}
# Grab nuget bits, install modules, set build variables, start build.
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
Resolve-Module $Modules
Write-Host "Completed Importing Modules`r`n" -ForegroundColor Green
Push-Location $PSScriptRoot
Write-Verbose "Cleaning current Build variables"
Get-ChildItem -Path env:\bh* | Remove-Item
Write-Verbose "Setting Build Variables"
Set-BuildEnvironment
Write-Host "Executing PSake Build`r`n" -ForegroundColor Green
Invoke-Psake -buildFile .\psake.ps1 -properties $PSBoundParameters -noLogo -taskList $Task
exit ( [int]( -not $psake.build_success ) )