-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
99 lines (85 loc) · 3.02 KB
/
Copy pathaction.yml
File metadata and controls
99 lines (85 loc) · 3.02 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: "Update chart values"
description: |
Updates Helm chart values files before release.
author: hoverkraft
branding:
icon: edit
color: blue
inputs:
path:
description: "Path to the chart to update"
required: true
values:
description: |
Define charts values to be filled.
See https://mikefarah.gitbook.io/yq/.
Format: `[{ file, path, value }]`.
Example:
```json
[
{
"file": "charts/application/charts/api/values.yaml",
"path": ".image.registry", "value": "ghcr.io"
}
]
```
required: false
runs:
using: "composite"
steps:
- id: chart-values-updates
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
INPUT_PATH: ${{ inputs.path }}
INPUT_VALUES: ${{ inputs.values }}
with:
script: |
const yqUpdates = {};
const basePath = process.env.INPUT_PATH;
if (!basePath) {
throw new Error(`"path" input is missing`);
}
// values.yaml files
const chartValuesInput = process.env.INPUT_VALUES;
if (chartValuesInput) {
let chartValues = null;
try {
chartValues = JSON.parse(chartValuesInput);
} catch (error) {
throw new Error(`"values" input is not a valid JSON: ${error}`);
}
if (!Array.isArray(chartValues)) {
throw new Error(`"values" input is not an array`);
}
if (chartValues.length) {
const defaultValuesPath = 'values.yaml';
for (const key in chartValues) {
const chartValue = chartValues[key];
if (typeof chartValue !== 'object' || chartValue === null) {
throw new Error(`"values[${key}]" input is not an object`);
}
for (const property of ['path', 'value']) {
if (!Object.prototype.hasOwnProperty.call(chartValue, property)) {
throw new Error(`"values[${key}].${property}" input is missing`);
}
}
const valueFilePath = chartValue.file ? chartValue.file : defaultValuesPath;
const filePath = `${basePath}/${valueFilePath}`;
if (!yqUpdates[filePath]) {
yqUpdates[filePath] = [];
}
yqUpdates[filePath].push(`${chartValue.path} = "${chartValue.value}"`);
}
}
}
const yqCommands = Object.entries(yqUpdates).map(([filePath, updates]) => {
return `yq -i '${updates.join(' | ')}' ${filePath}`;
});
core.setOutput('yq-command', yqCommands.join('\n'));
- if: ${{ steps.chart-values-updates.outputs.yq-command != '' }}
uses: mikefarah/yq@1b9b4ac5187171d2e5e3129be0cfa827c7f9d53d # v4.53.3
env:
YQ_COMMAND: ${{ steps.chart-values-updates.outputs.yq-command }}
with:
cmd: |
sh -c "$YQ_COMMAND"