on:
  push:
    branches:
      - master
  pull_request:
      types: [opened, synchronize, reopened]

name: SonarQube Scan
jobs:
  sonarqube:
    name: SonarQube Trigger
    runs-on: ubuntu-latest
    steps:
    - name: Checking out
      uses: actions/checkout@v4
      with:
        # Disabling shallow clone is recommended for improving relevancy of reporting
        fetch-depth: 0
    - name: Install maven
      run: |
        apt update
        apt install -y maven
    - name: Install java
      uses: actions/setup-java@v4
      with:
        distribution: 'temurin'
        java-version: '25'
        cache: 'maven'
    - name: Compile project
      run: |
        mvn clean dependency:copy-dependencies verify
    - name: SonarQube Scan
      uses: SonarSource/sonarqube-scan-action@v5.3.0
      env:
        SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
        SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
      with:
        args: >
          -Dsonar.projectKey=Java-TX
          -Dsonar.sources=src/main/java
          -Dsonar.tests=src/test/java
          -Dsonar.junit.reportPaths=target/test-reports
          -Dsonar.java.binaries=target/classes
          -Dsonar.java.libraries=target/dependency/*.jar
          -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml