chore: fixed critical sonar issues #9
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: Build and test | |
on: | |
# Capture this event so that gradle caches are updated when a PR is merged to develop | |
# More information on why: https://github.com/gradle/gradle-build-action#using-the-caches-read-only | |
push: | |
branches: | |
- develop | |
paths: | |
- 'src/**' | |
- '.github/**' | |
pull_request: | |
types: [opened, synchronize, reopened] | |
paths: | |
- 'src/**' | |
- '.github/**' | |
permissions: | |
contents: write # Required for https://github.com/gradle/actions/tree/main/setup-gradle#github-dependency-graph-support | |
pull-requests: write # https://github.com/gradle/actions/tree/main/setup-gradle#adding-job-summary-as-a-pull-request-comment | |
actions: read # Required for https://github.com/dorny/test-reporter | |
checks: write # Required for https://github.com/dorny/test-reporter | |
# Cancels previous workflow run on PR if a new one is started (does not affect push to develop). | |
# This is because github.head_ref is empty on push events so defaults to the unique github.run_id. | |
# More info: https://docs.github.com/en/actions/using-jobs/using-concurrency | |
concurrency: | |
group: ${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
BuildAndPackageWithUnitTests: | |
name: Build, test and package code | |
runs-on: ubuntu-24.04 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # SonarCloud: Shallow clones should be disabled for a better relevancy of analysis | |
# Setting up both JDK 11 and 17 | |
# 11 is used for compiling and running tests | |
# 17 is required by sonar | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Cache SonarCloud packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: Set up Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
with: | |
cache-read-only: ${{ github.ref != 'refs/heads/develop' }} | |
gradle-home-cache-cleanup: true | |
dependency-graph: generate-and-submit | |
add-job-summary-as-pr-comment: always | |
- name: Build and test source | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
working-directory: ./src | |
run: ./gradlew build jacocoTestReport sonar -Dsonar.projectKey=nordic-institute_xrd4j -Dsonar.organization=nordic-institute -Dsonar.host.url=https://sonarcloud.io | |
- name: Test report | |
uses: dorny/test-reporter@v1 | |
if: success() || failure() | |
with: | |
name: Unit and integration tests | |
path: src/**/build/test-results/**/TEST-*.xml | |
reporter: java-junit | |
list-suites: 'failed' | |
list-tests: 'failed' |