Skip to content

Commit ebf20b5

Browse files
fredlegerneilime
authored andcommitted
feat: add helm ct
1 parent aae565c commit ebf20b5

File tree

10 files changed

+244
-5
lines changed

10 files changed

+244
-5
lines changed

.github/workflows/__shared-ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ jobs:
3636
needs: linter
3737
uses: ./.github/workflows/__test-action-helm-release-chart.yml
3838

39+
test-action-helm-test-chart:
40+
needs: linter
41+
uses: ./.github/workflows/__test-action-helm-test-chart.yml
42+
3943
test-workflow-docker-build-images:
4044
name: Test docker build images
4145
needs: linter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Test for "helm/test-chart" action
2+
run-name: Test for "helm/test-chart" action
3+
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
tests:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- id: get-image-metadata
17+
uses: ./actions/docker/get-image-metadata
18+
with:
19+
oci-registry: ghcr.io
20+
image: application-test
21+
22+
- id: test-chart
23+
uses: ./actions/helm/test-chart
24+
with:
25+
image-tag: "${{ steps.get-image-metadata.outputs.tags }}"

.tool-versions

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
helm 3.12.1
2+
kubectl 1.28.5
3+
helm-ct 3.8.0

actions/helm/test-chart/README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!-- start branding -->
2+
<!-- end branding -->
3+
<!-- start title -->
4+
5+
# GitHub Action: Test Helm Chart
6+
7+
<!-- end title -->
8+
<!-- start badges -->
9+
<!-- end badges -->
10+
<!-- start description -->
11+
12+
Action to test a Helm chart
13+
14+
<!-- end description -->
15+
<!-- start contents -->
16+
<!-- end contents -->
17+
<!-- start usage -->
18+
19+
```yaml
20+
- uses: hoverkraft-tech/ci-github-container/actions/helm/[email protected]
21+
with:
22+
# The extra parameter image.tag to pass to the helm release
23+
# defaults to null
24+
image-tag: "1.0.0"
25+
```
26+
27+
<!-- end usage -->
28+
<!-- start inputs -->
29+
30+
| **Input** | **Description** | **Default** | **Required** |
31+
| --------- | --------------------------------------------------------- | ----------- | ------------ |
32+
| image-tag | The extra parameter image.tag to pass to the helm release | null |  false |
33+
34+
<!-- end inputs -->
35+
<!-- start outputs -->
36+
37+
| **Output** | **Description** | **Default** | **Required** |
38+
| ---------- | --------------- | ----------- | ------------ |
39+
40+
<!-- end outputs -->
41+
<!-- start [.github/ghadocs/examples/] -->
42+
<!-- end [.github/ghadocs/examples/] -->

actions/helm/test-chart/action.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: "Test Helm Chart"
2+
description: "Action to test a Helm chart"
3+
branding:
4+
icon: upload-cloud
5+
color: gray-dark
6+
7+
inputs:
8+
image-tag:
9+
description: "The extra parameter image.tag to pass to the helm release"
10+
required: false
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- uses: hoverkraft-tech/ci-github-common/actions/[email protected]
16+
with:
17+
# Fetch all history so that we can compare against the target branch
18+
fetch-depth: 0
19+
20+
- name: Check for .tools-version file
21+
id: check-tools-version
22+
run: |
23+
if [[ -f .tools-version ]]; then
24+
echo "tools-version-exists=true" >> "$GITHUB_OUTPUT"
25+
else
26+
echo "tools-version-exists=false" >> "$GITHUB_OUTPUT"
27+
fi
28+
29+
- name: Install tools with asdf
30+
if: steps.check-tools-version.outputs.tools-version-exists == 'true'
31+
uses: asdf-vm/actions/install@v3
32+
33+
- name: Check for ct.yaml file
34+
id: check-ct-yaml
35+
run: |
36+
if [[ -f ct.yaml ]]; then
37+
echo "ct-yaml-exists=true" >> "$GITHUB_OUTPUT"
38+
else
39+
echo "ct-yaml-exists=false" >> "$GITHUB_OUTPUT"
40+
fi
41+
42+
- uses: actions/setup-python@v5
43+
with:
44+
python-version: '3.12'
45+
46+
- name: Set up chart-testing
47+
if: steps.check-ct-yaml.outputs.ct-yaml-exists == 'true'
48+
uses: helm/[email protected]
49+
50+
- name: Run chart-testing (list-changed)
51+
id: list-changed
52+
if: steps.check-ct-yaml.outputs.ct-yaml-exists == 'true'
53+
run: |
54+
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
55+
if [[ -n "$changed" ]]; then
56+
echo "changed=true" >> "$GITHUB_OUTPUT"
57+
fi
58+
59+
- name: Run chart-testing (lint)
60+
if: steps.list-changed.outputs.changed == 'true'
61+
run: ct lint --target-branch ${{ github.event.repository.default_branch }}
62+
63+
- name: Create kind cluster
64+
if: steps.list-changed.outputs.changed == 'true'
65+
uses: helm/[email protected]
66+
67+
- name: Run chart-testing (install)
68+
if: steps.list-changed.outputs.changed == 'true'
69+
run: |
70+
if [[ -n "${{ inputs.image-tag }}" ]]; then
71+
HELM_EXTRA_ARGS="--set image.tag=${{ inputs.image-tag }}"
72+
fi
73+
74+
ct install \
75+
--target-branch ${{ github.event.repository.default_branch }} \
76+
--helm-extra-args "${HELM_EXTRA_ARGS} --wait"

ct.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
chart-dirs:
2+
- tests/charts
3+
charts:
4+
- tests/charts/application
5+
chart-yaml-schema: tests/charts/chart-schema.yaml
6+
lint-conf: tests/charts/lintconf.yaml
7+
helm-dependency-extra-args:
8+
- --skip-refresh
9+
validate-maintainers: false

tests/charts/application/ci/empty-values.yaml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4-
name: { { include "test-application.fullname" . } }
5-
labels: { { - include "test-application.labels" . | nindent 4 } }
4+
name: {{ include "test-application.fullname" . }}
5+
labels:
6+
{{- include "test-application.labels" . | nindent 4 }}
67
spec:
7-
type: { { .Values.service.type } }
8+
type: {{ .Values.service.type }}
89
ports:
9-
- port: { { .Values.service.port } }
10+
- port: {{ .Values.service.port }}
1011
targetPort: http
1112
protocol: TCP
1213
name: http
13-
selector: { { - include "test-application.selectorLabels" . | nindent 4 } }
14+
selector:
15+
{{- include "test-application.selectorLabels" . | nindent 4 }}

tests/charts/chart-schema.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: str()
2+
home: str(required=False)
3+
version: str()
4+
apiVersion: str()
5+
appVersion: any(str(), num(), required=False)
6+
description: str(required=False)
7+
keywords: list(str(), required=False)
8+
sources: list(str(), required=False)
9+
maintainers: list(include('maintainer'), required=False)
10+
dependencies: list(include('dependency'), required=False)
11+
icon: str(required=False)
12+
engine: str(required=False)
13+
condition: str(required=False)
14+
tags: str(required=False)
15+
deprecated: bool(required=False)
16+
kubeVersion: str(required=False)
17+
annotations: map(str(), str(), required=False)
18+
type: str(required=False)
19+
---
20+
maintainer:
21+
name: str()
22+
email: str(required=False)
23+
url: str(required=False)
24+
---
25+
dependency:
26+
name: str()
27+
version: str()
28+
repository: str(required=False)
29+
condition: str(required=False)
30+
tags: list(str(), required=False)
31+
enabled: bool(required=False)
32+
import-values: any(list(str()), list(include('import-value')), required=False)
33+
alias: str(required=False)
34+
---
35+
import-value:
36+
child: str()
37+
parent: str()

tests/charts/lintconf.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
rules:
2+
braces:
3+
min-spaces-inside: 0
4+
max-spaces-inside: 0
5+
min-spaces-inside-empty: -1
6+
max-spaces-inside-empty: -1
7+
brackets:
8+
min-spaces-inside: 0
9+
max-spaces-inside: 0
10+
min-spaces-inside-empty: -1
11+
max-spaces-inside-empty: -1
12+
colons:
13+
max-spaces-before: 0
14+
max-spaces-after: 1
15+
commas:
16+
max-spaces-before: 0
17+
min-spaces-after: 1
18+
max-spaces-after: 1
19+
comments:
20+
require-starting-space: true
21+
min-spaces-from-content: 2
22+
document-end: disable
23+
document-start: disable # No --- to start a file
24+
empty-lines:
25+
max: 2
26+
max-start: 0
27+
max-end: 0
28+
hyphens:
29+
max-spaces-after: 1
30+
indentation:
31+
spaces: consistent
32+
indent-sequences: whatever # - list indentation will handle both indentation and without
33+
check-multi-line-strings: false
34+
key-duplicates: enable
35+
line-length: disable # Lines can be any length
36+
new-line-at-end-of-file: disable
37+
new-lines:
38+
type: unix
39+
trailing-spaces: enable
40+
truthy:
41+
level: warning

0 commit comments

Comments
 (0)