Skip to content

Legger til testdekning på wf #64

Legger til testdekning på wf

Legger til testdekning på wf #64

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: Generate JaCoCo report
run: mvn jacoco:prepare-agent test jacoco:report --no-transfer-progress --settings .m2/maven-settings.xml --file pom.xml
- name: Upload JaCoCo report
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: target/site/jacoco
sonar:
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
cache: 'maven'
- name: Download JaCoCo report
uses: actions/download-artifact@v3
with:
name: jacoco-report
path: target/site/jacoco
- name: Cache Sonar packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Run Sonar
env:
GITHUB_USERNAME: x-access-token
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_PROJECTKEY: ${{ secrets.SONAR_PROJECTKEY }}
SONAR_LOGIN: ${{ secrets.SONAR_LOGIN }}
run: mvn sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml --settings .m2/maven-settings.xml --file pom.xml