Created
July 13, 2023 13:13
-
-
Save jimbo8098/8aacf9b9c4cde9ecc4546d6f55e08d4c to your computer and use it in GitHub Desktop.
Fan out Helm template files into their own files to assist in debugging big charts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory = $true)] | |
[string] | |
$InFile, | |
[Parameter(Mandatory = $true)] | |
[string] | |
$OutDir | |
) | |
$input = Get-Content $InFile -Delimiter "---" | |
if($input.Length -gt 1) { | |
$i = 0 | |
for($segmentNo = 0; $segmentNo -lt $input.Length; $segmentNo++) { | |
$segment = $input[$segmentNo] | |
# The first line of the file is always the chart sha | |
if ($segmentNo -eq 0) {continue;} | |
$sourceNameLine = $segment.Split("`r`n") | % { if($_.Contains("# Source:")){$_} } | |
if($sourceNameLine) { | |
$outputFile = $sourceNameLine.Split(":")[1].Replace(" ","") | |
$fullOutputPath = Join-Path -Path $OutDir -ChildPath $outputFile | |
$outputDir = Split-Path -Path $fullOutputPath | |
New-Item -Path $outputDir -ItemType "Directory" -Force | |
Set-Content -Path $fullOutputPath -Value $segment | |
} | |
else { | |
Write-Error "Couldn't find name for a segment" | |
} | |
} | |
} else { | |
Write-Warning "Nothing was templated" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment