Skip to content

Commit e1c62a9

Browse files
Alex-Welshsd109
andauthored
Add helm chart linting and snapshot testing (#407)
Implementation based on azimuth-cloud/cluster-api-janitor-openstack#192 --------- Co-authored-by: Scott Davidson <[email protected]>
1 parent ba2cfff commit e1c62a9

File tree

9 files changed

+538
-3
lines changed

9 files changed

+538
-3
lines changed

.github/workflows/helm-lint.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# NOTE: This workflow can be run locally using https://github.com/nektos/act with:
2+
# act -W .github/workflows/helm-lint.yaml workflow_call -s GITHUB_TOKEN=$(gh auth token)
3+
name: Helm Lint
4+
on:
5+
workflow_call:
6+
inputs:
7+
ref:
8+
type: string
9+
description: The Git ref under test.
10+
required: true
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ inputs.ref }}
20+
fetch-depth: 0
21+
22+
- name: Set up Helm
23+
uses: azure/setup-helm@v4
24+
with:
25+
version: v3.15.3
26+
27+
- name: Set up chart-testing
28+
uses: helm/chart-testing-action@v2
29+
30+
- name: Run chart-testing (lint)
31+
run: |-
32+
ct lint \
33+
--target-branch ${{ github.event.repository.default_branch }} \
34+
--charts chart/ \
35+
--validate-maintainers=false
36+
37+
- name: Run template validation
38+
run: |-
39+
helm template foo chart \
40+
| docker run -i --rm ghcr.io/yannh/kubeconform:latest \
41+
--strict --summary
42+
43+
- name: Run manifest snapshot test
44+
run: docker run -i --rm -v $(pwd):/apps helmunittest/helm-unittest chart

.github/workflows/test-pr.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ jobs:
2424
with:
2525
ref: ${{ github.event.pull_request.head.sha }}
2626

27+
# Run the chart linting on every PR, even from external repos
28+
lint:
29+
uses: ./.github/workflows/lint.yaml
30+
with:
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
2733
# This job exists so that PRs from outside the main repo are rejected
2834
fail_on_remote:
2935
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributing
2+
3+
We welcome contributions and suggestions for improvements to this code base.
4+
Please check for relevant issues and PRs before opening a new one of your own.
5+
6+
## Making a contribution
7+
8+
### Helm template snapshots
9+
10+
The CI in this repository uses the Helm
11+
[unittest](https://github.com/helm-unittest/helm-unittest) plugin's
12+
snapshotting functionality to check PRs for changes to the templated manifests.
13+
Therefore, if your PR makes changes to the manifest templates or values, you
14+
will need to update the saved snapshots to allow your changes to pass the
15+
automated tests. The easiest way to do this is to run the helm unittest command
16+
inside a docker container from the repo root.
17+
18+
```
19+
docker run -i --rm -v $(pwd):/apps helmunittest/helm-unittest chart -u
20+
```
21+
22+
where the `-u` option is used to update the existing snapshots.

chart/.helmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
.idea/
2222
*.tmproj
2323
.vscode/
24+
# Helm unit-test files
25+
tests/

chart/files/api/settings/01-django.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SECRET_KEY: {{ .Values.settings.secretKey | default (randAlphaNum 64) }}
1+
SECRET_KEY: {{ .Values.settings.secretKey | required "No Django secret key specified" }}
22
DEBUG: {{ .Values.settings.debug }}
33
CSRF_COOKIE_SECURE: {{ .Values.ingress.tls.enabled }}
44
{{- with .Values.settings.csrfCookieName }}

0 commit comments

Comments
 (0)