Skip to content

Instantly share code, notes, and snippets.

@spyder007
Created September 13, 2022 18:24
Show Gist options
  • Save spyder007/71937394cc5637f6601e596fc47f087c to your computer and use it in GitHub Desktop.
Save spyder007/71937394cc5637f6601e596fc47f087c to your computer and use it in GitHub Desktop.
Update chart versions in an Argo Repo
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