-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateHelmChart.js
29 lines (23 loc) · 908 Bytes
/
updateHelmChart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const getChartPath = ({ chart }) => {
if (!chart) {
throw new Error('Chart is required for @amille/semantic-release-plugins/updateHelmChart');
}
return path.resolve(process.cwd(), chart);
};
const prepare = (pluginConfig, context) => {
const chartFile = getChartPath(pluginConfig);
const { nextRelease, logger } = context;
const { version } = nextRelease;
if (!fs.existsSync(chartFile)) {
throw new Error(`${chartFile} chart file not found`);
}
const rawChart = fs.readFileSync(chartFile, 'utf8');
const chart = yaml.safeLoad(rawChart);
const newChart = yaml.safeDump({ ...chart, appVersion: version });
fs.writeFileSync(chartFile, newChart, 'utf8');
logger.log('Chart app version has been set to %s', version);
};
module.exports = { prepare };