This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
build.ps1
57 lines (48 loc) · 2.33 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
# Source: https://github.com/devblackops/POSHOrigin/blob/master/build.ps1
[cmdletbinding()]
param(
[string[]]$Task = 'Pre-Commit'
)
if ($IsWindows) {
if ( -not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator") ) {
Write-Error "Build Script Requires Admin Rights"
break;
}
}
function Resolve-Module {
[Cmdletbinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)]
[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 -Verbose:$false |
Measure-Object -Property Version -Maximum |
Select-Object -ExpandProperty Maximum
if ($Version -lt $GalleryVersion) {
Write-Verbose -Message "$($ModuleName) Installed Version [$($Version.tostring())] is outdated. Installing Gallery Version [$($GalleryVersion.tostring())]"
Install-Module -Name $ModuleName -Verbose:$false -Force -Repository PSGallery
Import-Module -Name $ModuleName -Verbose:$false -Force -RequiredVersion $GalleryVersion
}
else {
Write-Verbose -Message "Module Installed, Importing [$($ModuleName)]"
Import-Module -Name $ModuleName -Verbose:$false -Force -RequiredVersion $Version
}
}
else {
Write-Verbose -Message "[$($ModuleName)] Missing, installing Module"
Install-Module -Name $ModuleName -Verbose:$false -Force -Repository PSGallery
Import-Module -Name $ModuleName -Verbose:$false -Force -RequiredVersion $Version
}
}
}
}
Get-PackageProvider -Name Nuget -ForceBootstrap | Out-Null
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
'BuildHelpers', 'InvokeBuild', 'Pester', 'PSDeploy', 'PSScriptAnalyzer', 'PlatyPS' | Resolve-Module
Invoke-Build $Task