forked from AutomatedLab/AutomatedLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.ps1
82 lines (67 loc) · 3.64 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
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 -SkipPublisherCheck -AllowClobber
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 -AllowClobber
Import-Module -Name $moduleName -Force
}
}
}
}
# Grab nuget bits, install modules, set build variables, start build.
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
# Resolve Module will fail since AL requests interactivity, importing module fails without LabSources folder
[System.Environment]::SetEnvironmentVariable('AUTOMATEDLAB_TELEMETRY_OPTOUT',0, 'Machine')
$env:AUTOMATEDLAB_TELEMETRY_OPTOUT = 0
$f = New-Item -ItemType Directory -Path C:\LabSources\CustomRoles -Force
Resolve-Module -Name Psake, PSDeploy, Pester, BuildHelpers, AutomatedLab, Ships, PSFramework
$lastestVersion = Get-Module -Name PackageManagement -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
if (-not ($lastestVersion.Version -ge '1.1.7.0'))
{
Write-Host "Latest Version of 'PackageManagement' is '$($lastestVersion.Version)'. Updating to the latest version on the PowerShell Gallery"
Install-Module -Name PackageManagement -RequiredVersion 1.1.7.0 -Force -Confirm:$false #-Verbose
Remove-Module -Name PackageManagement -Force -ErrorAction Ignore
$m = Import-Module -Name PackageManagement -PassThru
Write-Host "New version of 'PackageManagement' is not $($m.Version)"
}
$lastestVersion = Get-Module -Name PowerShellGet -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
if (-not ($lastestVersion.Version -ge '1.6.0'))
{
Write-Host "Latest Version of 'PowerShellGet' is '$($lastestVersion.Version)'. Updating to the latest version on the PowerShell Gallery"
Install-Module -Name PowerShellGet -RequiredVersion 1.6.0 -Force -Confirm:$false #-Verbose
Remove-Module -Name PowerShellGet -Force -ErrorAction Ignore
$m = Import-Module -Name PowerShellGet -PassThru
Write-Host "New version of 'PowerShellGet' is not $($m.Version)"
}
Invoke-psake .\psake.ps1
exit ( [int]( -not $psake.build_success ) )