Skip to content

Commit

Permalink
Update sonar.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
jihuayu authored Apr 25, 2024
1 parent 964bfdc commit 70b37c5
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions .github/workflows/sonar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ jobs:
sonarcloud:
name: Upload to SonarCloud
runs-on: ubuntu-22.04
if: github.event.workflow_run.conclusion == 'success'
if: github.event.workflow_run.conclusion == 'success' && github.repository_owner == 'apache'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v2
- name: 'Download code coverage'
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
Expand All @@ -59,43 +59,40 @@ jobs:
run: |
unzip sonarcloud-data.zip -d sonarcloud-data
ls -a sonarcloud-data
- uses: actions/setup-python@v4
- name: Check upload
id : check
# We only run the sonar-scanner during a commit event on the unstable branch.
run: |
ref=$(jq -r '.ref' github-event.json)
if [[ -n "$ref" ]] && [[ "$ref" != "refs/heads/unstable" ]]; then
echo "run_flag=false" >> $GITHUB_OUTPUT
else
echo "run_flag=true" >> $GITHUB_OUTPUT
fi
- uses: actions/setup-python@v5
if: ${{steps.check.outputs.run_flag == 'true'}}
with:
python-version: 3.x
- name: Configure Kvrocks
if: ${{steps.check.outputs.run_flag == 'true'}}
run: |
./x.py build -j$(nproc) --compiler gcc --skip-build
- name: Run sonar-scanner
if: ${{steps.check.outputs.run_flag == 'true'}}
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"
if [ -n "$PR_NUMBER" ]; then
git remote add upstream https://github.com/jihuayu/kvrocks-test.git
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
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
echo "The PR number is $PR_NUMBER"
sonar-scanner \
--define sonar.cfamily.build-wrapper-output="sonarcloud-data" \
--define sonar.coverageReportPaths=sonarcloud-data/coverage.xml \
--define sonar.projectKey=apache_kvrocks \
--define sonar.organization=apache \
--define sonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
--define sonar.pullrequest.key=$PR_NUMBER

0 comments on commit 70b37c5

Please sign in to comment.