diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 56c5f16..28c4dd1 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -21,8 +21,19 @@ jobs: run: yarn install --frozen-lockfile - name: Test and coverage run: yarn jest --coverage + - name: Sonar Args + id: sonar-args + run: | + if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then + echo "SONAR_ARGS=-Dsonar.branch.name=main" >> $GITHUB_OUTPUT + else + echo "SONAR_ARGS=-Dsonar.branch.target=main -Dsonar.branch.name=${{ github.head_ref }}" >> $GITHUB_OUTPUT + fi + - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master + uses: sonarsource/sonarcloud-github-action@master env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: ${{ steps.sonar-args.outputs.SONAR_ARGS }}