Skip to content

Commit

Permalink
ci: added code coverage PR and optimize image build
Browse files Browse the repository at this point in the history
  • Loading branch information
chgl committed May 9, 2024
1 parent e5d5363 commit 1aeebf3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
42 changes: 40 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,49 @@ jobs:
actions: read
security-events: write
with:
enable-build-test-layer: false
enable-upload-test-image: false
enable-build-test-layer: true
enable-upload-test-image: true
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}

add-test-coverage:
runs-on: ubuntu-22.04
needs:
- build
permissions:
# for add Coverage PR Comment
pull-requests: write
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Download test image
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
name: ${{ needs.build.outputs.image-slug }}-test
path: /tmp

- name: Load test image
run: |
ls -lsa /tmp
docker load --input /tmp/image-test.tar
docker image ls
- name: Copy unit test coverage reports from test container
env:
UNIT_TEST_IMAGE: ${{ fromJson(needs.build.outputs.test-image-meta-json).tags[0] }}
run: |
docker create --name=unit-test-container "${UNIT_TEST_IMAGE}"
docker cp unit-test-container:/test ${{ github.workspace }}/test
- name: Add coverage to PR
id: jacoco
uses: madrapps/jacoco-report@db72e7e7c96f98d239967958b0a0a6ca7d3bb45f # v1.6.1
with:
paths: |
${{ github.workspace }}/test/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60

test:
name: run k8s smoke test
runs-on: ubuntu-22.04
Expand Down
28 changes: 17 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
FROM docker.io/library/gradle:8.6.0-jdk17@sha256:27ed98487dd9c155d555955084dfd33f32d9f7ac5a90a79b1323ab002a1a8b6e AS build
WORKDIR /home/gradle/src
ENV GRADLE_USER_HOME /gradle
WORKDIR /home/gradle/project

COPY build.gradle settings.gradle ./
RUN gradle clean build --no-daemon || true
RUN --mount=type=cache,target=/home/gradle/.gradle/caches gradle clean build --no-daemon || true

COPY --chown=gradle:gradle . .
RUN gradle clean build --info && \
gradle jacocoTestReport && \
awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }' build/jacoco/coverage.csv && \
java -Djarmode=layertools -jar build/libs/obds-to-fhir-*.jar extract

RUN --mount=type=cache,target=/home/gradle/.gradle/caches <<EOF
gradle clean build --info --no-daemon
gradle jacocoTestReport --no-daemon
java -Djarmode=layertools -jar build/libs/obds-to-fhir-*.jar extract
EOF

FROM scratch AS test
WORKDIR /test
COPY --from=build /home/gradle/project/build/reports/ .
ENTRYPOINT [ "true" ]

FROM docker.io/library/debian:11.9-slim@sha256:715354035496a48b9c4c8f146a6f751de70449913773038776eb1f3d01c93989 AS jemalloc
# hadolint ignore=DL3008
Expand All @@ -26,10 +32,10 @@ ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so"

COPY --from=jemalloc /usr/lib/x86_64-linux-gnu/libjemalloc.so /usr/lib/x86_64-linux-gnu/libjemalloc.so

COPY --from=build /home/gradle/src/dependencies/ ./
COPY --from=build /home/gradle/src/spring-boot-loader/ ./
COPY --from=build /home/gradle/src/snapshot-dependencies/ ./
COPY --from=build /home/gradle/src/application/ ./
COPY --from=build /home/gradle/project/dependencies/ ./
COPY --from=build /home/gradle/project/spring-boot-loader/ ./
COPY --from=build /home/gradle/project/snapshot-dependencies/ ./
COPY --from=build /home/gradle/project/application/ ./

USER 65532:65532
ENTRYPOINT ["java", "-XX:MaxRAMPercentage=75", "org.springframework.boot.loader.launch.JarLauncher"]
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ spotless {

jacocoTestReport {
reports {
csv.outputLocation = file(layout.buildDirectory.dir('jacoco/coverage.csv'))
csv.required = true
html.outputLocation = file(layout.buildDirectory.dir('jacoco/coverage.html'))
html.required = true
xml.required = false
xml.required = true
}
}

Expand Down

0 comments on commit 1aeebf3

Please sign in to comment.