Merge pull request #104 from tommens/dependabot/maven/org.jacoco-jaco… #245
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow builds a Java project with Maven | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | |
name: Java CI with Maven | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
build: | |
name: build and analyse | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up with Java 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
cache: 'maven' | |
- name: Build with Maven (including running of all tests) | |
run: mvn -B package --file pom.xml | |
- name: Publish Test Report | |
if: ${{ always() }} | |
uses: scacap/action-surefire-report@v1 | |
- name: Generate JaCoCo Badge | |
id: jacoco | |
uses: cicirello/jacoco-badge-generator@v2 | |
with: | |
generate-coverage-badge: true | |
generate-branches-badge: true | |
generate-summary: true | |
- name: Log coverage percentage | |
run: | | |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}" | |
echo "branch coverage = ${{ steps.jacoco.outputs.branches }}" | |
- name: Commit and push the svg badges and the json coverage summary (if it changed) | |
uses: EndBug/add-and-commit@v9 | |
with: | |
default_author: github_actions | |
message: 'commit coverage badge and summary' | |
add: '*.svg *.json' | |
- name: Upload JaCoCo coverage report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: jacoco-report | |
path: target/site/jacoco/ | |
- name: Comment on PR with coverage percentages | |
if: ${{ github.event_name == 'pull_request' }} | |
run: | | |
REPORT=$(<.github/badges/coverage-summary.json) | |
COVERAGE=$(jq -r '.coverage' <<< "$REPORT")% | |
BRANCHES=$(jq -r '.branches' <<< "$REPORT")% | |
NEWLINE=$'\n' | |
BODY="## Test Coverage Summary ${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}" | |
gh pr comment ${{github.event.pull_request.number}} -b "${BODY}" | |
continue-on-error: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# - name: Build and analyze with Sonar Cloud | |
# run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=tommens_calculator-cucumber | |
# env: | |
# # Needed to get some information about the pull request, if any | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# # SonarCloud access token should be generated from https://sonarcloud.io/account/security/ | |
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |