TaskFunctions/Invoke-PlumberYAML.ps1
|
function Invoke-PlumberYAML { <# .SYNOPSIS Runs the YAML task body. #> [CmdletBinding()] param () $convertFromYaml = Get-Command ConvertFrom-Yaml -ErrorAction SilentlyContinue $convertToYaml = Get-Command ConvertTo-Yaml -ErrorAction SilentlyContinue if (-not $convertFromYaml -or -not $convertToYaml) { throw 'ConvertFrom-Yaml and ConvertTo-Yaml are required. Install the powershell-yaml module.' } $yamlFiles = Get-PlumberTaskFile -Task YAML -Extension '.yml', '.yaml' if (-not $yamlFiles) { Write-Build Yellow 'No YAML files found' return } foreach ($yamlFile in $yamlFiles) { try { Get-Content $yamlFile.FullName -Raw -ErrorAction Stop | ConvertFrom-Yaml -ErrorAction Stop | ConvertTo-Yaml -ErrorAction Stop | Out-Null } catch { Write-Error "Invalid YAML in $($yamlFile.FullName): $($_.Exception.Message)" } } } |