Skip to content

Commit 842cd2c

Browse files
committed
feat(helm/test-chart): build chart dependencies before testing
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 695db98 commit 842cd2c

4 files changed

Lines changed: 313 additions & 160 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!-- header:start -->
2+
<!-- header:end -->
3+
4+
<!-- badges:start -->
5+
<!-- badges:end -->
6+
7+
<!-- overview:start -->
8+
<!-- overview:end -->
9+
10+
<!-- usage:start -->
11+
<!-- usage:end -->
12+
13+
<!-- inputs:start -->
14+
<!-- inputs:end -->
15+
16+
<!-- secrets:start -->
17+
<!-- secrets:end -->
18+
19+
<!-- outputs:start -->
20+
<!-- outputs:end -->
21+
22+
<!-- examples:start -->
23+
<!-- examples:end -->
24+
25+
<!--
26+
// jscpd:ignore-start
27+
-->
28+
29+
<!-- contributing:start -->
30+
<!-- contributing:end -->
31+
32+
<!-- security:start -->
33+
<!-- security:end -->
34+
35+
<!-- license:start -->
36+
<!-- license:end -->
37+
38+
<!-- generated:start -->
39+
<!-- generated:end -->
40+
41+
<!--
42+
// jscpd:ignore-start
43+
-->
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
name: "Prepare Helm Chart"
3+
description: |
4+
Add Helm repositories and build chart dependencies
5+
for all charts found under a path.
6+
author: hoverkraft
7+
branding:
8+
icon: package
9+
color: blue
10+
11+
inputs:
12+
path:
13+
description: "Path containing the chart(s) to prepare"
14+
required: true
15+
helm-repositories:
16+
description: |
17+
List of Helm repositories to add before building chart dependencies.
18+
See https://helm.sh/docs/helm/helm_repo_add/.
19+
required: false
20+
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: Add Helm repositories
25+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
26+
env:
27+
INPUT_HELM_REPOSITORIES: ${{ inputs.helm-repositories }}
28+
with:
29+
script: |
30+
const repositories = (process.env.INPUT_HELM_REPOSITORIES ?? '')
31+
.split(/\r?\n/)
32+
.map((line) => line.trim())
33+
.filter((line) => line.length > 0);
34+
35+
for (const repository of repositories) {
36+
await exec.exec('helm', [
37+
'repo',
38+
'add',
39+
...repository.split(/\s+/),
40+
]);
41+
}
42+
43+
- name: Build chart dependencies
44+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
45+
env:
46+
INPUT_PATH: ${{ inputs.path }}
47+
with:
48+
script: |
49+
const path = require('node:path');
50+
51+
const chartPath = process.env.INPUT_PATH;
52+
if (!chartPath) {
53+
core.setFailed('"path" input is missing');
54+
return;
55+
}
56+
57+
core.info('Building charts dependencies');
58+
59+
const chartRootDir = path.resolve(
60+
process.env.GITHUB_WORKSPACE ?? '.',
61+
chartPath,
62+
);
63+
const chartFiles = [];
64+
const globber = await glob.create(
65+
`${chartPath}/**/Chart.yaml`,
66+
{ followSymbolicLinks: false },
67+
);
68+
69+
for await (const chartFile of globber.globGenerator()) {
70+
chartFiles.push(chartFile);
71+
}
72+
73+
if (chartFiles.length === 0) {
74+
core.info(`No charts found in ${chartRootDir}`);
75+
return;
76+
}
77+
78+
chartFiles.sort();
79+
80+
for (const chartFile of chartFiles) {
81+
const chartDir = path.dirname(chartFile);
82+
core.info(`Building dependencies for ${chartDir}`);
83+
await exec.exec('helm', ['dependency', 'build', chartDir]);
84+
}

actions/helm/release-chart/action.yml

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -252,45 +252,12 @@ runs:
252252
253253
- uses: azure/setup-helm@dda3372f752e03dde6b3237bc9431cdc2f7a02a2 # v5.0.0
254254

255-
- shell: bash
256-
env:
257-
INPUT_HELM_REPOSITORIES: ${{ inputs.helm-repositories }}
258-
run: |
259-
# For each line in the input, add the Helm repository
260-
printf '%s\n' "$INPUT_HELM_REPOSITORIES" | while IFS= read -r line; do
261-
if [ -z "$line" ]; then
262-
continue
263-
fi
264-
265-
# shellcheck disable=SC2086
266-
helm repo add $line
267-
done
268-
269-
- shell: bash
270-
env:
271-
INPUT_PATH: ${{ inputs.path }}
272-
run: |
273-
echo "Building charts dependencies"
274-
275-
CHART_ROOT_DIR="$(pwd)/$INPUT_PATH"
276-
CHART_FILES=$(find "$CHART_ROOT_DIR" -name "Chart.yaml")
277-
278-
# If no files found, exit
279-
if [ -z "$CHART_FILES" ]; then
280-
echo "No charts found in $CHART_ROOT_DIR"
281-
exit 0
282-
fi
283-
284-
# For each chart, build dependencies
285-
for chart in $CHART_FILES; do
286-
if [ ! -f "$chart" ]; then
287-
continue
288-
fi
289-
290-
CHART_DIR=$(dirname "$chart")
291-
echo "Building dependencies for $CHART_DIR"
292-
helm dependency build "$CHART_DIR"
293-
done
255+
- name: Prepare chart dependencies
256+
uses: ./actions/helm/prepare-chart
257+
with:
258+
path: ${{ inputs.path }}
259+
helm-repositories: >-
260+
${{ inputs.helm-repositories }}
294261
295262
- id: chart-releaser
296263
uses: appany/helm-oci-chart-releaser@d94988c92bed2e09c6113981f15f8bb495d10943 # v0.5.0

0 commit comments

Comments
 (0)