refacto/ci/update-workflow #5
Workflow file for this run
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: SonarQube | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| permissions: | |
| pull-requests: read # allows SonarCloud to decorate PRs with analysis results | |
| jobs: | |
| backend-sonar-scan: | |
| name: Build and analyze Backend with SonarQube | |
| runs-on: ubuntu-latest | |
| strategy: | |
| # If you add more microservices in the future, just edit the matrix.service array to include new subfolders | |
| matrix: | |
| service: | |
| - . # Refers to the parent Spring Boot service | |
| - discovery-service # For hospital-service under /backend | |
| - hospital-service # For emergency-service under /backend | |
| - emergency-service # Add other microservices here | |
| steps: | |
| # Step 1: Checkout the repository | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
| # Step 2: Set up JDK 21 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 21 | |
| distribution: 'zulu' # Alternative distribution options are available. | |
| # Step 3: Cache SonarQube packages (optional performance boost) | |
| - name: Cache SonarQube packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| # Step 4: Cache Maven dependencies to save CI time | |
| - name: Cache Maven packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-m2 | |
| # Step 5: Build and analyze each service | |
| - name: Build and analyze ${{ matrix.service }} | |
| run: mvn -f backend/${{ matrix.service }}/pom.xml \ | |
| -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ | |
| -D sonar.projectKey=swyth-dev_${{ matrix.service }} \ | |
| -D sonar.pullrequest.key=${{ github.event.number }} \ | |
| -D sonar.pullrequest.branch=${{ github.head_ref }} \ | |
| -D sonar.pullrequest.base=${{ github.base_ref }} \ | |
| -D sonar.pullrequest.github.repository=${{ github.repository }} | |
| # Frontend Angular App Scan | |
| frontend-sonar-scan: | |
| name: Frontend Build and Analyze with SonarQube | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 # Use a Node.js version compatible with Angular | |
| - name: Install Dependencies | |
| run: | | |
| cd frontend/realtime-emergency-app/ | |
| npm ci | |
| - name: Run Tests with Coverage | |
| run: | | |
| frontend/realtime-emergency-app/ | |
| npm run test -- --code-coverage | |
| - name: Install SonarScanner | |
| run: npm install -g sonar-scanner | |
| - name: Analyze with SonarQube | |
| run: | | |
| cd frontend/realtime-emergency-app/ && \ | |
| sonar-scanner \ | |
| -D sonar.projectKey=swyth-dev_frontend \ | |
| -D sonar.organization=swyth-dev \ | |
| -D sonar.sources=src \ | |
| -D sonar.exclusions=**/node_modules/**,**/*.spec.ts,**/dist/** \ | |
| -D sonar.tests=src \ | |
| -D sonar.test.inclusions=**/*.spec.ts \ | |
| -D sonar.typescript.lcov.reportPaths=coverage/lcov.info \ | |
| -D sonar.sourceEncoding=UTF-8 \ | |
| -D sonar.pullrequest.key=${{ github.event.number }} \ | |
| -D sonar.pullrequest.branch=${{ github.head_ref }} \ | |
| -D sonar.pullrequest.base=${{ github.base_ref }} \ | |
| -D sonar.pullrequest.github.repository=${{ github.repository }} |