11# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
22
3- name : Java CI with Maven, Run Tests, Coverage Report and Badge
3+ name : Build
44
55on :
66 push :
1515
1616 steps :
1717 - uses : actions/checkout@v4
18-
19- - name : Setup Java Development Kits
20- uses : actions/setup-java@v4
21- with :
22- java-version : 17
23- distribution : microsoft
24- cache : maven
25-
18+
2619 - name : Build with Maven
2720 run : mvn -B package --file pom.xml
28-
29- - name : Generate JavaCodeCoverage badge
30- id : jacoco
31- uses : cicirello/jacoco-badge-generator@v2
32- with :
33- badges-directory : .github/badges
34- generate-branches-badge : true
35- generate-summary : true
36-
37- - name : Log coverage percentages to workflow output
38- run : |
39- echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
40- echo "branches = ${{ steps.jacoco.outputs.branches }}"
41-
42- - name : Upload JaCoCo coverage report as a workflow artifact
43- uses : actions/upload-artifact@v4
44- with :
45- name : jacoco-report
46- path : target/site/jacoco/
47-
48- - name : Commit and push the coverage badges and summary file
49- if : ${{ github.event_name != 'pull_request' }}
50- run : |
51- cd .github/badges
52- if [[ `git status --porcelain *.svg *.json` ]]; then
53- git config --global user.name 'github-actions'
54- git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
55- git add *.svg *.json
56- git commit -m "Autogenerated JaCoCo coverage badges" *.svg *.json
57- git push
58- fi
59-
60- # - name: Comment on PR with coverage percentages
61- # if: ${{ github.event_name == 'pull_request' }}
62- # run: |
63- # REPORT=$(<.github/badges/coverage-summary.json)
64- # COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
65- # BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
66- # NEWLINE=$'\n'
67- # BODY="## JaCoCo Test Coverage Summary Statistics${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}"
68- # gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
69- # env:
70- # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
0 commit comments