|
| 1 | +name: SonarCloud |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + pull_request: |
| 9 | + types: [opened, synchronize, reopened] |
| 10 | + |
| 11 | +jobs: |
| 12 | + sonarcloud: |
| 13 | + name: SonarCloud Scan |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Compile Java (for Sonar) |
| 22 | + run: | |
| 23 | + set -e |
| 24 | + mkdir -p .sonar_classes |
| 25 | + find . -name "*.java" \ |
| 26 | + -not -path "./out/*" \ |
| 27 | + -not -path "./.idea/*" \ |
| 28 | + -not -path "./.git/*" \ |
| 29 | + -not -path "./skills/*" > .sonar_java_files.txt |
| 30 | +
|
| 31 | + if [ -s .sonar_java_files.txt ]; then |
| 32 | + javac -d .sonar_classes @.sonar_java_files.txt |
| 33 | + else |
| 34 | + echo "No Java files found to compile." |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Validate SonarCloud settings |
| 38 | + run: | |
| 39 | + if [ -z "${{ vars.SONAR_ORGANIZATION }}" ] || [ -z "${{ vars.SONAR_PROJECT_KEY }}" ]; then |
| 40 | + echo "Missing SONAR_ORGANIZATION or SONAR_PROJECT_KEY repo variables." |
| 41 | + echo "Set them in GitHub: Settings > Secrets and variables > Actions > Variables." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: SonarQube Cloud Scan |
| 46 | + uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 |
| 47 | + env: |
| 48 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 50 | + with: |
| 51 | + args: > |
| 52 | + -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} |
| 53 | + -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} |
| 54 | + -Dsonar.sources=. |
| 55 | + -Dsonar.exclusions=**/out/**,**/.idea/**,**/.git/**,**/skills/** |
| 56 | + -Dsonar.java.binaries=.sonar_classes |
0 commit comments