Skip to content

Commit 80cde52

Browse files
committed
feat: add bump helm chart version script
1 parent f4b5c45 commit 80cde52

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

scripts/bump-helm-chart-version.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const yaml = require("js-yaml");
4+
5+
export const bumpChartVersion = () => {
6+
const rootDir = path.join(__dirname, "..");
7+
8+
const chartYamlPath = path.join(
9+
rootDir,
10+
"helm-charts",
11+
"catalogi",
12+
"Chart.yaml"
13+
);
14+
15+
try {
16+
const chartYamlContent = fs.readFileSync(chartYamlPath, "utf8");
17+
const chartYaml = yaml.load(chartYamlContent);
18+
const currentVersion = chartYaml.version;
19+
20+
// --- This is the new, dependency-free logic ---
21+
const parts = currentVersion.split(".");
22+
if (parts.length !== 3) {
23+
throw new Error(
24+
`Chart version "${currentVersion}" is not a valid x.y.z format.`
25+
);
26+
}
27+
28+
const patch = parseInt(parts[2], 10);
29+
if (isNaN(patch)) {
30+
throw new Error(`Patch version "${parts[2]}" is not a valid number.`);
31+
}
32+
33+
parts[2] = patch + 1;
34+
const newVersion = parts.join(".");
35+
// --- End of new logic ---
36+
37+
console.log(
38+
`Bumping Helm chart version from ${currentVersion} to ${newVersion}...`
39+
);
40+
chartYaml.version = newVersion;
41+
const newChartYamlContent = yaml.dump(chartYaml);
42+
fs.writeFileSync(chartYamlPath, newChartYamlContent, "utf8");
43+
console.log("✅ Helm chart version bumped.");
44+
} catch (error) {
45+
console.error("❌ Error bumping Helm chart version:", error.message);
46+
process.exit(1);
47+
}
48+
};

scripts/helm-version-utils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Increments the patch number of a semantic version string.
3+
* @param {string} versionString - The version to increment (e.g., "1.2.3").
4+
* @returns {string} The incremented version string (e.g., "1.2.4").
5+
*/
6+
7+
const getBumpedVersion = versionString => {
8+
const parts = versionString.split(".");
9+
if (parts.length !== 3) {
10+
throw new Error(
11+
`Version "${versionString}" is not a valid x.y.z format.`,
12+
);
13+
}
14+
15+
const patch = parseInt(parts[2], 10);
16+
if (isNaN(patch)) {
17+
throw new Error(`Patch version "${parts[2]}" is not a valid number.`);
18+
}
19+
20+
parts[2] = patch + 1;
21+
return parts.join(".");
22+
};
23+
24+
module.exports = { getBumpedVersion };

scripts/sync-helm-app-version.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require("fs");
22
const path = require("path");
33
const yaml = require("js-yaml");
4+
const { exec, execSync } = require("child_process");
45

56
const rootDir = path.join(__dirname, "..");
67
const rootPackageJsonPath = path.join(rootDir, "package.json");
@@ -30,6 +31,13 @@ try {
3031
const newChartYamlContent = yaml.dump(chartYaml);
3132
fs.writeFileSync(chartYamlPath, newChartYamlContent, "utf8");
3233
console.log("✅ Helm chart appVersion updated");
34+
35+
console.log("Calling bump script...");
36+
execSync(
37+
`node ${path.join(__dirname, "bump-chart-version.js")}`,
38+
{ stdio: "inherit" }, // This ensures the output of the bump script is shown
39+
);
40+
3341
} else {
3442
console.log("✅ Helm chart appVersion is already in sync.");
3543
}

0 commit comments

Comments
 (0)