1
1
---
2
2
name : " Test Helm Chart"
3
- # yamllint disable-line rule:line-length
4
- description : " Action to test a Helm chart. Mainly using [helm/chart-testing-action](https://github.com/helm/chart-testing-action)"
3
+ description : |
4
+ Action to lint and test installing some Helm chart(s).
5
+ Mainly using [helm/chart-testing-action](https://github.com/helm/chart-testing-action).
6
+
5
7
branding :
6
8
icon : check-circle
7
9
color : gray-dark
@@ -41,15 +43,20 @@ inputs:
41
43
See <https://github.com/docker/login-action#usage>.
42
44
default : ${{ github.token }}
43
45
required : false
46
+ check-diff-only :
47
+ description : |
48
+ Only run lint and tests on changed charts.
49
+ required : false
50
+ default : " true"
44
51
enable-lint :
45
52
description : |
46
53
Enable linting of the Helm chart.
47
54
See <https://github.com/helm/chart-testing/blob/main/doc/ct_lint.md>.
48
55
required : false
49
56
default : " true"
50
- enable-test :
57
+ enable-install :
51
58
description : |
52
- Enable testing of the Helm chart.
59
+ Enable installing the Helm chart.
53
60
See <https://github.com/helm/chart-testing/blob/main/doc/ct_install.md>.
54
61
required : false
55
62
default : " true"
58
65
using : " composite"
59
66
steps :
60
67
- shell : bash
61
- if : ${{ inputs.enable-lint != 'true' && inputs.enable-test != 'true' }}
68
+ if : ${{ inputs.enable-lint != 'true' && inputs.enable-install != 'true' }}
62
69
run : |
63
- echo "::error ::At least one of 'enable-lint' or 'enable-test ' input must be true"
70
+ echo "::error ::At least one of 'enable-lint' or 'enable-install ' input must be true"
64
71
exit 1
65
72
66
73
-
uses :
hoverkraft-tech/ci-github-common/actions/[email protected]
92
99
fi
93
100
94
101
- uses : actions/setup-python@v5
95
- with :
96
- python-version : " 3.12"
97
102
98
103
- name : Set up chart-testing
99
104
@@ -110,86 +115,109 @@ runs:
110
115
helm repo add $line
111
116
done
112
117
113
- - name : Run chart-testing (lint)
114
- if : ${{ inputs.enable-lint == 'true' }}
118
+ - name : Prepare ct variables
119
+ id : prepare-ct-variables
115
120
shell : bash
116
- working-directory : ${{ inputs.working-directory }}
117
121
run : |
118
- LINT_ARGS="--check-version-increment=false --target-branch ${{ github.event.repository.default_branch }}"
122
+ if [ "${{ inputs.check-diff-only }}" == "true" ]; then
123
+ if [ "${{ github.event_name }}" == "pull_request" ]; then
124
+ TARGET_BRANCH="${{ github.event.pull_request.base.ref }}"
125
+ else
126
+ TARGET_BRANCH="${{ github.event.repository.default_branch }}"
127
+ fi
128
+ CT_ARGS="--target-branch $TARGET_BRANCH"
129
+ fi
130
+
119
131
if [ -n "${{ steps.check-ct-yaml.outputs.path }}" ]; then
120
- LINT_ARGS=" --config ${{ steps.check-ct-yaml.outputs.path }}"
132
+ CT_ARGS="$CT_ARGS --config ${{ steps.check-ct-yaml.outputs.path }}"
121
133
fi
122
134
123
- ct lint $LINT_ARGS
135
+ if [ -z "$CT_ARGS" ]; then
136
+ CT_ARGS="--all"
137
+ fi
124
138
125
- - name : Create kind cluster
126
- if : ${{ inputs.enable-test == 'true' }}
127
-
139
+ echo "args=$CT_ARGS" >> "$GITHUB_OUTPUT"
140
+
141
+ # Namespace for the test cluster
142
+ NAMESPACE="test-chart-${{ github.run_id}}-$(uuidgen)"
143
+ echo "namespace=$NAMESPACE" >> "$GITHUB_OUTPUT"
128
144
129
- - name : Install default registry secrets
130
- if : ${{ inputs.enable-test == 'true' }}
145
+ - name : Run chart-testing (lint)
146
+ if : ${{ inputs.enable-lint == 'true' }}
131
147
shell : bash
148
+ working-directory : ${{ inputs.working-directory }}
132
149
run : |
133
- echo "DOCKER_REGISTRY=$DOCKER_REGISTRY"
134
- echo "DOCKER_USERNAME=${DOCKER_USERNAME: -4}" # last 4 characters
135
- echo "DOCKER_PASSWORD=${DOCKER_PASSWORD: -4}" # last 4 characters
136
- if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
137
- kubectl create secret docker-registry regcred \
138
- --docker-server=$DOCKER_REGISTRY \
139
- --docker-username=$DOCKER_USERNAME \
140
- --docker-password=$DOCKER_PASSWORD
141
- else
142
- echo "Docker credentials not provided, skipping secret creation"
143
- fi
144
- env :
145
- DOCKER_REGISTRY : ${{ inputs.oci-registry }}
146
- DOCKER_USERNAME : ${{ inputs.oci-registry-username }}
147
- DOCKER_PASSWORD : ${{ inputs.oci-registry-password }}
150
+ ct lint ${{ steps.prepare-ct-variables.outputs.args }}
148
151
149
- - name : Define target branch
150
- if : ${{ inputs.enable-test == 'true' }}
151
- id : define-target-branch
152
+ - name : Create kind cluster
153
+ if : ${{ inputs.enable-install == 'true' }}
154
+
155
+
156
+ - name : Install default OCI registry secrets
157
+ id : oci-registry-secret
158
+ if : ${{ inputs.enable-install == 'true' && inputs.oci-registry != '' && inputs.oci-registry-username != '' && inputs.oci-registry-password != '' }}
152
159
shell : bash
153
160
run : |
154
- if [ "${{ github.event_name }}" == "pull_request" ]; then
155
- TARGET_BRANCH="${{ github.event.pull_request.base.ref }}"
156
- else
157
- TARGET_BRANCH="${{ github.event.repository.default_branch }}"
158
- fi
159
- echo "target-branch=$TARGET_BRANCH" >> "$GITHUB_OUTPUT"
161
+ # See https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
162
+ NAMESPACE="${{ steps.prepare-ct-variables.outputs.namespace }}"
163
+ kubectl --context kind-chart-testing create namespace "$NAMESPACE"
164
+
165
+ SECRET_NAME="regcred"
166
+ DOCKER_REGISTRY="${{ inputs.oci-registry }}"
167
+ DOCKER_USERNAME="${{ inputs.oci-registry-username }}"
168
+ DOCKER_PASSWORD="${{ inputs.oci-registry-password }}"
169
+
170
+ kubectl --context kind-chart-testing create secret docker-registry "$SECRET_NAME" \
171
+ --namespace="$NAMESPACE" \
172
+ --docker-server=$DOCKER_REGISTRY \
173
+ --docker-username=$DOCKER_USERNAME \
174
+ --docker-password=$DOCKER_PASSWORD
175
+
176
+ echo "oci-registry-secret=$SECRET_NAME" >> "$GITHUB_OUTPUT"
160
177
161
178
- name : Run chart-testing (install)
162
- if : ${{ inputs.enable-test == 'true' }}
179
+ if : ${{ inputs.enable-install == 'true' }}
163
180
shell : bash
164
181
working-directory : ${{ inputs.working-directory }}
165
182
env :
166
183
HELM_EXPERIMENTAL_OCI : true
167
184
run : |
168
- HELM_SET="${{ inputs.helm-set }}"
169
- HELM_EXTRA_SET_ARGS="imagePullSecrets[0].name=regcred"
185
+ NAMESPACE="${{ steps.prepare-ct-variables.outputs.namespace }}"
186
+
187
+ HELM_SET="namespace=$NAMESPACE
188
+ ${{ inputs.helm-set }}"
189
+
190
+ OCI_REGISTRY_SECRET="${{ steps.oci-registry-secret.outputs.oci-registry-secret }}"
191
+ if [ -n "$OCI_REGISTRY_SECRET" ]; then
192
+ # Ensure secret exists
193
+ kubectl --context kind-chart-testing get secret "$OCI_REGISTRY_SECRET" --output=yaml --namespace=$NAMESPACE
194
+
195
+ HELM_SET="$HELM_SET
196
+ imagePullSecrets[0].name=${OCI_REGISTRY_SECRET}"
197
+ fi
198
+
199
+ HELM_EXTRA_SET_ARGS=""
170
200
if [ -n "$HELM_SET" ]; then
171
201
IFS=$'\n' read -r -d '' -a lines <<< "$HELM_SET" || true
172
-
173
202
for line in "${lines[@]}"; do
174
203
if [ -z "$line" ]; then
175
204
continue
176
205
fi
177
206
# Escape commas in the line
178
207
line=$(echo "$line" | sed 's/,/\\,/g') || true
179
- HELM_EXTRA_SET_ARGS+=",${line}"
180
- done
181
208
182
- # Format HELM_EXTRA_SET_ARGS for helm command
183
- if [ -n "$HELM_EXTRA_SET_ARGS" ]; then
184
- HELM_EXTRA_SET_ARGS="--set ${HELM_EXTRA_SET_ARGS:1}"
185
- fi
209
+ if [ -n "$HELM_EXTRA_SET_ARGS" ]; then
210
+ HELM_EXTRA_SET_ARGS="${HELM_EXTRA_SET_ARGS},"
211
+ fi
186
212
187
- echo "::debug::helm-extra-set-args: $HELM_EXTRA_SET_ARGS"
213
+ HELM_EXTRA_SET_ARGS="${HELM_EXTRA_SET_ARGS}${line}"
214
+ done
188
215
fi
189
216
190
- TARGET_BRANCH="${{ steps.define-target-branch.outputs.target-branch }}"
217
+ HELM_EXTRA_SET_ARGS="--set=${HELM_EXTRA_SET_ARGS}"
218
+
219
+ echo "::debug::ct install ${{ steps.prepare-ct-variables.outputs.args }} --helm-extra-set-args ${HELM_EXTRA_SET_ARGS}"
191
220
192
- ct install \
193
- --target-branch "$TARGET_BRANCH" \
194
- --helm-extra-args "--wait" \
195
- --helm-extra-set-args "$HELM_EXTRA_SET_ARGS"
221
+ ct install ${{ steps.prepare-ct-variables.outputs.args }} \
222
+ --namespace $NAMESPACE \
223
+ --helm-extra-set-args ${HELM_EXTRA_SET_ARGS}
0 commit comments