From 1c08324e3a5e0cf112b96e5879782b459fa607f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=AA=E5=8D=8E=E8=A3=95?= Date: Thu, 14 Mar 2024 08:05:59 +0800 Subject: [PATCH] Update sonar.yaml --- .github/workflows/sonar.yaml | 50 ++++++++++++++---------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml index a0e5350a..321f35c2 100644 --- a/.github/workflows/sonar.yaml +++ b/.github/workflows/sonar.yaml @@ -67,8 +67,7 @@ jobs: run: | ./x.py build -j$(nproc) --compiler gcc --skip-build - - name: Run sonar-scanner(PUSH) - if: github.event_name != 'pull_request' + - name: Run sonar-scanner env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} @@ -79,35 +78,24 @@ jobs: REF=$(jq -r '.ref | select (.!=null)' sonarcloud-data/github-event.json) echo "The PR number is $PR_NUMBER, ref is $REF, head ref is $HEAD_REF, base ref is $BASE_REF" - - sonar-scanner \ - --define sonar.cfamily.build-wrapper-output="sonarcloud-data" \ - --define sonar.coverageReportPaths=sonarcloud-data/coverage.xml \ - --define sonar.projectKey=jihuayu_kvrocks-test \ - --define sonar.organization=jihuayu \ - --define sonar.scm.revision=${{ github.event.workflow_run.head_sha }} - - - - name: Run sonar-scanner(PR) - if: github.event_name == 'pull_request' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} - run: | - PR_NUMBER=$(jq -r '.number | select (.!=null)' sonarcloud-data/github-event.json) - HEAD_REF=$(jq -r '.pull_request.head.ref | select (.!=null)' sonarcloud-data/github-event.json) - BASE_REF=$(jq -r '.pull_request.base.ref | select (.!=null)' sonarcloud-data/github-event.json) - REF=$(jq -r '.ref | select (.!=null)' sonarcloud-data/github-event.json) - echo "The PR number is $PR_NUMBER, ref is $REF, head ref is $HEAD_REF, base ref is $BASE_REF" git fetch upstream - sonar-scanner \ - --define sonar.cfamily.build-wrapper-output="sonarcloud-data" \ - --define sonar.coverageReportPaths=sonarcloud-data/coverage.xml \ - --define sonar.projectKey=jihuayu_kvrocks-test \ - --define sonar.organization=jihuayu \ - --define sonar.scm.revision=${{ github.event.workflow_run.head_sha }} \ - --define sonar.pullrequest.key=$PR_NUMBER \ - --define sonar.pullrequest.branch=$HEAD_REF \ - --define sonar.pullrequest.base=upstream/unstable + if [ -n "$PR_NUMBER" ]; then + sonar-scanner \ + --define sonar.cfamily.build-wrapper-output="sonarcloud-data" \ + --define sonar.coverageReportPaths=sonarcloud-data/coverage.xml \ + --define sonar.projectKey=jihuayu_kvrocks-test \ + --define sonar.organization=jihuayu \ + --define sonar.scm.revision="${{ github.event.workflow_run.head_sha }}" \ + --define sonar.pullrequest.key="$PR_NUMBER" \ + --define sonar.pullrequest.branch="$HEAD_REF" \ + --define sonar.pullrequest.base=upstream/unstable + else + sonar-scanner \ + --define sonar.cfamily.build-wrapper-output="sonarcloud-data" \ + --define sonar.coverageReportPaths=sonarcloud-data/coverage.xml \ + --define sonar.projectKey=jihuayu_kvrocks-test \ + --define sonar.organization=jihuayu \ + --define sonar.scm.revision="${{ github.event.workflow_run.head_sha }}" + fi