-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.ps1
90 lines (77 loc) · 3.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
[cmdletbinding(DefaultParameterSetName = 'task')]
param(
[parameter(ParameterSetName = 'task', Position = 0)]
[string[]]$Task = 'default',
[parameter(ParameterSetName = 'help')]
[switch]$Help,
[switch]$UpdateModules
)
function Resolve-Module {
[Cmdletbinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)]
[string[]]$Name,
[switch]$UpdateModules
)
begin {
Get-PackageProvider -Name Nuget -ForceBootstrap -Verbose:$false | Out-Null
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -Verbose:$false
$PSDefaultParameterValues = @{
'*-Module:Verbose' = $false
'Install-Module:ErrorAction' = 'Stop'
'Install-Module:Force' = $true
'Install-Module:Scope' = 'CurrentUser'
'Install-Module:Verbose' = $false
'Install-Module:AllowClobber' = $true
'Import-Module:ErrorAction' = 'Stop'
'Import-Module:Verbose' = $false
'Import-Module:Force' = $true
}
}
process {
foreach ($moduleName in $Name) {
$versionToImport = ''
Write-Verbose -Message "Resolving Module [$($moduleName)]"
if ($Module = Get-Module -Name $moduleName -ListAvailable -Verbose:$false) {
# Determine latest version on PSGallery and warn us if we're out of date
$latestLocalVersion = ($Module | Measure-Object -Property Version -Maximum).Maximum
$latestGalleryVersion = (Find-Module -Name $moduleName -Repository PSGallery |
Measure-Object -Property Version -Maximum).Maximum
# Are we out of date?
if ($latestLocalVersion -lt $latestGalleryVersion) {
if ($UpdateModules) {
Write-Verbose -Message "$($moduleName) installed version [$($latestLocalVersion.ToString())] is outdated. Installing gallery version [$($latestGalleryVersion.ToString())]"
if ($UpdateModules) {
Install-Module -Name $moduleName -RequiredVersion $latestGalleryVersion
$versionToImport = $latestGalleryVersion
}
} else {
Write-Warning "$($moduleName) is out of date. Latest version on PSGallery is [$latestGalleryVersion]. To update, use the -UpdateModules switch."
}
} else {
$versionToImport = $latestLocalVersion
}
} else {
Write-Verbose -Message "[$($moduleName)] missing. Installing..."
Install-Module -Name $moduleName -Repository PSGallery
$versionToImport = (Get-Module -Name $moduleName -ListAvailable | Measure-Object -Property Version -Maximum).Maximum
}
Write-Verbose -Message "$($moduleName) installed. Importing..."
if (-not [string]::IsNullOrEmpty($versionToImport)) {
Import-module -Name $moduleName -RequiredVersion $versionToImport
} else {
Import-module -Name $moduleName
}
}
}
}
'BuildHelpers', 'psake', 'PSDeploy' | Resolve-Module -UpdateModules:($PSBoundParameters.ContainsKey('UpdateModules'))
if ($PSBoundParameters.ContainsKey('help')) {
Get-PSakeScriptTasks -buildFile "$PSScriptRoot\psake.ps1" |
Sort-Object -Property Name |
Format-Table -Property Name, Description, Alias, DependsOn
} else {
Set-BuildEnvironment -Force
Invoke-psake -buildFile "$PSScriptRoot\psake.ps1" -taskList $Task -nologo -Verbose:($VerbosePreference -eq 'Continue')
exit ( [int]( -not $psake.build_success ) )
}