Created
September 13, 2022 18:24
-
-
Save spyder007/71937394cc5637f6601e596fc47f087c to your computer and use it in GitHub Desktop.
Update chart versions in an Argo Repo
This file contains 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
install-module powershell-yaml | |
Invoke-Expression "helm repo update" | |
$repos = ConvertFrom-Json (Invoke-Expression "helm repo list -o json") | |
$charts = get-childitem chart.yaml -Recurse | |
foreach ($chart in $charts) { | |
Write-Host "Checking $chart" | |
$updated = $false | |
$yaml = ConvertFrom-Yaml (Get-Content -Raw $chart) | |
for ($index = 0; $index -lt $yaml.dependencies.Count; $index++) { | |
$name = $yaml.dependencies[$index].name | |
$version = New-Object "System.Version" $yaml.dependencies[$index].version | |
$url = $yaml.dependencies[$index].repository | |
$repo = $repos | Where-Object {$_.url -eq $url} | Select-Object -First 1 | |
$searchResult = ConvertFrom-Json (Invoke-Expression "helm search repo $($repo.name)/$name -o json") | |
$singleResult = $searchResult | Where-Object { $_.name -eq "$($repo.name)/$name"} | Select-Object -First 1 | |
$newVersion = $singleResult.version | |
$repoVersion = New-Object "System.Version" $newVersion.replace("v", "") | |
if ($version -lt $repoVersion) { | |
Write-Host "Updating $name : $version -> $repoVersion" | |
$updated = $true | |
$yaml.dependencies[$index].version = $newVersion | |
$yaml.version = $newVersion | |
} | |
} | |
if ($updated) { | |
(ConvertTo-Yaml $yaml) | Out-String | Set-Content -path $chart.FullName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment