Legger til testdekning på wf #63
Workflow file for this run
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
name: Java CI | |
on: | |
workflow_dispatch: | |
pull_request: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
fetch-depth: 0 # brukes for å unngå feil i differ i sonar | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
cache: 'maven' | |
- name: Bygg (dependabot) | |
if: github.actor == 'dependabot[bot]' | |
env: | |
GITHUB_USERNAME: x-access-token | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: mvn --no-transfer-progress verify --settings .m2/maven-settings.xml --file pom.xml | |
- name: Cache Maven dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Opprett JaCoCo report | |
run: | | |
mvn -B package --file pom.xml | |
- name: Last opp testdekning rapport | |
uses: actions/upload-artifact@v3 | |
with: | |
name: jacoco-report | |
path: target/site/jacoco/jacoco.xml | |
- name: Add coverage to PR | |
id: jacoco | |
uses: madrapps/[email protected] | |
with: | |
paths: target/site/jacoco/jacoco.xml | |
token: ${{ secrets.GITHUB_TOKEN }} | |
min-coverage-overall: 80 | |
min-coverage-changed-files: 80 | |
title: Code Coverage | |
- name: Save Coverage To Environment Variable | |
run: | | |
echo "TOTAL_COVERAGE=${{ steps.jacoco.outputs.coverage-overall }}" >> $GITHUB_ENV | |
echo "CHANGED_FILES_COVERAGE=${{ steps.jacoco.outputs.coverage-changed-files }}" >> $GITHUB_ENV | |
- name: Print & Check Coverage Info | |
run: | | |
import os | |
import sys | |
print("Total Coverage: " + str(os.environ["TOTAL_COVERAGE"])) | |
print("Changed Files Coverage: " + str(os.environ["CHANGED_FILES_COVERAGE"])) | |
if float(os.environ["TOTAL_COVERAGE"]) < 80 or float(os.environ["CHANGED_FILES_COVERAGE"]) < 80: | |
print("Insufficient Coverage!") | |
sys.exit(-1) # Cause Status Check Failure due to noncompliant coverage | |
sys.exit(0) | |
shell: python | |
- name: Bygg og SonarCloud | |
if: github.actor != 'dependabot[bot]' | |
env: | |
GITHUB_USERNAME: x-access-token | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_PROJECTKEY: ${{ secrets.SONAR_PROJECTKEY }} | |
SONAR_LOGIN: ${{ secrets.SONAR_LOGIN }} | |
run: mvn --no-transfer-progress verify --settings .m2/maven-settings.xml --file pom.xml | |
#run: mvn --no-transfer-progress verify sonar:sonar --settings .m2/maven-settings.xml --file pom.xml |