SonarCloud Scan #8
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 Scan | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "server/**" | |
| - "frontend/**" | |
| - "screenshot/**" | |
| workflow_dispatch: # add ability to run workflow. | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| sonarCheck: | |
| name: SonarQube config check | |
| runs-on: ubuntu-latest | |
| outputs: | |
| enabled: ${{ steps.check.outputs.enabled }} | |
| steps: | |
| - id: check | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| SONAR_HOST_URL: ${{ secrets.SONAR_HOST }} | |
| run: | | |
| if [ -n "$SONAR_TOKEN" ] && [ -n "$SONAR_HOST_URL" ]; then | |
| echo "enabled=true" >> "$GITHUB_OUTPUT" | |
| echo "SonarQube secrets detected; scans will run." | |
| else | |
| echo "enabled=false" >> "$GITHUB_OUTPUT" | |
| echo "SonarQube secrets not configured; skipping scans." | |
| fi | |
| sonarQubeServer: | |
| name: SonarQube Server | |
| runs-on: ubuntu-latest | |
| needs: sonarCheck | |
| if: ${{ needs.sonarCheck.outputs.enabled == 'true' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 21 | |
| distribution: "temurin" | |
| - name: Cache SonarQube packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.gradle/caches | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
| restore-keys: ${{ runner.os }}-gradle | |
| - name: Scan server | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # analysis token associated to your project | |
| SONAR_HOST_URL: ${{ secrets.SONAR_HOST }} | |
| run: | | |
| cd server/ | |
| ./gradlew build sonar | |
| sonarQubeFrontend: | |
| name: sonarQube Frontend | |
| runs-on: ubuntu-latest | |
| needs: sonarCheck | |
| if: ${{ needs.sonarCheck.outputs.enabled == 'true' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| run_install: true | |
| - name: Run coverage | |
| run: | | |
| cd frontend | |
| pnpm run coverage | |
| - name: Scan Frontend | |
| uses: SonarSource/sonarqube-scan-action@v6.0.0 | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| SONAR_HOST_URL: ${{ secrets.SONAR_HOST }} | |
| SONAR_PROJECT_NAME: antonrasmussen_findfirst_frontend | |
| with: | |
| projectBaseDir: frontend/ | |
| sonarQubeScreenshot: | |
| name: SonarQube Screenshot | |
| runs-on: ubuntu-latest | |
| needs: sonarCheck | |
| if: ${{ needs.sonarCheck.outputs.enabled == 'true' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 21 | |
| distribution: "temurin" | |
| - name: Cache SonarQube packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.gradle/caches | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
| restore-keys: ${{ runner.os }}-gradle | |
| - name: Scan screenshot | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # analysis token associated to your project | |
| SONAR_HOST_URL: ${{ secrets.SONAR_HOST }} | |
| run: | | |
| cd screenshot/ | |
| ./gradlew build sonar |