Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Update coverage badge #10

Update coverage badge

Update coverage badge #10

Workflow file for this run

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout github pages
uses: actions/checkout@v3
with:
ref: gh-pages
path: pages
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Generate JaCoCo badge
uses: cicirello/jacoco-badge-generator@v2
with:
badges-directory: pages/badges
generate-branches-badge: true
generate-summary: true
- name: Upload JaCoCo coverage report as a workflow artifact
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: target/site/jacoco/
- name: Commit and push the coverage badges and summary file
if: ${{ github.event_name != 'pull_request' }}
run: |
cd pages
if [[ `git status --porcelain *.svg *.json` ]]; then
git config --global user.name 'github-actions'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add *.svg *.json
git commit -m "Autogenerated JaCoCo coverage badges" *.svg *.json
git push
fi
- name: Comment on PR with coverage percentages
if: ${{ github.event_name == 'pull_request' }}
run: |
REPORT=$(<pages/badges/coverage-summary.json)
COVERAGE=$(jq -r '.coverage' <<< "$REPORT")
BRANCHES=$(jq -r '.branches' <<< "$REPORT")
NEWLINE=$'\n'
BODY="## JaCoCo Test Coverage Summary Statistics${NEWLINE}* __Coverage:__ ${COVERAGE:0:5}%${NEWLINE}* __Branches:__ ${BRANCHES:0:5}%"
gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}