Skip to content

Commit cc13225

Browse files
committed
feat: add helm integration tests workflow and integrate with publish and tests workflows
1 parent 5fc7e76 commit cc13225

3 files changed

Lines changed: 181 additions & 93 deletions

File tree

.github/workflows/helm-tests.yaml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: Helm integration tests
2+
on:
3+
workflow_call:
4+
inputs:
5+
build-operator:
6+
description: "Build operator image from source (false = use published image from chart defaults)"
7+
required: false
8+
type: boolean
9+
default: true
10+
secrets:
11+
MONDOO_TEST_ORG_TOKEN:
12+
required: true
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
build-operator:
19+
if: inputs.build-operator
20+
runs-on: ubuntu-latest
21+
name: Build operator container
22+
steps:
23+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24+
with:
25+
ref: ${{ github.event.pull_request.head.sha }}
26+
persist-credentials: false
27+
fetch-depth: 0 # fetch is needed for "git tag --list" in the Makefile
28+
- name: Import environment variables from file
29+
run: cat ".github/env" >> $GITHUB_ENV
30+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
31+
with:
32+
go-version: "${{ env.golang-version }}"
33+
- name: Build operator container image
34+
run: make docker-save
35+
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
36+
with:
37+
name: helm-operator-build
38+
path: operator.tar
39+
retention-days: 1
40+
41+
helm-tests:
42+
name: Helm integration tests (${{ matrix.k8s-version }})
43+
runs-on: ubuntu-latest
44+
needs: [build-operator]
45+
if: always() && (needs.build-operator.result == 'success' || needs.build-operator.result == 'skipped')
46+
47+
permissions:
48+
contents: read
49+
checks: write
50+
statuses: write
51+
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
k8s-version: [v1.32.0, v1.35.0]
56+
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
60+
with:
61+
fetch-depth: 0
62+
63+
- name: Import environment variables from file
64+
run: cat ".github/env" >> $GITHUB_ENV
65+
66+
- name: Install Go
67+
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
68+
with:
69+
go-version: "${{ env.golang-version }}"
70+
71+
- name: Start minikube
72+
uses: medyagh/setup-minikube@master
73+
with:
74+
memory: 4000m
75+
kubernetes-version: ${{ matrix.k8s-version }}
76+
77+
- name: Install Helm
78+
uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
79+
with:
80+
token: ${{ secrets.GITHUB_TOKEN }}
81+
id: install
82+
83+
- name: Download operator build artifact
84+
if: inputs.build-operator
85+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
86+
with:
87+
name: helm-operator-build
88+
89+
- name: Load operator image into minikube
90+
if: inputs.build-operator
91+
run: minikube image load operator.tar
92+
93+
- name: Determine operator image tag
94+
id: image-tag
95+
run: |
96+
if [ "${{ inputs.build-operator }}" = "true" ]; then
97+
echo "tag=sha256-$(git rev-parse HEAD).sig" >> $GITHUB_OUTPUT
98+
else
99+
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
100+
fi
101+
102+
- name: Install Mondoo Operator Helm chart
103+
run: |
104+
HELM_ARGS=""
105+
if [ "${{ inputs.build-operator }}" = "true" ]; then
106+
HELM_ARGS="--set controllerManager.manager.image.tag=${{ steps.image-tag.outputs.tag }} --set controllerManager.manager.imagePullPolicy=Never"
107+
fi
108+
helm install mondoo-operator charts/mondoo-operator -n mondoo-operator --create-namespace --wait $HELM_ARGS
109+
110+
# Now that dependencies are cached the tests start almost immediately after minikube has started
111+
# this makes tests fail occasionally. This sleep gives the runner some time to become more stable
112+
# before the test execution starts.
113+
- name: Wait a bit for the runner to become more stable
114+
run: kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=60s
115+
116+
- name: Run integration tests
117+
env:
118+
MONDOO_API_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
119+
run: EXTERNAL_INSTALLATION=1 VERSION=${{ steps.image-tag.outputs.tag }} make test/integration/ci
120+
121+
- run: mv integration-tests.xml integration-tests-helm-${{ matrix.k8s-version }}.xml
122+
if: success() || failure()
123+
124+
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
125+
if: success() || failure()
126+
with:
127+
name: test-results-helm-${{ matrix.k8s-version }}
128+
path: integration-tests-helm-${{ matrix.k8s-version }}.xml
129+
130+
- name: Upload test logs artifact
131+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
132+
if: failure()
133+
with:
134+
name: helm-test-logs-${{ matrix.k8s-version }}
135+
path: /home/runner/work/mondoo-operator/mondoo-operator/tests/integration/_output/
136+
137+
report-tests:
138+
name: Report helm test results
139+
runs-on: ubuntu-latest
140+
needs: [helm-tests]
141+
if: always()
142+
permissions:
143+
actions: read
144+
contents: read
145+
checks: write
146+
pull-requests: write
147+
steps:
148+
- name: Download test results
149+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
150+
with:
151+
pattern: test-results-helm-*
152+
merge-multiple: true
153+
154+
- name: Publish Test Results
155+
uses: EnricoMi/publish-unit-test-result-action@27d65e188ec43221b20d26de30f4892fad91df2f # v2.22.0
156+
with:
157+
commit: ${{ github.event.workflow_run.head_sha }}
158+
event_file: ${{ github.event_path }}
159+
event_name: ${{ github.event.workflow_run.event }}
160+
files: "*.xml"

.github/workflows/publish.yaml

Lines changed: 8 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -240,107 +240,22 @@ jobs:
240240
# this should ensure the manifest is tagged latest, which is required for the install automation
241241
- release-helm
242242

243-
# publish helm chart after the release of container images is complete
243+
# Run helm integration tests using the published container images
244244
run-helm-tests:
245-
name: Run helm integration tests
246245
if: startsWith(github.ref, 'refs/tags/v')
247246
needs:
248247
- push-virtual-tag
249-
runs-on: ubuntu-latest
250-
248+
uses: ./.github/workflows/helm-tests.yaml
249+
with:
250+
build-operator: false
251251
permissions:
252252
contents: read
253+
actions: read
253254
checks: write
254255
statuses: write
255-
256-
strategy:
257-
fail-fast: false
258-
matrix:
259-
k8s-version: [v1.32.0, v1.35.0]
260-
261-
steps:
262-
- name: Checkout
263-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
264-
with:
265-
fetch-depth: 0
266-
267-
- name: Import environment variables from file
268-
run: cat ".github/env" >> $GITHUB_ENV
269-
270-
- name: Install Go
271-
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
272-
with:
273-
go-version: "${{ env.golang-version }}"
274-
275-
- name: Start minikube
276-
uses: medyagh/setup-minikube@master
277-
with:
278-
memory: 4000m
279-
kubernetes-version: ${{ matrix.k8s-version }}
280-
281-
- name: Install Helm
282-
uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
283-
with:
284-
token: ${{ secrets.GITHUB_TOKEN }}
285-
id: install
286-
287-
- name: Extract Docker metadata
288-
id: meta
289-
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
290-
with:
291-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
292-
293-
- name: Install Mondoo Operator Helm chart
294-
run: helm install mondoo-operator charts/mondoo-operator -n mondoo-operator --create-namespace --wait
295-
296-
# Now that dependencies are cached the tests start almost immediately after minikube has started
297-
# this makes tests fail occasionally. This sleep gives the runner some time to become more stable
298-
# before the test execution starts.
299-
- name: Wait a bit for the runner to become more stable
300-
run: kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=60s
301-
302-
- name: Run integration tests
303-
env:
304-
MONDOO_API_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
305-
run: EXTERNAL_INSTALLATION=1 VERSION=${{ steps.meta.outputs.version }} make test/integration/ci
306-
307-
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
308-
if: success() || failure() # run this step even if previous step failed
309-
with: # upload a combined archive with unit and integration test results
310-
name: test-results-helm-${{ matrix.k8s-version }}
311-
path: integration-tests-helm-${{ matrix.k8s-version }}.xml
312-
313-
- name: Upload test logs artifact
314-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
315-
if: failure()
316-
with:
317-
name: helm-test-logs-${{ matrix.k8s-version }}
318-
path: /home/runner/work/mondoo-operator/mondoo-operator/tests/integration/_output/
319-
320-
report-tests:
321-
name: Report test results
322-
runs-on: ubuntu-latest
323-
needs:
324-
- run-helm-tests
325-
permissions:
326-
actions: read # Required to read the artifact
327-
contents: read # Required to read the source
328-
checks: write # Required to write the results
329-
pull-requests: write # Required to write comments
330-
steps:
331-
- name: Download test results
332-
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
333-
with:
334-
pattern: test-results-*
335-
merge-multiple: true
336-
337-
- name: Publish Test Results
338-
uses: EnricoMi/publish-unit-test-result-action@27d65e188ec43221b20d26de30f4892fad91df2f # v2.22.0
339-
with:
340-
commit: ${{ github.event.workflow_run.head_sha }}
341-
event_file: ${{ github.event_path }}
342-
event_name: ${{ github.event.workflow_run.event }}
343-
files: "*.xml"
256+
pull-requests: write
257+
secrets:
258+
MONDOO_TEST_ORG_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
344259

345260
release-helm:
346261
name: Release helm chart

.github/workflows/tests.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,16 @@ jobs:
4242
with:
4343
cnspecImageTag: ""
4444
secrets: inherit
45+
helm-tests:
46+
name: Helm tests
47+
needs: [unit-tests]
48+
if: needs.unit-tests.result == 'success'
49+
uses: ./.github/workflows/helm-tests.yaml
50+
permissions:
51+
contents: read
52+
actions: read
53+
checks: write
54+
statuses: write
55+
pull-requests: write
56+
secrets:
57+
MONDOO_TEST_ORG_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}

0 commit comments

Comments
 (0)