Skip to content

Commit 08a7142

Browse files
committed
feat(59649): enable code coverage for Java path
1 parent 28b84b5 commit 08a7142

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

.github/workflows/ci-cd-java.yml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
required: true
1212
DOCKER_PASSWORD:
1313
required: true
14+
CODECOV_TOKEN:
15+
required: false
1416
inputs:
1517
# it is required for backwards compatibility with CI/CD pipelines that have not been yet fully migrated to shared workflows
1618
uploadJarArtifact:
@@ -38,10 +40,20 @@ on:
3840
required: false
3941
type: boolean
4042
default: false
43+
codeCoverageEnabled:
44+
required: false
45+
type: boolean
46+
default: false
47+
codeCoverageExcludes:
48+
required: false
49+
type: string
50+
default: ""
4151

4252
env:
4353
IMAGE_NAME_MIXED_CASE: "${{ github.repository }}"
4454
TEST_STAGE: test
55+
JACOCO_VERSION: "0.8.12"
56+
JACOCO_REPORTS: "**/target/site/jacoco/jacoco.xml,**/target/site/jacoco-it/jacoco.xml,**/target/site/jacoco-aggregate/jacoco.xml"
4557

4658
jobs:
4759
build-check-test-push:
@@ -68,15 +80,52 @@ jobs:
6880
6981
- name: Run tests outside Docker
7082
working-directory: ${{ inputs.workingDirectory }}
71-
run: mvn test
83+
run: |
84+
JACOCO_EXCLUDES_ARG=""
85+
if [[ -n "${JACOCO_EXCLUDES}" ]]; then
86+
JACOCO_EXCLUDES_ARG="-Djacoco.excludes=${JACOCO_EXCLUDES}"
87+
fi
88+
if [[ "${CODE_COVERAGE_ENABLED}" == "true" ]]; then
89+
mvn "org.jacoco:jacoco-maven-plugin:${JACOCO_VERSION}:prepare-agent" \
90+
test \
91+
"org.jacoco:jacoco-maven-plugin:${JACOCO_VERSION}:report" \
92+
${JACOCO_EXCLUDES_ARG}
93+
else
94+
mvn test
95+
fi
7296
env:
7397
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
CODE_COVERAGE_ENABLED: ${{ inputs.codeCoverageEnabled }}
99+
JACOCO_EXCLUDES: ${{ inputs.codeCoverageExcludes }}
74100

75101
- name: Run Integration tests (Testcontainers)
76102
working-directory: ${{ inputs.workingDirectory }}
77-
run: mvn verify
103+
run: |
104+
JACOCO_EXCLUDES_ARG=""
105+
if [[ -n "${JACOCO_EXCLUDES}" ]]; then
106+
JACOCO_EXCLUDES_ARG="-Djacoco.excludes=${JACOCO_EXCLUDES}"
107+
fi
108+
if [[ "${CODE_COVERAGE_ENABLED}" == "true" ]]; then
109+
mvn "org.jacoco:jacoco-maven-plugin:${JACOCO_VERSION}:prepare-agent-integration" \
110+
verify \
111+
"org.jacoco:jacoco-maven-plugin:${JACOCO_VERSION}:report-integration" \
112+
${JACOCO_EXCLUDES_ARG}
113+
else
114+
mvn verify
115+
fi
78116
env:
79117
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118+
CODE_COVERAGE_ENABLED: ${{ inputs.codeCoverageEnabled }}
119+
JACOCO_EXCLUDES: ${{ inputs.codeCoverageExcludes }}
120+
121+
- name: Upload coverage reports to Codecov
122+
if: ${{ inputs.codeCoverageEnabled }}
123+
uses: codecov/codecov-action@v5
124+
with:
125+
token: ${{ secrets.CODECOV_TOKEN }}
126+
files: ${{ env.JACOCO_REPORTS }}
127+
fail_ci_if_error: true
128+
verbose: true
80129

81130
- name: Build artifact
82131
working-directory: ${{ inputs.workingDirectory }}
@@ -173,4 +222,4 @@ jobs:
173222
context: ${{ inputs.workingDirectory }}
174223
push: ${{ env.PERFORM_RELEASE }}
175224
tags: ${{ steps.meta.outputs.tags }}
176-
labels: ${{ steps.meta.outputs.labels }}
225+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea
1+
.idea
2+
/AGENTS.md

0 commit comments

Comments
 (0)