SonarCloud Code Scanning #37
This file contains hidden or 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: SonarCloud Code Scanning | |
| # Trigger workflow on push to main/master branches and on schedule | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| schedule: | |
| # Run weekly on Monday at 00:00 UTC | |
| - cron: '0 0 * * 1' | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| sonarcloud-scan: | |
| name: SonarCloud Code Analysis | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for better analysis | |
| # Set up Java 11 for building | |
| - name: Set up JDK 11 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '11' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| # Cache SonarCloud packages | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| # Build with Maven and run tests with coverage | |
| - name: Build and analyze with Maven | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: | | |
| mvn clean \ | |
| org.jacoco:jacoco-maven-plugin:0.8.8:prepare-agent \ | |
| verify \ | |
| org.jacoco:jacoco-maven-plugin:0.8.8:report | |
| # Set up Java 17 for SonarCloud analysis (required by SonarQube scanner) | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| # Run SonarCloud analysis | |
| - name: SonarCloud Scan | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: | | |
| mvn sonar:sonar \ | |
| -Dsonar.projectKey=Sunbird-Knowlg_knowledge-platform-jobs \ | |
| -Dsonar.organization=sunbird-knowlg-1 \ | |
| -Dsonar.host.url=https://sonarcloud.io \ | |
| -Dsonar.coverage.jacoco.xmlReportPaths=**/target/site/jacoco/jacoco.xml |