Skip to content

Commit 4f30bd9

Browse files
authored
Merge pull request #608 from binkley/gradle-coverage-report
Gradle coverage report in GitHub
2 parents 023950f + 9f3b53a commit 4f30bd9

File tree

5 files changed

+47
-43
lines changed

5 files changed

+47
-43
lines changed

.github/workflows/ci-earthly-gradle.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,42 @@ jobs:
6868
- name: Execute run script
6969
run: earthly --secret OWASP_NVD_API_KEY +run-with-gradle
7070

71+
# Save artifacts for build
72+
# See Earthfile that copies these from container to local
73+
74+
# Javadoc HTML and jars
75+
76+
- name: Save Javadoc HTML for main
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: javadoc-html
80+
if-no-files-found: error
81+
path: build/docs/javadoc/
82+
83+
- name: Save Javadoc HTML Jar for main
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: javadoc-jar
87+
if-no-files-found: error
88+
path: build/libs/modern-java-practices-0-SNAPSHOT-javadoc.jar
89+
90+
# Generate coverage report
91+
7192
- name: Save coverage report
7293
uses: actions/upload-artifact@v4
7394
with:
7495
name: coverage-report
7596
if-no-files-found: error
7697
path: build/reports/jacoco/test/
98+
99+
- name: Generate coverage badge
100+
uses: cicirello/jacoco-badge-generator@v2
101+
with:
102+
badges-directory: images
103+
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
104+
# To avoid conflicts with the Maven build, only generate the badge
105+
# there. For Gradle only projects: REMOVE THIS LINE.
106+
generate-coverage-badge: false
107+
generate-branches-badge: false
108+
generate-summary: false
109+

.github/workflows/ci-earthly-maven.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
- name: Execute run script
7171
run: earthly --secret OWASP_NVD_API_KEY +run-with-maven
7272

73-
# Save artifacts for build
73+
# Save artifacts for build
7474
# See Earthfile that copies these from container to local
7575

7676
# Javadoc HTML and jars
@@ -103,7 +103,7 @@ jobs:
103103
if-no-files-found: error
104104
path: target/modern-java-practices-0-SNAPSHOT-test-javadoc.jar
105105

106-
# Coverage badge report
106+
# Coverage coverage report
107107

108108
- name: Save coverage report
109109
uses: actions/upload-artifact@v4
@@ -112,7 +112,7 @@ jobs:
112112
if-no-files-found: error
113113
path: target/site/jacoco/
114114

115-
# Generage coverage badge for README
115+
# Generate coverage badge for README
116116
# Gradle builds are similar but will require configuration the path for the
117117
# CSV JaCoCo report.
118118

Earthfile

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,15 @@ build-with-gradle:
1212
COPY src src
1313
RUN --secret OWASP_NVD_API_KEY ./gradlew clean build
1414

15+
# For CI so that GitHub can copy artifacts:
16+
# Just copy everything rather than maintain a whitelist of files/dirs.
17+
SAVE ARTIFACT --keep-ts build AS LOCAL build
18+
1519
run-with-gradle:
1620
FROM +build-with-gradle
1721
COPY run-with-gradle.sh .
1822
RUN ./run-with-gradle.sh
1923

20-
# For CI so that GitHub can copy artifacts
21-
# Coverage reports
22-
SAVE ARTIFACT --keep-ts build/reports/jacoco/test/ AS LOCAL build/reports/jacoco/test/
23-
# Javadocs and jars
24-
SAVE ARTIFACT --keep-ts build/libs/modern-java-practices-0-javadoc.jar
25-
SAVE ARTIFACT --keep-ts build/docs/javadoc/ AS LOCAL build/docs/javadoc/
26-
27-
# Test coverage and badge for Gradle:
28-
# You need to PICK ONE from Gradle or Maven for your build.
29-
# This project uses Maven (see below) to create the code coverage badge to
30-
# avoid multiple updating.
31-
# Commented is the minimum needed from the containerized build when using
32-
# Gradle.
33-
# After this enabling this, you still need to update the GitHub action steps
34-
# to generate the badge using a custom path to the CVS report.
35-
# SAVE ARTIFACT --save-ts build/reports/jacoco/test/jacocoTestReport.csv AS LOCAL build/reports/jacoco/test/jacocoTestReport.csv
36-
3724
build-with-maven:
3825
COPY mvnw .
3926
COPY .mvn .mvn
@@ -42,20 +29,9 @@ build-with-maven:
4229
COPY src src
4330
RUN --secret OWASP_NVD_API_KEY ./mvnw --no-transfer-progress clean verify
4431

45-
# For CI so that GitHub can copy artifacts
46-
# Coverage reports
47-
SAVE ARTIFACT --keep-ts target/site/jacoco/
48-
# Javadocs and jars
49-
SAVE ARTIFACT --keep-ts target/modern-java-practices-0-SNAPSHOT-javadoc.jar AS LOCAL target/modern-java-practices-0-SNAPSHOT-javadoc.jar
50-
SAVE ARTIFACT --keep-ts target/apidocs/ AS LOCAL target/apidocs/
51-
SAVE ARTIFACT --keep-ts target/modern-java-practices-0-SNAPSHOT-test-javadoc.jar AS LOCAL target/modern-java-practices-0-SNAPSHOT-test-javadoc.jar
52-
SAVE ARTIFACT --keep-ts target/testapidocs/ AS LOCAL target/testapidocs/
53-
54-
# Test coverage and badge for Maven:
55-
# See above comments on enabling for Gradle.
56-
# Note that ONLY the Maven containerized build updates the README frontpage
57-
# badge for coverage. This is to avoid multiple updating.
58-
SAVE ARTIFACT --keep-ts target/site/jacoco/jacoco.csv AS LOCAL target/site/jacoco/jacoco.csv
32+
# For CI so that GitHub can copy artifacts:
33+
# Just copy everything rather than maintain a whitelist of files/dirs.
34+
SAVE ARTIFACT --keep-ts target AS LOCAL target
5935

6036
run-with-maven:
6137
FROM +build-with-maven

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ Some highlighted documentation pages:
1515
- [_Shift security
1616
left_](https://github.com/binkley/modern-java-practices/wiki/Shift-security-left)
1717

18-
> [!NOTE]
19-
> The license has changed to
20-
> [Creative Commons 0 Public Domain Dedication
21-
> (CC0)](https://creativecommons.org/public-domain/cc0/) from earlier commits
22-
> with [Public Domain](https://unlicense.org/) licensing.
23-
> This change accomodates countries/juristictions where _Public Domain_ is
24-
> restricted, and _CC0_ seems the most open choice available.<br>
25-
> See [`LICENSE.md`](./LICENSE.md) for legal details.
26-
2718
# Modern Java/JVM Build Practices
2819

2920
<a href="https://modernagile.org/" title="Modern Agile">

build-as-ci-does.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ set -e # Fail on first failed command
99

1010
# Workaround for: https://github.com/earthly/earthly/issues/4220
1111
export EARTHLY_DISABLE_REMOTE_REGISTRY_PROXY=true
12+
# TODO: CI does not implement Earthly caching (for now)
13+
# This **significantly** slows the development cycle.
14+
# Best use _this script_ only before pushing changes, else make coffee or tea.
15+
export EARTHLY_NO_CACHE=true
1216

1317
# Provide nicer console output via formatting and color
1418
# See https://github.com/binkley/shell/blob/master/color/color.sh

0 commit comments

Comments
 (0)