Common/Run-Pipelines.psm1
Import-Module "$PSScriptRoot\Logging-Module.psm1" -Force $ErrorActionPreference = "Stop" function RemoveTemp { if (Test-Path "$PSScriptRoot\..\temp") { Remove-Item "$PSScriptRoot\..\temp" -Recurse -Force | Out-Null } } function CreateTemp { $tempFolder = "$PSScriptRoot\..\temp" if (!(Test-Path $tempFolder)) { New-Item -ItemType Directory -Path $tempFolder -Force | Out-Null } } function GetPipelineSteps { [CmdletBinding()] Param ( [string]$Pipeline, [switch]$RunExtensions ) $steps = $global:Pipelines.$Pipeline if (($RunExtensions.IsPresent) -and ($null -ne $global:Configuration.Extensions.Pipelines)) { $steps += $global:Configuration.Extensions.Pipelines } return $steps } function BuildStepAbsolutePath { [CmdletBinding()] Param ( [string]$Path ) if (!($Path.StartsWith("/") -or $Path.StartsWith("\"))) { return $Path } $absPath = "$(Get-Location)\$Path" if (Test-Path $absPath) { return $absPath } return "$PSScriptRoot\..$($Path)" } function ShowSteps { [CmdletBinding()] Param ( [string]$Pipeline, [PSObject[]]$Steps ) Write-Output "`n`nSAF will run '$Pipeline' pipeline:`n" foreach ($step in $Steps) { if (($step.skip -eq $true) -or (IsStepCompleted -Pipeline $Pipeline -Step $step.name)) { Write-Warning "SKIP $($step.name)" } else { Write-Output "- $($step.name)" } } Write-Output "" Write-Warning "Starting after 13 seconds..." Write-Output "" Start-Sleep -s 13 } function RunSteps { [CmdletBinding()] Param ( [string]$Pipeline, [switch]$Force, [switch]$RunExtensions ) CreateTemp if ($Force.IsPresent) { EraseHistoryLog -Pipeline $Pipeline } $steps = GetPipelineSteps -Pipeline $Pipeline -RunExtensions:$RunExtensions ShowSteps -Pipeline $Pipeline -Steps $steps try { foreach ($step in $steps) { if (($step.skip -eq $true) -or (IsStepCompleted -Pipeline $Pipeline -Step $step.name)) { continue } $stepAbsPath = BuildStepAbsolutePath -Path $step.script & $stepAbsPath MarkStepAsCompleted -Pipeline $Pipeline -Step $step.name } RemoveTemp } catch { $exception = $_.Exception | Format-List -Force | Out-String Write-Error $exception } } Export-ModuleMember -Function "RunSteps" Export-ModuleMember -Function "RemoveTemp" |