Skip to content

Commit

Permalink
ci: update chart version index for a single chart (#1867)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-zimnowoda authored Dec 16, 2024
1 parent 8a20b29 commit d636aba
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions ci/src/update-helm-chart-deps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ import yaml from 'js-yaml'
import semver from 'semver'
import { $ } from 'zx'

export function isVersionApplicable(currentVersion, version, allowedUpgradeType) {
if (semver.lte(version, currentVersion)) {
return false // Ignore versions that are <= current version
}
if (allowedUpgradeType === 'patch') {
return semver.diff(currentVersion, version) === 'patch'
}
if (allowedUpgradeType === 'minor') {
const isMinorOrPatch =
semver.diff(currentVersion, version) === 'patch' || semver.diff(currentVersion, version) === 'minor'
return isMinorOrPatch
}
return true // Default: Allow all upgrades
}

async function main() {
config()
const env = envalid.cleanEnv(process.env, {
Expand Down Expand Up @@ -44,6 +59,7 @@ async function main() {
}

for (const dependency of chart.dependencies) {
const currentDependencyVersion = dependency.version
if (dependencyNameFilter.length != 0 && !dependencyNameFilter.includes(dependency.name)) {
console.log(
`Skipping updates for dependency: ${dependency.name} due to dependencyNameFilter: ${dependencyNameFilter} `,
Expand All @@ -70,18 +86,7 @@ async function main() {
// Filter versions for allowed upgrades (minor/patch)
const currentVersion = dependency.version
const filteredVersions = allVersions.filter((version) => {
if (semver.lte(version, currentVersion)) {
return false // Ignore versions that are <= current version
}
if (allowedUpgradeType === 'patch') {
return semver.diff(currentVersion, version) === 'patch'
}
if (allowedUpgradeType === 'minor') {
const isMinorOrPatch =
semver.diff(currentVersion, version) === 'patch' || semver.diff(currentVersion, version) === 'minor'
return isMinorOrPatch
}
return true // Default: Allow all upgrades
return isVersionApplicable(currentVersion, version, allowedUpgradeType)
})

if (!filteredVersions.length) {
Expand Down Expand Up @@ -143,8 +148,9 @@ async function main() {
}
} catch (error) {
console.error('Error updating dependencies:', error)
continue
} finally {
// restore this version so it does not populate to the next chart update
dependency.version = currentDependencyVersion
if (ciCreateFeatureBranch) {
// Reset to the main branch for the next dependency
await $`git checkout ${baseBranch}`
Expand Down

0 comments on commit d636aba

Please sign in to comment.