Merge pull request #225 from bcgov/feature/AB#33397-Applicant-Portal-… #167
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 Analysis | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| - test | |
| - main | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| workflow_dispatch: | |
| permissions: | |
| checks: write | |
| contents: read | |
| pull-requests: write | |
| security-events: write | |
| jobs: | |
| sonarcloud: | |
| name: SonarCloud | |
| runs-on: ubuntu-latest | |
| environment: ${{ github.ref_name == 'main' && 'main' || github.ref_name == 'test' && 'test' || 'dev' }} | |
| steps: | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: 17 | |
| distribution: 'temurin' | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '9.0.x' | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '22' | |
| cache: 'npm' | |
| cache-dependency-path: applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Frontend/package-lock.json | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Cache SonarCloud scanner | |
| id: cache-sonar-scanner | |
| uses: actions/cache@v5 | |
| with: | |
| path: ./.sonar/scanner | |
| key: ${{ runner.os }}-sonar-scanner | |
| restore-keys: ${{ runner.os }}-sonar-scanner | |
| - name: Install SonarCloud scanner | |
| if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' | |
| run: | | |
| dotnet tool install --global dotnet-sonarscanner | |
| - name: Set version for SonarCloud | |
| run: | | |
| VERSION="${{ vars.GRANTS_BUILD_VERSION }}" | |
| echo "Debug: GRANTS_BUILD_VERSION variable value: '$VERSION'" | |
| if [ -n "$VERSION" ]; then | |
| echo "BUILD_VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "Using project version: $VERSION" | |
| # Replace ${BUILD_VERSION} with actual value | |
| sed -i "s/\${BUILD_VERSION}/$VERSION/g" applications/Grants.ApplicantPortal/sonar-project.properties | |
| else | |
| echo "GRANTS_BUILD_VERSION variable not set - removing sonar.projectVersion property" | |
| # Remove the projectVersion line entirely if no version is available | |
| sed -i "/sonar.projectVersion=/d" applications/Grants.ApplicantPortal/sonar-project.properties | |
| fi | |
| - name: Clear npm cache | |
| run: npm cache clean --force | |
| - name: Install Node.js dependencies | |
| working-directory: ./applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Frontend | |
| run: npm ci --no-audit --prefer-offline | |
| - name: Build Angular frontend | |
| working-directory: ./applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Frontend | |
| run: npm run build:dev | |
| - name: Restore .NET dependencies | |
| working-directory: ./applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Backend | |
| run: dotnet restore Grants.ApplicantPortal.API.sln | |
| - name: Build .NET solution | |
| working-directory: ./applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Backend | |
| run: dotnet build Grants.ApplicantPortal.API.sln --no-restore | |
| - name: SonarCloud sonar.projectVersion | |
| run: | | |
| echo "BUILD_VERSION environment variable: $BUILD_VERSION" | |
| echo "Updated sonar-project.properties:" | |
| cat applications/Grants.ApplicantPortal/sonar-project.properties | grep "sonar.projectVersion" || echo "No projectVersion set" | |
| - name: SonarCloud Scan | |
| uses: SonarSource/sonarqube-scan-action@v7 | |
| with: | |
| projectBaseDir: applications/Grants.ApplicantPortal | |
| args: > | |
| -Dsonar.verbose=true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |