From 48c74de3260e49cc310c59bee740ddfe2ebc53eb Mon Sep 17 00:00:00 2001 From: alam00000 Date: Sun, 3 May 2026 13:32:04 +0530 Subject: [PATCH] refactor(release): simplify Helm chart bump --- scripts/release.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/scripts/release.js b/scripts/release.js index 0d1d23b..551aae9 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -43,29 +43,30 @@ function updateVersion(type) { } function updateHelmChart(newAppVersion) { - const chartYaml = fs.readFileSync(chartYamlPath, 'utf8'); + const lines = fs.readFileSync(chartYamlPath, 'utf8').split('\n'); + let newChartVersion = null; - const appVersionMatch = chartYaml.match( - /^appVersion:\s*['"]?([^'"\n]+)['"]?/m - ); - const chartVersionMatch = chartYaml.match(/^version:\s*([^\s\n]+)/m); - if (!appVersionMatch || !chartVersionMatch) { - throw new Error('Could not parse version fields in chart/Chart.yaml'); + const updated = lines.map((line) => { + if (line.startsWith('version:')) { + const [maj, min, patch] = line + .slice('version:'.length) + .trim() + .split('.') + .map(Number); + newChartVersion = `${maj}.${min}.${patch + 1}`; + return `version: ${newChartVersion}`; + } + if (line.startsWith('appVersion:')) { + return `appVersion: '${newAppVersion}'`; + } + return line; + }); + + if (!newChartVersion) { + throw new Error('Could not find chart version line in chart/Chart.yaml'); } - const [chartMajor, chartMinor, chartPatch] = chartVersionMatch[1] - .split('.') - .map(Number); - const newChartVersion = `${chartMajor}.${chartMinor}.${chartPatch + 1}`; - - const updated = chartYaml - .replace(/^version:\s*[^\s\n]+/m, `version: ${newChartVersion}`) - .replace( - /^appVersion:\s*['"]?[^'"\n]+['"]?/m, - `appVersion: '${newAppVersion}'` - ); - - fs.writeFileSync(chartYamlPath, updated); + fs.writeFileSync(chartYamlPath, updated.join('\n')); return { chartVersion: newChartVersion, appVersion: newAppVersion }; }