I'm new to Github workflows. I wanted to do a POC/demo showing code coverage and gating. I'm trying to fix two issues:
- Get past the code coverage issue (the previous run worked)
- Make a low coverage un-mergable into the master branch. I don't know how to raise some sort of blocking Github status. I request enlightenment on this.
Details:
If I do
mvn test
I get a build that works and has 100% code coverage (it says anyway).
When I check this into Github, the PR has an error, but no explanation.
Run madrapps/jacoco-report@v1.2
with:
paths: /home/runner/work/java-testing-demo/java-testing-demo/target/site/jacoco/jacoco.xml
token: ***
min-coverage-overall: 40
min-coverage-changed-files: 85
debug-mode: false
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Adopt_jdk/17.0.2-8/x64
Event is push
base sha: 736b95e6068cb7a507790dfc01c6b44d9b663e67
head sha: 0a796a06c68a47511db88838b9d7794df9777535
build.yml:
name: Build
on:
push:
branches:
- "*"
pull_request:
branches:
- master
jobs:
build:
environment: DEV
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
run: |
mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
-Dsonar.projectKey=bpracht_java-testing-demo \
-Dsonar.organization=bpracht \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login="${{secrets.SONAR_TOKEN}}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Code coverage metric
id: jacoco
uses: madrapps/jacoco-report@v1.2
with:
paths: ${{ github.workspace }}/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 85
- name: Get the Coverage information
run: |
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"