forked from dsccommunity/DscWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.ps1
173 lines (138 loc) · 4.95 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
[CmdletBinding()]
param (
[string]
$BuildOutput = 'BuildOutput',
[string]
$ResourcesFolder = 'DscResources',
[string]
$ConfigDataFolder = 'DscConfigData',
[string]
$ConfigurationsFolder = 'DscConfigurations',
[string]
$TestFolder = 'Tests',
[ScriptBlock]
$Filter = {},
[int]
$CurrentJobNumber = 1,
[int]
$TotalJobCount = 1,
[string]
$Repository = 'PSGallery',
[uri]
$GalleryProxy,
[Parameter(Position = 0)]
$Tasks,
[switch]
$ResolveDependency,
[string]
$ProjectPath,
[switch]
$DownloadResourcesAndConfigurations,
[switch]
$Help,
[ScriptBlock]
$TaskHeader = {
Param($Path)
''
'=' * 79
Write-Build Cyan "`t`t`t$($Task.Name.Replace('_',' ').ToUpper())"
Write-Build DarkGray "$(Get-BuildSynopsis $Task)"
'-' * 79
Write-Build DarkGray " $Path"
Write-Build DarkGray " $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)"
''
}
)
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$env:BHBuildStartTime = Get-Date
Write-Host "Current Process ID is '$PID'"
#changing the path is required to make PSDepend run without internet connection. It is required to download nutget.exe once first:
#Invoke-WebRequest -Uri 'https://aka.ms/psget-nugetexe' -OutFile C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\nuget.exe -ErrorAction Stop
$pathElements = $env:Path -split ';'
$pathElements += 'C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet'
$env:Path = $pathElements -join ';'
#cannot be a default parameter value due to https://github.com/PowerShell/PowerShell/issues/4688
if (-not $ProjectPath) {
$ProjectPath = $PSScriptRoot
}
if (-not ([System.IO.Path]::IsPathRooted($BuildOutput))) {
$BuildOutput = Join-Path -Path $ProjectPath -ChildPath $BuildOutput
}
$buildModulesPath = Join-Path -Path $BuildOutput -ChildPath 'Modules'
if (-not (Test-Path -Path $buildModulesPath)) {
$null = mkdir -Path $buildModulesPath -Force
}
$configurationPath = Join-Path -Path $ProjectPath -ChildPath $ConfigurationsFolder
$resourcePath = Join-Path -Path $ProjectPath -ChildPath $ResourcesFolder
$configDataPath = Join-Path -Path $ProjectPath -ChildPath $ConfigDataFolder
$testsPath = Join-Path -Path $ProjectPath -ChildPath $TestFolder
$psModulePathElemets = $env:PSModulePath -split ';'
if ($buildModulesPath -notin $psModulePathElemets) {
$env:PSModulePath = $psModulePathElemets -join ';'
$env:PSModulePath += ";$buildModulesPath"
}
#importing all resources from 'Build' directory
Get-ChildItem -Path "$PSScriptRoot/Build" -Recurse -Include *.ps1 |
ForEach-Object {
Write-Verbose "Importing file $($_.BaseName)"
try {
. $_.FullName
}
catch { }
}
if (-not (Get-Module -Name InvokeBuild -ListAvailable) -and -not $ResolveDependency) {
Write-Error "Requirements are missing. Please call the script again with the switch 'ResolveDependency'"
return
}
if ($ResolveDependency) {
. $PSScriptRoot/Build/BuildHelpers/Resolve-Dependency.ps1
Resolve-Dependency
}
if ($MyInvocation.ScriptName -notlike '*Invoke-Build.ps1') {
if ($ResolveDependency -or $PSBoundParameters['ResolveDependency']) {
$PSBoundParameters.Remove('ResolveDependency')
$PSBoundParameters['DownloadResourcesAndConfigurations'] = $true
}
if ($Help) {
Invoke-Build ?
}
else {
$PSBoundParameters.Remove('Tasks') | Out-Null
Invoke-Build -Tasks $Tasks -File $MyInvocation.MyCommand.Path @PSBoundParameters
}
if (($Tasks -contains 'CompileRootConfiguration' -or $Tasks -contains 'CompileRootMetaMof') -or -not $Tasks) {
Invoke-Build -File "$ProjectPath\PostBuild.ps1"
}
$mofFileCount = (Get-ChildItem -Path "$BuildOutput\MOF" -Filter *.mof -ErrorAction SilentlyContinue).Count
Write-Host "Created $mofFileCount MOF files in '$BuildOutput/MOF'" -ForegroundColor Green
#Debug Output
Write-Host "------------------------------------" -ForegroundColor Magenta
Write-Host "PowerShell Variables" -ForegroundColor Magenta
Get-Variable | Out-String | Write-Host -ForegroundColor Magenta
Write-Host "------------------------------------" -ForegroundColor Magenta
Write-Host "Environment Variables" -ForegroundColor Magenta
dir env: | Out-String | Write-Host -ForegroundColor Magenta
Write-Host "------------------------------------" -ForegroundColor Magenta
return
}
if ($TaskHeader) {
Set-BuildHeader $TaskHeader
}
if (-not $Tasks) {
task . Init,
CleanBuildOutput,
SetPsModulePath,
TestConfigData,
VersionControl,
LoadDatumConfigData,
CompileDatumRsop,
TestDscResources,
CompileRootConfiguration,
CompileRootMetaMof
}
else {
task . $Tasks
}
Write-Host "Running the folling tasks:" -ForegroundColor Magenta
${*}.All[-1].Jobs | ForEach-Object { "`t$_" } | Write-Host
Write-Host