-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.ps1
103 lines (93 loc) · 4 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
91
92
93
94
95
96
97
98
99
100
101
102
103
# Helper function
function Resolve-Module
{
<#
.SYNOPSIS
Function to verify that you are using the last version of the modules used in this script
.DESCRIPTION
Function to verify that you are using the last version of the modules used in this script
It is getting the module from the local machine (if present) and compare with the one on the Gallery,
and download/install the last version if needed
.NOTES
Copied from PSDeploy Project
https://raw.githubusercontent.com/RamblingCookieMonster/PSDeploy/master/build.ps1
#>
[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
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
Import-Module -Name $ModuleName -Force -RequiredVersion $Version
}
}
}
}
#---------------------------------#
# Header #
#---------------------------------#
Write-Host 'Running AppVeyor build script' -ForegroundColor Yellow
Write-Host "Repository : $env:APPVEYOR_REPO_NAME"
Write-Host "ModuleName : $env:ModuleName"
Write-Host "Provider : $env:APPVEYOR_REPO_PROVIDER"
Write-Host "Branch : $env:APPVEYOR_REPO_BRANCH"
Write-Host ""
Write-Host "# BUILD #"
Write-Host " ID : $env:APPVEYOR_BUILD_ID"
Write-Host " Number : $env:APPVEYOR_BUILD_NUMBER"
Write-Host " Version : $env:APPVEYOR_BUILD_VERSION"
Write-Host " Folder : $env:APPVEYOR_BUILD_FOLDER"
Write-Host ""
Write-Host "# COMMIT #"
Write-Host " ID (SHA) : $env:APPVEYOR_REPO_COMMIT"
Write-Host " Author : $env:APPVEYOR_REPO_COMMIT_AUTHOR"
Write-Host " Author Email : $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL"
Write-Host " Date/Time : $env:APPVEYOR_REPO_COMMIT_TIMESTAMP"
Write-Host " Message : $env:APPVEYOR_REPO_COMMIT_MESSAGE"
Write-Host " Additional msg: $env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED"
#---------------------------------#
# BuildScript #
#---------------------------------#
Write-Verbose -Message "Loading Nuget Package Provider"
# Grab nuget bits, install modules, set build variables, start build.
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
Write-Verbose -Message "Verify if we have the last version of Psake,PSDeploy, Pester, BuildHelpers"
Resolve-Module Psake, PSDeploy, Pester, BuildHelpers
# PSDeploy - Set the Build variables
Set-BuildEnvironment
# Invoke the PSake tasks
Invoke-psake .\psake.ps1
exit ( [int]( -not $psake.build_success ) )
<#
Write-host "Get BuildVariables" -ForegroundColor Yellow
Get-BuildVariables
Write-host "Get-ProjectName" -ForegroundColor Yellow
Get-ProjectName
#>