Skip to content

Commit 996b90f

Browse files
msu8kasemAlem
authored andcommitted
feat: add test coverage reporting using Coverport
Integrate coverport for test code coverage reporting See: https://github.com/konflux-ci/coverport Signed-off-by: David Turecek <[email protected]>
1 parent ccdac89 commit 996b90f

File tree

12 files changed

+417
-5
lines changed

12 files changed

+417
-5
lines changed

.github/workflows/codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ jobs:
1919
run: make test
2020
- name: Codecov
2121
uses: codecov/codecov-action@v5
22+
with:
23+
token: ${{ secrets.CODECOV_TOKEN }}
24+
flags: unit-tests

.github/workflows/pr.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ jobs:
132132
make test
133133
- name: Upload coverage to Codecov
134134
uses: codecov/codecov-action@v5
135+
with:
136+
token: ${{ secrets.CODECOV_TOKEN }}
137+
flags: unit-tests
135138
gitlint:
136139
name: Run gitlint checks
137140
runs-on: ubuntu-24.04

.tekton/integration-service-pull-request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ spec:
222222
- name: BUILD_ARGS
223223
value:
224224
- $(params.build-args[*])
225+
- ENABLE_COVERAGE=true
225226
- name: BUILD_ARGS_FILE
226227
value: $(params.build-args-file)
227228
- name: SOURCE_ARTIFACT

.tekton/integration-service-push.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,48 @@ spec:
194194
workspace: git-auth
195195
- name: netrc
196196
workspace: netrc
197+
- name: build-instrumented-image
198+
params:
199+
- name: IMAGE
200+
value: $(params.output-image).instrumented
201+
- name: DOCKERFILE
202+
value: $(params.dockerfile)
203+
- name: CONTEXT
204+
value: $(params.path-context)
205+
- name: HERMETIC
206+
value: $(params.hermetic)
207+
- name: PREFETCH_INPUT
208+
value: $(params.prefetch-input)
209+
- name: IMAGE_EXPIRES_AFTER
210+
value: $(params.image-expires-after)
211+
- name: COMMIT_SHA
212+
value: $(tasks.clone-repository.results.commit)
213+
- name: BUILD_ARGS
214+
value:
215+
- $(params.build-args[*])
216+
- ENABLE_COVERAGE=true
217+
- name: BUILD_ARGS_FILE
218+
value: $(params.build-args-file)
219+
- name: SOURCE_ARTIFACT
220+
value: $(tasks.prefetch-dependencies.results.SOURCE_ARTIFACT)
221+
- name: CACHI2_ARTIFACT
222+
value: $(tasks.prefetch-dependencies.results.CACHI2_ARTIFACT)
223+
runAfter:
224+
- prefetch-dependencies
225+
taskRef:
226+
params:
227+
- name: name
228+
value: buildah-oci-ta
229+
- name: bundle
230+
value: quay.io/konflux-ci/tekton-catalog/task-buildah-oci-ta:0.7@sha256:b54509f5f695c0c89de4587a403099a26da5cdc3707037edd4b7cf4342b63edd
231+
- name: kind
232+
value: task
233+
resolver: bundles
234+
when:
235+
- input: $(tasks.init.results.build)
236+
operator: in
237+
values:
238+
- "true"
197239
- matrix:
198240
params:
199241
- name: PLATFORM

Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@ COPY --chown=1001:0 go.sum go.sum
1515
# Copy the go source
1616
COPY --chown=1001:0 . .
1717

18-
# Build
19-
RUN CGO_ENABLED=0 go build -a -o manager cmd/main.go \
18+
# Build arguments
19+
ARG ENABLE_COVERAGE=false
20+
21+
# Build with or without coverage instrumentation
22+
RUN if [ "$ENABLE_COVERAGE" = "true" ]; then \
23+
echo "Building with coverage instrumentation..."; \
24+
CGO_ENABLED=0 go build -cover -covermode=atomic -tags=coverage -o manager ./cmd; \
25+
else \
26+
echo "Building production binary..."; \
27+
CGO_ENABLED=0 go build -a -o manager ./cmd; \
28+
fi \
2029
&& CGO_ENABLED=0 go build -a -o snapshotgc cmd/snapshotgc/snapshotgc.go
2130

2231
ARG ENABLE_WEBHOOKS=true

cmd/coverage_init.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build coverage
2+
3+
package main
4+
5+
// This file is only included when building with -tags=coverage.
6+
// It starts a coverage HTTP server that allows collecting coverage data
7+
// from the running binary during E2E tests.
8+
9+
import _ "github.com/konflux-ci/coverport/instrumentation/go" // starts coverage server via init()

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/google/go-containerregistry v0.20.6
1414
github.com/google/go-github/v45 v45.2.0
1515
github.com/konflux-ci/application-api v0.0.0-20250324201748-5a9670bf7679
16+
github.com/konflux-ci/coverport/instrumentation/go v0.0.0-20251127115143-b5207b335f8b
1617
github.com/konflux-ci/operator-toolkit v0.0.0-20240402130556-ef6dcbeca69d
1718
github.com/konflux-ci/release-service v0.0.0-20240514150425-d25d533f66ba
1819
github.com/onsi/ginkgo/v2 v2.23.4

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zt
278278
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
279279
github.com/konflux-ci/application-api v0.0.0-20250324201748-5a9670bf7679 h1:mtLA7dQ9iIncxYoOLgty2B1l1cucnp/tsbxQaKn9Myw=
280280
github.com/konflux-ci/application-api v0.0.0-20250324201748-5a9670bf7679/go.mod h1:948Z+a1IbfRT0RtoHzWWSN9YEucSbMJTHaMhz7dVICc=
281+
github.com/konflux-ci/coverport/instrumentation/go v0.0.0-20251127115143-b5207b335f8b h1:NoriO1KRc+7d2/JA07JizqxP0LlA2oJdD5AuQOvEIjE=
282+
github.com/konflux-ci/coverport/instrumentation/go v0.0.0-20251127115143-b5207b335f8b/go.mod h1:WVMHU9A2464s/vjH1xOTm4LJDD4xP+VlEiU+KM0gkSU=
281283
github.com/konflux-ci/operator-toolkit v0.0.0-20240402130556-ef6dcbeca69d h1:z7j3mglNoXvIrw5Vz/Ul+izoITRaqYURPIWrFoEyHgI=
282284
github.com/konflux-ci/operator-toolkit v0.0.0-20240402130556-ef6dcbeca69d/go.mod h1:AcChx7FjpYSIkDvQgaUKyauuF0PXm3ivB5MqZSC9Eis=
283285
github.com/konflux-ci/release-service v0.0.0-20240514150425-d25d533f66ba h1:04A7d9bdym9vY6dXqjFE6RaB3elm7sSthnQQA/IBQxk=

integration-tests/pipelines/konflux-e2e-tests.yaml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ spec:
4646
- name: revision
4747
value: main
4848
- name: pathInRepo
49-
value: tasks/test-metadata/0.3/test-metadata.yaml
49+
value: tasks/test-metadata/0.4/test-metadata.yaml
5050
params:
5151
- name: SNAPSHOT
5252
value: $(params.SNAPSHOT)
@@ -110,9 +110,9 @@ spec:
110110
- name: component-name
111111
value: integration-service
112112
- name: component-image-repository
113-
value: $(tasks.test-metadata.results.container-repo)
113+
value: $(tasks.test-metadata.results.instrumented-container-repo)
114114
- name: component-image-tag
115-
value: $(tasks.test-metadata.results.container-tag)
115+
value: $(tasks.test-metadata.results.instrumented-container-tag)
116116
- name: component-pr-owner
117117
value: $(tasks.test-metadata.results.pull-request-author)
118118
- name: component-pr-sha
@@ -158,6 +158,35 @@ spec:
158158
- name: test-environment
159159
value: "upstream"
160160
finally:
161+
- name: collect-and-upload-coverage
162+
params:
163+
- name: instrumented-images
164+
value: "$(tasks.test-metadata.results.instrumented-container-repo):$(tasks.test-metadata.results.instrumented-container-tag)"
165+
- name: cluster-access-secret-name
166+
value: kfg-$(context.pipelineRun.name)
167+
- name: test-name
168+
value: e2e-tests
169+
- name: oci-container
170+
value: "$(params.oci-container-repo):$(context.pipelineRun.name)-coverport"
171+
- name: codecov-flags
172+
value: e2e-tests
173+
- name: credentials-secret-name
174+
value: "integration-service-coverport-secrets"
175+
taskRef:
176+
resolver: git
177+
params:
178+
- name: url
179+
value: https://github.com/konflux-ci/tekton-integration-catalog.git
180+
- name: revision
181+
value: main
182+
- name: pathInRepo
183+
value: tasks/coverport-coverage/0.1/coverport-coverage.yaml
184+
when:
185+
- input: $(tasks.konflux-e2e-tests.status)
186+
operator: in
187+
values:
188+
- Succeeded
189+
- Failed
161190
- name: store-pipeline-status
162191
taskRef:
163192
resolver: git

vendor/github.com/konflux-ci/coverport/instrumentation/go/LICENSE

Lines changed: 201 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)