PowerStig/build.ps1

424 строки
17 KiB
PowerShell
Исходник Постоянная ссылка Обычный вид История

master into dev (#662) * Prep for release of 4.1.1 (#519) * Functions.Checklist - Adding manual check functionality (#495) * Adding manual check functionality * Exception Parameter Backward Compatibility Feature Request (#515) * backward compatibility commit * fixed Issue #517 (#518) * Fixed [#517](https://github.com/microsoft/PowerStig/issues/517): 4.1.0 GPRegistryPolicyDsc Module Version Issue * resolving dev merge issue conflict * Release PR from milestone (4.4.0) to master (#661) * Migrate PowerSTIG to Azure DevOps for Build and Test (#603) * update folder structure for azure dev ops * dscresource unit test passing * updated unit tests * Unit test pathing update, all passing * updated unit test to ensure regex data files are loaded * updated .tests.header for unit\tools directory * daily commit - Integrated test updates * updated tests based on testing feedback * optimized test header based on feedback * updated build.psd1 case sensitive * update build agent to windows-2019 * update build and azure yml files * added hqrm tests to build yml and dependencies * updated azure-pipelines.yml to include hqrm test * updated HRQM display name * updated test exclusion DSCResources * intro logic to dynamically build requiredmodules * updated yml to reflect master * updated changelog.md * Update azure-pipelines.yml * rename sources to source (#605) * Migrate PowerSTIG to Azure DevOps for Build, Test and Release Deployment (#606) * updated powerstig for dynamic versioning * updated gitversion to reflect base version * updated if statement to adhere to style gls * updated code to adhere to sgl hqrmtest * updated code to adhere to sgl hqrm tests * updated code to adhere to sgl hqrm * update yml files to support CICD pipeline * updated markdown function * update change log structure * updated spacing via PR feedback * updated 2012R2 STIG after convert tests reflected a minor delta * Update PowerSTIG to parse and apply Vmware Vsphere 6.5 STIG V1R3 (#607) * initial commit for vsphere * updated based on test results * updated based on vsphere module name * updated module manifest to check build status * updated newlines in raw xccdf * updated newline * updated newlies in rules * updated tests * updated processed Stig name * updated vsphere schema * updated composites * updated spacing * updated format * Updated based on feedback * update required parameter for composite * updated service rule * Added Integration DSCresrouce Vsphere Test * reverted changes to test * updated integration tests * added unit tests * added unit tests * added unit tests * updated formatting based on feedback * updated based on feedback * updated comments * updated tests * updated changelog.md * trailing whitespace removed * updated for HQRM tests * updated based on pr feedback * updated case * update code based on PR feedback * updated code based on PR feedback. * updated tests based on PR feedback * updated test based on PR feedback Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Unable to Import PowerSTIG 4.4.0 Due to cyclic dependency Error (#617) * removed vmware.vspheredsc as a dependency because all of its required dependencies are loaded * updated module load process for VMware modules * updated build.yaml * updated test * Updated tests * removed stop error action * updated formating * updated based on failing hqrm * updated module helper * moved helper module * updated location of module helper * reduced vmware.VsphereDSC version * updated build.yaml * updated data file * update module version schema * updated based on testing * Update changelog * Update based on PR feedback * Update PowerSTIG to successfully parse/apply Microsoft IIS Server/Site STIG - Ver 1, Rel10 (#623) * added IIS Server V1R10 * updated changelog and added iis site v1r10 * updated changelog * removed N-2 STIGS * Update PowerSTIG to successfully parse Microsoft SQL Server 2012 Database STIG - Ver 1, Rel 20 (#621) * updated PowerSTIG to use SQL 2012 Database V1R20 * quotes in test * updated tabs to spaces in sql raw xccdf Co-authored-by: Brian Wilhite <bcwilhite@live.com> * explicit Pester version due to 5.x (latest) test failures * Update PowerSTIG to successfully parse/apply Windows Defender Antivirus STIG - V1R8 (#626) * added new Windows Defender STIG V1R8 removed V1R6 * updated based on PR feedback: * merged origin Co-authored-by: Brian Wilhite <bcwilhite@live.com> * initial commit (#640) Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Update PowerSTIG to successfully parse/apply Microsoft IIS 10 Server/Site STIG - V1R1 (#641) * added IIS 10.0 Server * updated IIS 10 site stig * updated based on tests * updated based on tests * updated log file * added esxi 6.5 v1r4 (#637) Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Update PowerSTIG to successfully parse/apply Windows Server 2012 DNS STIG - Ver 1, Rel 14 (#635) * DNS Update commit * removed DNS 1.12 * explicit version for DscResource.Test * Update PowerSTIG to allow for workgroup level scans (#643) * added community requested functionality to not require domain/forest parameters * updated warning message * reverted to old module dscresource.test * Updated based on feedback * updated sql 2016 instance 1.9 (#638) * Update PowerSTIG to successfully parse/apply MS SQL Server 2012 Instance Ver. 1 Rel. 20 (#642) * updated sql 2012 Instance V1R20 * updated Get-SqlTechnologyRole * removed tabs * added a new line to the end of xccdf * update build to use dscresource.test 0.13.1 * updated code based on feedback * updated sql script query rule and test to take multiple db's withouth conflict * updated based on testing * log file update for IE rule bug * updated change log * added new line to the end of the log files * Updated based on pr feedback * Update PowerSTIG to successfully parse/apply Windows 10 STIG - V1R21 (#656) * Updated to support latest WIN10 STIG * update 1.19 to remove extra slash for bug * update changelog * update release process to correct wiki percentage Co-authored-by: Eric Jenkins <erjenkin@microsoft.com> * update changelog.md Co-authored-by: Eric Jenkins <erjenkin@microsoft.com>
2020-07-01 21:33:36 +03:00
<#
.DESCRIPTION
Bootstrap and build script for PowerShell module pipeline
#>
[CmdletBinding()]
param
(
[Parameter(Position = 0)]
[string[]]$Tasks = '.',
[Parameter()]
[String]
$CodeCoverageThreshold = '',
[Parameter()]
[validateScript(
{ Test-Path -Path $_ }
)]
$BuildConfig,
[Parameter()]
# A Specific folder to build the artefact into.
$OutputDirectory = 'output',
[Parameter()]
# Subdirectory name to build the module (under $OutputDirectory)
$BuiltModuleSubdirectory = '',
# Can be a path (relative to $PSScriptRoot or absolute) to tell Resolve-Dependency & PSDepend where to save the required modules,
# or use CurrentUser, AllUsers to target where to install missing dependencies
# You can override the value for PSDepend in the Build.psd1 build manifest
# This defaults to $OutputDirectory/modules (by default: ./output/modules)
[Parameter()]
$RequiredModulesDirectory = $(Join-Path 'output' 'RequiredModules'),
[Parameter()]
[object[]]
$PesterScript,
# Filter which tags to run when invoking Pester tests
# This is used in the Invoke-Pester.pester.build.ps1 tasks
[Parameter()]
[string[]]
$PesterTag,
# Filter which tags to exclude when invoking Pester tests
# This is used in the Invoke-Pester.pester.build.ps1 tasks
[Parameter()]
[string[]]
$PesterExcludeTag,
# Filter which tags to run when invoking DSC Resource tests
# This is used in the DscResource.Test.build.ps1 tasks
[Parameter()]
[string[]]
$DscTestTag,
# Filter which tags to exclude when invoking DSC Resource tests
# This is used in the DscResource.Test.build.ps1 tasks
[Parameter()]
[string[]]
$DscTestExcludeTag,
[Parameter()]
[Alias('bootstrap')]
[switch]$ResolveDependency,
[Parameter(DontShow)]
[AllowNull()]
$BuildInfo,
[Parameter()]
[switch]
$AutoRestore
)
# The BEGIN block (at the end of this file) handles the Bootstrap of the Environment before Invoke-Build can run the tasks
# if the -ResolveDependency (aka Bootstrap) is specified, the modules are already available, and can be auto loaded
process
{
if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1')
{
# Only run the process block through InvokeBuild (Look at the Begin block at the bottom of this script)
return
}
# Execute the Build Process from the .build.ps1 path.
Push-Location -Path $PSScriptRoot -StackName BeforeBuild
try
{
Write-Host -ForeGroundColor magenta "[build] Parsing defined tasks"
# Load Default BuildInfo if not provided as parameter
if (!$PSBoundParameters.ContainsKey('BuildInfo'))
{
try
{
if (Test-Path $BuildConfig)
{
$ConfigFile = (Get-Item -Path $BuildConfig)
Write-Host "[build] Loading Configuration from $ConfigFile"
$BuildInfo = switch -Regex ($ConfigFile.Extension)
{
# Native Support for PSD1
'\.psd1'
{
Import-PowerShellDataFile -Path $BuildConfig
}
# Support for yaml when module PowerShell-Yaml is available
'\.[yaml|yml]'
{
Import-Module -ErrorAction Stop -Name 'powershell-yaml'
ConvertFrom-Yaml -Yaml (Get-Content -Raw $ConfigFile)
}
# Native Support for JSON and JSONC (by Removing comments)
'\.[json|jsonc]'
{
$JSONC = (Get-Content -Raw -Path $ConfigFile)
$JSON = $JSONC -replace '(?m)\s*//.*?$' -replace '(?ms)/\*.*?\*/'
# This should probably be converted to hashtable for splatting
$JSON | ConvertFrom-Json
}
default
{
Write-Error "Extension '$_' not supported. using @{}"
@{ }
}
}
}
else
{
Write-Host -Object "Configuration file $BuildConfig not found" -ForegroundColor Red
$BuildInfo = @{ }
}
}
catch
{
Write-Host -Object "Error loading Config $ConfigFile.`r`n Are you missing dependencies?" -ForegroundColor Yellow
Write-Host -Object "Make sure you run './build.ps1 -ResolveDependency -tasks noop' to restore the Required modules the first time" -ForegroundColor Yellow
$BuildInfo = @{ }
Write-Error $_.Exception.Message
}
}
# If the Invoke-Build Task Header is specified in the Build Info, set it
if ($BuildInfo.TaskHeader)
{
Set-BuildHeader ([scriptblock]::Create($BuildInfo.TaskHeader))
}
# Import Tasks from modules via their exported aliases when defined in BUild Manifest
# https://github.com/nightroman/Invoke-Build/tree/master/Tasks/Import#example-2-import-from-a-module-with-tasks
if ($BuildInfo.containsKey('ModuleBuildTasks'))
{
foreach ($Module in $BuildInfo['ModuleBuildTasks'].Keys)
{
try
{
Write-Host -ForegroundColor DarkGray -Verbose "Importing tasks from module $Module"
$LoadedModule = Import-Module $Module -PassThru -ErrorAction Stop
foreach ($TaskToExport in $BuildInfo['ModuleBuildTasks'].($Module))
{
$LoadedModule.ExportedAliases.GetEnumerator().Where{
# using -like to support wildcard
Write-Host -ForegroundColor DarkGray "`t Loading $($_.Key)..."
$_.Key -like $TaskToExport
}.ForEach{
# Dot sourcing the Tasks via their exported aliases
. (Get-Alias $_.Key)
}
}
}
catch
{
Write-Host -ForegroundColor Red -Object "Could not load tasks for module $Module."
Write-Error $_
}
}
}
# Loading Build Tasks defined in the .build/ folder (will override the ones imported above if same task name)
Get-ChildItem -Path ".build/" -Recurse -Include *.ps1 -ErrorAction Ignore | ForEach-Object {
"Importing file $($_.BaseName)" | Write-Verbose
. $_.FullName
}
# Synopsis: Empty task, useful to test the bootstrap process
task noop { }
# Define default task sequence ("."), can be overridden in the $BuildInfo
task . {
Write-Build Yellow "No sequence currently defined for the default task"
}
# Load Invoke-Build task sequences/workflows from $BuildInfo
Write-Host -ForegroundColor DarkGray "Adding Workflow from configuration:"
foreach ($Workflow in $BuildInfo.BuildWorkflow.keys)
{
Write-Verbose "Creating Build Workflow '$Workflow' with tasks $($BuildInfo.BuildWorkflow.($Workflow) -join ', ')"
$WorkflowItem = $BuildInfo.BuildWorkflow.($Workflow)
if ($WorkflowItem.Trim() -match '^\{(?<sb>[\w\W]*)\}$')
{
$WorkflowItem = [ScriptBlock]::Create($Matches['sb'])
}
Write-Host -ForegroundColor DarkGray " +-> $Workflow"
task $Workflow $WorkflowItem
}
Write-Host -ForeGroundColor magenta "[build] Executing requested workflow: $($Tasks -join ', ')"
}
finally
{
Pop-Location -StackName BeforeBuild
}
}
Begin
{
# dynamically build the required module data file based on PowerStig.psd1 module manifest
$requiredModulesContent = @'
@{
# Set up a mini virtual environment...
PSDependOptions = @{
AddToPath = $true
Target = 'output\RequiredModules'
Parameters = @{
}
}
InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = '4.10.1'
Plaster = 'latest'
ModuleBuilder = '1.0.0'
ChangelogManagement = 'latest'
Sampler = '0.104.0'
xDSCResourceDesigner = 'latest'
PSPKI = 'latest'
MarkdownLinkCheck = 'latest'
'DscResource.Test' = '0.13.1'
'DscResource.AnalyzerRules' = 'latest'
'powershell-yaml' = 'latest'
'Vmware.VsphereDSC' = '2.1.0.58'
master into dev (#662) * Prep for release of 4.1.1 (#519) * Functions.Checklist - Adding manual check functionality (#495) * Adding manual check functionality * Exception Parameter Backward Compatibility Feature Request (#515) * backward compatibility commit * fixed Issue #517 (#518) * Fixed [#517](https://github.com/microsoft/PowerStig/issues/517): 4.1.0 GPRegistryPolicyDsc Module Version Issue * resolving dev merge issue conflict * Release PR from milestone (4.4.0) to master (#661) * Migrate PowerSTIG to Azure DevOps for Build and Test (#603) * update folder structure for azure dev ops * dscresource unit test passing * updated unit tests * Unit test pathing update, all passing * updated unit test to ensure regex data files are loaded * updated .tests.header for unit\tools directory * daily commit - Integrated test updates * updated tests based on testing feedback * optimized test header based on feedback * updated build.psd1 case sensitive * update build agent to windows-2019 * update build and azure yml files * added hqrm tests to build yml and dependencies * updated azure-pipelines.yml to include hqrm test * updated HRQM display name * updated test exclusion DSCResources * intro logic to dynamically build requiredmodules * updated yml to reflect master * updated changelog.md * Update azure-pipelines.yml * rename sources to source (#605) * Migrate PowerSTIG to Azure DevOps for Build, Test and Release Deployment (#606) * updated powerstig for dynamic versioning * updated gitversion to reflect base version * updated if statement to adhere to style gls * updated code to adhere to sgl hqrmtest * updated code to adhere to sgl hqrm tests * updated code to adhere to sgl hqrm * update yml files to support CICD pipeline * updated markdown function * update change log structure * updated spacing via PR feedback * updated 2012R2 STIG after convert tests reflected a minor delta * Update PowerSTIG to parse and apply Vmware Vsphere 6.5 STIG V1R3 (#607) * initial commit for vsphere * updated based on test results * updated based on vsphere module name * updated module manifest to check build status * updated newlines in raw xccdf * updated newline * updated newlies in rules * updated tests * updated processed Stig name * updated vsphere schema * updated composites * updated spacing * updated format * Updated based on feedback * update required parameter for composite * updated service rule * Added Integration DSCresrouce Vsphere Test * reverted changes to test * updated integration tests * added unit tests * added unit tests * added unit tests * updated formatting based on feedback * updated based on feedback * updated comments * updated tests * updated changelog.md * trailing whitespace removed * updated for HQRM tests * updated based on pr feedback * updated case * update code based on PR feedback * updated code based on PR feedback. * updated tests based on PR feedback * updated test based on PR feedback Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Unable to Import PowerSTIG 4.4.0 Due to cyclic dependency Error (#617) * removed vmware.vspheredsc as a dependency because all of its required dependencies are loaded * updated module load process for VMware modules * updated build.yaml * updated test * Updated tests * removed stop error action * updated formating * updated based on failing hqrm * updated module helper * moved helper module * updated location of module helper * reduced vmware.VsphereDSC version * updated build.yaml * updated data file * update module version schema * updated based on testing * Update changelog * Update based on PR feedback * Update PowerSTIG to successfully parse/apply Microsoft IIS Server/Site STIG - Ver 1, Rel10 (#623) * added IIS Server V1R10 * updated changelog and added iis site v1r10 * updated changelog * removed N-2 STIGS * Update PowerSTIG to successfully parse Microsoft SQL Server 2012 Database STIG - Ver 1, Rel 20 (#621) * updated PowerSTIG to use SQL 2012 Database V1R20 * quotes in test * updated tabs to spaces in sql raw xccdf Co-authored-by: Brian Wilhite <bcwilhite@live.com> * explicit Pester version due to 5.x (latest) test failures * Update PowerSTIG to successfully parse/apply Windows Defender Antivirus STIG - V1R8 (#626) * added new Windows Defender STIG V1R8 removed V1R6 * updated based on PR feedback: * merged origin Co-authored-by: Brian Wilhite <bcwilhite@live.com> * initial commit (#640) Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Update PowerSTIG to successfully parse/apply Microsoft IIS 10 Server/Site STIG - V1R1 (#641) * added IIS 10.0 Server * updated IIS 10 site stig * updated based on tests * updated based on tests * updated log file * added esxi 6.5 v1r4 (#637) Co-authored-by: Brian Wilhite <bcwilhite@live.com> * Update PowerSTIG to successfully parse/apply Windows Server 2012 DNS STIG - Ver 1, Rel 14 (#635) * DNS Update commit * removed DNS 1.12 * explicit version for DscResource.Test * Update PowerSTIG to allow for workgroup level scans (#643) * added community requested functionality to not require domain/forest parameters * updated warning message * reverted to old module dscresource.test * Updated based on feedback * updated sql 2016 instance 1.9 (#638) * Update PowerSTIG to successfully parse/apply MS SQL Server 2012 Instance Ver. 1 Rel. 20 (#642) * updated sql 2012 Instance V1R20 * updated Get-SqlTechnologyRole * removed tabs * added a new line to the end of xccdf * update build to use dscresource.test 0.13.1 * updated code based on feedback * updated sql script query rule and test to take multiple db's withouth conflict * updated based on testing * log file update for IE rule bug * updated change log * added new line to the end of the log files * Updated based on pr feedback * Update PowerSTIG to successfully parse/apply Windows 10 STIG - V1R21 (#656) * Updated to support latest WIN10 STIG * update 1.19 to remove extra slash for bug * update changelog * update release process to correct wiki percentage Co-authored-by: Eric Jenkins <erjenkin@microsoft.com> * update changelog.md Co-authored-by: Eric Jenkins <erjenkin@microsoft.com>
2020-07-01 21:33:36 +03:00
# The modules below are dynamically inserted from the Begin block of .\build.ps1
'@
$stringBuilder = New-Object -TypeName System.Text.StringBuilder -ArgumentList $requiredModulesContent
$powerStigModuleManifest = Import-PowerShellDataFile -Path (Join-Path -Path $PSScriptRoot -ChildPath '.\source\PowerStig.psd1')
$powerStigRequiredModule = $powerStigModuleManifest.RequiredModules
foreach ($requiredModule in $powerStigRequiredModule)
{
$moduleInfo = " '{0}' = '{1}'" -f $requiredModule.ModuleName, $requiredModule.ModuleVersion
[void] $stringBuilder.AppendLine($moduleInfo)
}
[void] $stringBuilder.AppendLine("}`n`r")
Set-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath 'RequiredModules.psd1') -Value $stringBuilder.ToString() -Encoding UTF8
# Find build config if not specified
if (-not $BuildConfig) {
$config = Get-ChildItem -Path "$PSScriptRoot\*" -Include 'build.y*ml', 'build.psd1', 'build.json*' -ErrorAction:Ignore
if (-not $config -or ($config -is [array] -and $config.Length -le 0)) {
throw "No build configuration found. Specify path via -BuildConfig"
}
elseif ($config -is [array]) {
if ($config.Length -gt 1) {
throw "More than one build configuration found. Specify which one to use via -BuildConfig"
}
$BuildConfig = $config[0]
}
else {
$BuildConfig = $config
}
}
# Bootstrapping the environment before using Invoke-Build as task runner
if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1')
{
Write-Host -foregroundColor Green "[pre-build] Starting Build Init"
Push-Location $PSScriptRoot -StackName BuildModule
}
if ($RequiredModulesDirectory -in @('CurrentUser', 'AllUsers'))
{
# Installing modules instead of saving them
Write-Host -foregroundColor Green "[pre-build] Required Modules will be installed for $RequiredModulesDirectory, not saved."
# Tell Resolve-Dependency to use provided scope as the -PSDependTarget if not overridden in Build.psd1
$PSDependTarget = $RequiredModulesDirectory
}
else
{
if (-Not (Split-Path -IsAbsolute -Path $OutputDirectory))
{
$OutputDirectory = Join-Path -Path $PSScriptRoot -ChildPath $OutputDirectory
}
# Resolving the absolute path to save the required modules to
if (-Not (Split-Path -IsAbsolute -Path $RequiredModulesDirectory))
{
$RequiredModulesDirectory = Join-Path -Path $PSScriptRoot -ChildPath $RequiredModulesDirectory
}
# Create the output/modules folder if not exists, or resolve the Absolute path otherwise
if (Resolve-Path $RequiredModulesDirectory -ErrorAction SilentlyContinue)
{
Write-Debug "[pre-build] Required Modules path already exist at $RequiredModulesDirectory"
$RequiredModulesPath = Convert-Path $RequiredModulesDirectory
}
else
{
Write-Host -foregroundColor Green "[pre-build] Creating required modules directory $RequiredModulesDirectory."
$RequiredModulesPath = (New-Item -ItemType Directory -Force -Path $RequiredModulesDirectory).FullName
}
# Prepending $RequiredModulesPath folder to PSModulePath to resolve from this folder FIRST
if ($RequiredModulesDirectory -notIn @('CurrentUser', 'AllUsers') -and
(($Env:PSModulePath -split [io.path]::PathSeparator) -notContains $RequiredModulesDirectory))
{
Write-Host -foregroundColor Green "[pre-build] Prepending '$RequiredModulesDirectory' folder to PSModulePath"
$Env:PSModulePath = $RequiredModulesDirectory + [io.path]::PathSeparator + $Env:PSModulePath
}
# Checking if the user should -ResolveDependency
if ((!(Get-Module -ListAvailable powershell-yaml) -or !(Get-Module -ListAvailable InvokeBuild) -or !(Get-Module -ListAvailable PSDepend)) -and !$ResolveDependency)
{
if ($AutoRestore -or !$PSBoundParameters.ContainsKey('Tasks') -or $Tasks -contains 'build')
{
Write-Host -ForegroundColor Yellow "[pre-build] Dependency missing, running './build.ps1 -ResolveDependency -Tasks noop' for you `r`n"
$ResolveDependency = $true
}
else
{
Write-Warning "Some required Modules are missing, make sure you first run with the '-ResolveDependency' parameter."
Write-Warning "Running 'build.ps1 -ResolveDependency -Tasks noop' will pull required modules without running the build task."
}
}
if ($BuiltModuleSubdirectory)
{
if (-Not (Split-Path -IsAbsolute $BuiltModuleSubdirectory))
{
$BuildModuleOutput = Join-Path $OutputDirectory $BuiltModuleSubdirectory
}
else
{
$BuildModuleOutput = $BuiltModuleSubdirectory
}
}
else
{
$BuildModuleOutput = $OutputDirectory
}
# Prepending $BuildModuleOutput folder to PSModulePath to resolve built module from this folder
if (($Env:PSModulePath -split [io.path]::PathSeparator) -notContains $BuildModuleOutput)
{
Write-Host -foregroundColor Green "[pre-build] Prepending '$BuildModuleOutput' folder to PSModulePath"
$Env:PSModulePath = $BuildModuleOutput + [io.path]::PathSeparator + $Env:PSModulePath
}
# Tell Resolve-Dependency to use $RequiredModulesPath as -PSDependTarget if not overridden in Build.psd1
$PSDependTarget = $RequiredModulesPath
}
if ($ResolveDependency)
{
Write-Host -Object "[pre-build] Resolving dependencies." -foregroundColor Green
$ResolveDependencyParams = @{ }
# If BuildConfig is a Yaml file, bootstrap powershell-yaml via ResolveDependency
if ($BuildConfig -match '\.[yaml|yml]$')
{
$ResolveDependencyParams.add('WithYaml', $True)
}
$ResolveDependencyAvailableParams = (Get-Command -Name '.\Resolve-Dependency.ps1').parameters.keys
foreach ($CmdParameter in $ResolveDependencyAvailableParams)
{
# The parameter has been explicitly used for calling the .build.ps1
if ($MyInvocation.BoundParameters.ContainsKey($CmdParameter))
{
$ParamValue = $MyInvocation.BoundParameters.ContainsKey($CmdParameter)
Write-Debug " adding $CmdParameter :: $ParamValue [from user-provided parameters to Build.ps1]"
$ResolveDependencyParams.Add($CmdParameter, $ParamValue)
}
# Use defaults parameter value from Build.ps1, if any
else
{
if ($ParamValue = Get-Variable -Name $CmdParameter -ValueOnly -ErrorAction Ignore)
{
Write-Debug " adding $CmdParameter :: $ParamValue [from default Build.ps1 variable]"
$ResolveDependencyParams.add($CmdParameter, $ParamValue)
}
}
}
Write-Host -foregroundColor Green "[pre-build] Starting bootstrap process."
.\Resolve-Dependency.ps1 @ResolveDependencyParams
}
if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1')
{
Write-Verbose "Bootstrap completed. Handing back to InvokeBuild."
if ($PSBoundParameters.ContainsKey('ResolveDependency'))
{
Write-Verbose "Dependency already resolved. Removing task"
$null = $PSBoundParameters.Remove('ResolveDependency')
}
Write-Host -foregroundColor Green "[build] Starting build with InvokeBuild."
Invoke-Build @PSBoundParameters -Task $Tasks -File $MyInvocation.MyCommand.Path
Pop-Location -StackName BuildModule
return
}
}