Skip to content

Commit

Permalink
feat(helm/release-chart): supports umbrella chart
Browse files Browse the repository at this point in the history
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
  • Loading branch information
neilime committed Jul 26, 2024
1 parent d2f486f commit 08ea2c6
Showing 1 changed file with 55 additions and 37 deletions.
92 changes: 55 additions & 37 deletions actions/helm/release-chart/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,53 +67,72 @@ runs:
uses: actions/github-script@v7.0.1
with:
script: |
const chartValuesInput = `${{ inputs.values }}`;
if(!chartValuesInput) {
return;
}
const path = require('node:path');
// Check if is valid Json
let chartValues = null;
try {
chartValues = JSON.parse(chartValuesInput);
} catch (error) {
throw new Error(`"values" input is not a valid JSON: ${error}`);
}
const yqUpdates = {};
// Check if is an array
if (!Array.isArray(chartValues)) {
throw new Error(`"values" input is not an array`);
}
// Chart.yml files
const globber = await glob.create(`${{ inputs.path }}/**/Chart.yaml`, {followSymbolicLinks: false})
for await (const chartFile of globber.globGenerator()) {
const filePath = path.relative(`${{ github.workspace }}`, chartFile);
if (!yqUpdates[filePath]) {
yqUpdates[filePath] = [];
}
if (!chartValues.length) {
return;
}
// Update name for root chart
if (filePath === '${{ inputs.path }}/Chart.yaml') {
yqUpdates[filePath].push(`.name = "${{ github.event.repository.name }}"`);
}
const defaultValuesPath = "values.yaml";
// Update version fields
yqUpdates[filePath].push(`.version = "${{ inputs.tag }}"`);
yqUpdates[filePath].push(`.appVersion = "${{ inputs.tag }}"`);
}
// Check each item
const yqUpdates = {};
for (const key in chartValues) {
const chartValue = chartValues[key];
if (typeof chartValue !== 'object') {
throw new Error(`"values[${key}]" input is not an object`);
// values.yml files
const chartValuesInput = `${{ inputs.values }}`;
if(chartValuesInput) {
// Check if is valid Json
let chartValues = null;
try {
chartValues = JSON.parse(chartValuesInput);
} catch (error) {
throw new Error(`"values" input is not a valid JSON: ${error}`);
}
// Check mandatory properties
for (const property of ['path', 'value']) {
if (!chartValue.hasOwnProperty(property)) {
throw new Error(`"values[${key}].${property}" input is missing`);
}
// Check if is an array
if (!Array.isArray(chartValues)) {
throw new Error(`"values" input is not an array`);
}
const valueFilePath = chartValue['file'] ? chartValue['file'] : defaultValuesPath;
const filePath = `${{ inputs.path }}/${valueFilePath}`;
if (chartValues.length) {
const defaultValuesPath = "values.yaml";
if (!yqUpdates[filePath]) {
yqUpdates[filePath] = [];
}
// Check each item
for (const key in chartValues) {
const chartValue = chartValues[key];
if (typeof chartValue !== 'object') {
throw new Error(`"values[${key}]" input is not an object`);
}
yqUpdates[filePath].push(`${chartValue.path} = "${chartValue.value}"`);
// Check mandatory properties
for (const property of ['path', 'value']) {
if (!chartValue.hasOwnProperty(property)) {
throw new Error(`"values[${key}].${property}" input is missing`);
}
}
const valueFilePath = chartValue['file'] ? chartValue['file'] : defaultValuesPath;
const filePath = `${{ inputs.path }}/${valueFilePath}`;
if (!yqUpdates[filePath]) {
yqUpdates[filePath] = [];
}
yqUpdates[filePath].push(`${chartValue.path} = "${chartValue.value}"`);
}
}
}
// Build yq commands
Expand All @@ -126,7 +145,6 @@ runs:
- uses: mikefarah/yq@v4.44.2
with:
cmd: |
yq -i '.name = "${{ github.event.repository.name }}" | .version = "${{ inputs.tag }}" | .appVersion = "${{ inputs.tag }}"' ${{ inputs.path }}/Chart.yaml
${{ steps.chart-values-updates.outputs.yq-command }}
- uses: azure/setup-helm@v4
Expand Down

0 comments on commit 08ea2c6

Please sign in to comment.