diff --git a/.github/workflows/sonar_maven.yaml b/.github/workflows/sonar_maven.yaml new file mode 100644 index 0000000..3c3aa6a --- /dev/null +++ b/.github/workflows/sonar_maven.yaml @@ -0,0 +1,53 @@ +name: Sonar for Maven + +on: + workflow_call: + +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Check for pom.xml + id: check_pom + run: | + if git ls-files "pom.xml" "**/pom.xml" | grep -q "."; then + echo "pom.xml found" + echo "found=true" >> "$GITHUB_OUTPUT" + else + echo "No pom.xml found" + echo "found=false" >> "$GITHUB_OUTPUT" + fi + + - name: Set up JDK 17 + if: steps.check_pom.outputs.found == 'true' + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'zulu' # Alternative distribution options are available. + + - name: Cache SonarQube packages + if: steps.check_pom.outputs.found == 'true' + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Cache Maven packages + if: steps.check_pom.outputs.found == 'true' + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + + - name: Build and analyze + if: steps.check_pom.outputs.found == 'true' + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.organization=woped -Dsonar.projectKey=woped_${{ github.event.repository.name }} -Dsonar.host.url=https://sonarcloud.io \ No newline at end of file diff --git a/.github/workflows/template_CI.yaml b/.github/workflows/template_CI.yaml index d64f768..3b1f09a 100644 --- a/.github/workflows/template_CI.yaml +++ b/.github/workflows/template_CI.yaml @@ -10,7 +10,12 @@ jobs: linting: uses: woped/devops/.github/workflows/linting.yaml@main testing_maven: - uses: woped/devops/.github/workflows/testing_maven.yaml@main + uses: woped/devops/.github/workflows/testing_maven.yaml@feature/main + sonar_maven: + needs: testing_maven + uses: woped/devops/.github/workflows/sonar_maven.yaml@feature/main + secrets: inherit + testing_pytest: uses: woped/devops/.github/workflows/testing_pytest.yaml@main sonar_python: