Skip to content

Commit f4b5c45

Browse files
committed
feat: create script to sync helm charts with root package.json version
1 parent d33af0d commit f4b5c45

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

helm-charts/catalogi/Chart.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v2
2+
name: catalogi
3+
description: A Helm chart for deploying the Catalogi open source software catalog.
4+
type: application
5+
version: 0.1.0
6+
appVersion: 1.50.2
7+
dependencies:
8+
- name: postgresql
9+
version: '16'
10+
repository: https://charts.bitnami.com/bitnami
11+
condition: postgresql.enabled

lefthook.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ pre-commit:
33
format:
44
run: yarn format
55
stage_fixed: true
6+
sync-helm-version:
7+
glob: "{package.json,helm-charts/catalogi/Chart.yaml}"
8+
run: yarn sync-helm-charts
9+
stage_fixed: true
610
lint:
711
run: yarn turbo lint
812

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
"format": "turbo format",
1212
"format:check": "turbo format:check",
1313
"fullcheck": "turbo typecheck format:check lint test",
14-
"turbo": "turbo"
14+
"turbo": "turbo",
15+
"sync-helm-charts": "node scripts/sync-helm-app-version.js"
1516
},
1617
"devDependencies": {
1718
"@commitlint/cli": "^19.8.0",
1819
"@commitlint/config-conventional": "^19.8.0",
20+
"js-yaml": "^4.1.0",
1921
"lefthook": "^1.10.10",
2022
"turbo": "^1.12.5"
2123
},

scripts/sync-helm-app-version.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const yaml = require("js-yaml");
4+
5+
const rootDir = path.join(__dirname, "..");
6+
const rootPackageJsonPath = path.join(rootDir, "package.json");
7+
const chartYamlPath = path.join(
8+
rootDir,
9+
"helm-charts",
10+
"catalogi",
11+
"Chart.yaml",
12+
);
13+
14+
try {
15+
const packageJsonContent = fs.readFileSync(rootPackageJsonPath, "utf8");
16+
const { version: appVersion } = JSON.parse(packageJsonContent);
17+
18+
if (!appVersion) {
19+
throw new Error("Version not found in root package.json");
20+
}
21+
22+
const chartYamlContent = fs.readFileSync(chartYamlPath, "utf8");
23+
const chartYaml = yaml.load(chartYamlContent);
24+
25+
if (chartYaml.appVersion !== appVersion) {
26+
console.log(
27+
`Updating Helm chart appVersion from ${chartYaml.appVersion} to ${appVersion}...`,
28+
);
29+
chartYaml.appVersion = appVersion;
30+
const newChartYamlContent = yaml.dump(chartYaml);
31+
fs.writeFileSync(chartYamlPath, newChartYamlContent, "utf8");
32+
console.log("✅ Helm chart appVersion updated");
33+
} else {
34+
console.log("✅ Helm chart appVersion is already in sync.");
35+
}
36+
} catch (error) {
37+
console.error("❌ Error syncing Helm chart version:", error.message);
38+
process.exit(1);
39+
}

0 commit comments

Comments
 (0)