Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle coverage report in GitHub #608

Merged
merged 10 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci-earthly-gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,42 @@ jobs:
- name: Execute run script
run: earthly --secret OWASP_NVD_API_KEY +run-with-gradle

# Save artifacts for build
# See Earthfile that copies these from container to local

# Javadoc HTML and jars

- name: Save Javadoc HTML for main
uses: actions/upload-artifact@v4
with:
name: javadoc-html
if-no-files-found: error
path: build/docs/javadoc/

- name: Save Javadoc HTML Jar for main
uses: actions/upload-artifact@v4
with:
name: javadoc-jar
if-no-files-found: error
path: build/libs/modern-java-practices-0-SNAPSHOT-javadoc.jar

# Generate coverage report

- name: Save coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
if-no-files-found: error
path: build/reports/jacoco/test/

- name: Generate coverage badge
uses: cicirello/jacoco-badge-generator@v2
with:
badges-directory: images
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
# To avoid conflicts with the Maven build, only generate the badge
# there. For Gradle only projects: REMOVE THIS LINE.
generate-coverage-badge: false
generate-branches-badge: false
generate-summary: false

6 changes: 3 additions & 3 deletions .github/workflows/ci-earthly-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Execute run script
run: earthly --secret OWASP_NVD_API_KEY +run-with-maven

# Save artifacts for build
# Save artifacts for build
# See Earthfile that copies these from container to local

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

# Coverage badge report
# Coverage coverage report

- name: Save coverage report
uses: actions/upload-artifact@v4
Expand All @@ -112,7 +112,7 @@ jobs:
if-no-files-found: error
path: target/site/jacoco/

# Generage coverage badge for README
# Generate coverage badge for README
# Gradle builds are similar but will require configuration the path for the
# CSV JaCoCo report.

Expand Down
38 changes: 7 additions & 31 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,15 @@ build-with-gradle:
COPY src src
RUN --secret OWASP_NVD_API_KEY ./gradlew clean build

# For CI so that GitHub can copy artifacts:
# Just copy everything rather than maintain a whitelist of files/dirs.
SAVE ARTIFACT --keep-ts build AS LOCAL build

run-with-gradle:
FROM +build-with-gradle
COPY run-with-gradle.sh .
RUN ./run-with-gradle.sh

# For CI so that GitHub can copy artifacts
# Coverage reports
SAVE ARTIFACT --keep-ts build/reports/jacoco/test/ AS LOCAL build/reports/jacoco/test/
# Javadocs and jars
SAVE ARTIFACT --keep-ts build/libs/modern-java-practices-0-javadoc.jar
SAVE ARTIFACT --keep-ts build/docs/javadoc/ AS LOCAL build/docs/javadoc/

# Test coverage and badge for Gradle:
# You need to PICK ONE from Gradle or Maven for your build.
# This project uses Maven (see below) to create the code coverage badge to
# avoid multiple updating.
# Commented is the minimum needed from the containerized build when using
# Gradle.
# After this enabling this, you still need to update the GitHub action steps
# to generate the badge using a custom path to the CVS report.
# SAVE ARTIFACT --save-ts build/reports/jacoco/test/jacocoTestReport.csv AS LOCAL build/reports/jacoco/test/jacocoTestReport.csv

build-with-maven:
COPY mvnw .
COPY .mvn .mvn
Expand All @@ -42,20 +29,9 @@ build-with-maven:
COPY src src
RUN --secret OWASP_NVD_API_KEY ./mvnw --no-transfer-progress clean verify

# For CI so that GitHub can copy artifacts
# Coverage reports
SAVE ARTIFACT --keep-ts target/site/jacoco/
# Javadocs and jars
SAVE ARTIFACT --keep-ts target/modern-java-practices-0-SNAPSHOT-javadoc.jar AS LOCAL target/modern-java-practices-0-SNAPSHOT-javadoc.jar
SAVE ARTIFACT --keep-ts target/apidocs/ AS LOCAL target/apidocs/
SAVE ARTIFACT --keep-ts target/modern-java-practices-0-SNAPSHOT-test-javadoc.jar AS LOCAL target/modern-java-practices-0-SNAPSHOT-test-javadoc.jar
SAVE ARTIFACT --keep-ts target/testapidocs/ AS LOCAL target/testapidocs/

# Test coverage and badge for Maven:
# See above comments on enabling for Gradle.
# Note that ONLY the Maven containerized build updates the README frontpage
# badge for coverage. This is to avoid multiple updating.
SAVE ARTIFACT --keep-ts target/site/jacoco/jacoco.csv AS LOCAL target/site/jacoco/jacoco.csv
# For CI so that GitHub can copy artifacts:
# Just copy everything rather than maintain a whitelist of files/dirs.
SAVE ARTIFACT --keep-ts target AS LOCAL target

run-with-maven:
FROM +build-with-maven
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ Some highlighted documentation pages:
- [_Shift security
left_](https://github.com/binkley/modern-java-practices/wiki/Shift-security-left)

> [!NOTE]
> The license has changed to
> [Creative Commons 0 Public Domain Dedication
> (CC0)](https://creativecommons.org/public-domain/cc0/) from earlier commits
> with [Public Domain](https://unlicense.org/) licensing.
> This change accomodates countries/juristictions where _Public Domain_ is
> restricted, and _CC0_ seems the most open choice available.<br>
> See [`LICENSE.md`](./LICENSE.md) for legal details.

# Modern Java/JVM Build Practices

<a href="https://modernagile.org/" title="Modern Agile">
Expand Down
4 changes: 4 additions & 0 deletions build-as-ci-does.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ set -e # Fail on first failed command

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

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