sonarcloud.yml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. name: SonarCloud Scan (triggered by maven.yml)
  2. on:
  3. workflow_run:
  4. workflows:
  5. - Build
  6. types:
  7. - completed
  8. # Allows you to run this workflow manually from the Actions tab
  9. workflow_dispatch:
  10. jobs:
  11. sonar:
  12. name: SonarCloud Scan
  13. runs-on: ubuntu-latest
  14. if: ${{ github.actor != 'dependabot[bot]' && github.event.workflow_run.conclusion == 'success' }}
  15. steps:
  16. - uses: actions/checkout@v3
  17. with:
  18. repository: ${{ github.event.workflow_run.head_repository.full_name }}
  19. ref: ${{ github.event.workflow_run.head_branch }}
  20. fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
  21. - name: Set up JDK
  22. uses: actions/setup-java@v3
  23. with:
  24. distribution: 'temurin'
  25. java-version: 17
  26. - name: Cache SonarCloud packages
  27. uses: actions/cache@v3
  28. with:
  29. path: ~/.sonar/cache
  30. key: ${{ runner.os }}-sonar
  31. restore-keys: ${{ runner.os }}-sonar
  32. - name: Cache Maven packages
  33. uses: actions/cache@v3
  34. with:
  35. path: ~/.m2
  36. key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
  37. restore-keys: ${{ runner.os }}-m2
  38. - name: Build and analyze
  39. env:
  40. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  41. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  42. run: mvn -Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} -Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0] != null && github.event.workflow_run.pull_requests[0].number }} -Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0] != null && github.event.workflow_run.pull_requests[0].head.ref }} -Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0] != null && github.event.workflow_run.pull_requests[0].base.ref }} -U -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar