-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
98 lines (82 loc) · 3.99 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
[CmdletBinding()]
Param (
$Task = 'test',
# skips the initialization of the environment, which can be slow, and jumps
# straight to the build script
[switch]
$Bootstrap
)
function Test-Administrator {
if ($PSVersionTable.Platform -ne 'Unix') {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
} else {
# TODO: We are running in Linux so assume (at this stage) we have root / Admin - this needs resolved
$true
}
}
if ($Bootstrap.IsPresent) {
$dependencies = @{
InvokeBuild = 'latest'
Configuration = 'latest'
PowerShellBuild = 'latest'
Pester = 'latest'
PSScriptAnalyzer = 'latest'
PSPesterTestHelpers = 'latest' # I don't trust this Warren guy...
PSDeploy = 'latest' # Maybe pin the version in case he breaks this...
PSTodoTxt = 'latest'
}
# dependencies
if (-not (Get-Command -Name 'Get-PackageProvider' -ErrorAction SilentlyContinue)) {
$null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Write-Verbose 'Bootstrapping NuGet package provider.'
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
} elseif ((Get-PackageProvider).Name -notcontains 'nuget') {
Write-Verbose 'Bootstrapping NuGet package provider.'
Get-PackageProvider -Name NuGet -ForceBootstrap
}
# Trust the PSGallery is needed
if ((Get-PSRepository -Name PSGallery).InstallationPolicy -ne 'Trusted') {
Write-Verbose "Trusting PowerShellGallery."
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
}
# install Chocolatey and apps if this is the Desktop edition or Core on Windows
if ($PSVersionTable.PSEdition -eq 'Desktop' -or
($PSVersionTable.PSEdition -eq 'Core' -and $PSVersionTable.Platform -eq 'Win32NT') -and
(-not (Get-Command -Name 'choco.exe' -ErrorAction SilentlyContinue))) {
# install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Import-Module C:\ProgramData\chocolatey\helpers\chocolateyProfile.psm1
refreshenv
choco.exe install git -y
}
Install-Module -Name PSDepend
if (Test-Administrator) {
$dependencies | Invoke-PSDepend -Import -Install -Force
} else {
Write-Warning "Not running as Administrator - could not initialize build environment."
}
# Configure git
if ($null -eq (Invoke-Expression -Command 'git config --get user.email')) {
Write-Verbose 'Git is not configured so we need to configure it now.'
git config --global user.email "[email protected]"
git config --global user.name "pauby"
git config --global core.safecrlf false
}
}
# # Used in Pester tests to import the built module and not a module already installed on the system
# function global:Import-HelperModuleForTesting {
# # build the filename
# $moduleScript = "{0}\{1}.psm1" -f $env:BHBuildOutput, $env:BHProjectName
# if (Test-Path -Path $moduleScript) {
# Remove-Module -Name $moduleScript -ErrorAction SilentlyContinue
# Import-Module -Name $moduleScript -Force -ErrorAction Stop
# $importedModule = Get-Module -Name $env:BHProjectName
# Write-Verbose "Imported module '$($importedModule.Path)'"
# } else {
# throw "Module manifest '$moduleScript' does not exist!"
# }
# }
Write-Host "Tag : $($env:CI_COMMIT_TAG)`nBranch : $($env:CI_COMMIT_REF_NAME)"
Invoke-Build -File .\.pstodowarrior.build.ps1 -Task $Task -Verbose:$VerbosePreference
Remove-Item function:Import-HelpersModuleForTesting -ErrorAction SilentlyContinue