Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SonarCloud Github Action #2835

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,19 @@ jobs:
path: |
rskj-core/build/reports/

- name: Run SonarQube analysis
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v3.1.0 # Ex: v3.1.0, See the latest version at https://github.com/marketplace/actions/sonarcloud-scan
env:
GH_EVENT: ${{ github.event_name }}
GH_PR_NUMBER: ${{ github.event.pull_request.number }}
GH_PR_BASE_REF: ${{ github.base_ref }}
GH_PR_HEAD_REF: ${{ github.head_ref }}
GH_REF: ${{ github.ref }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
run: |
if [ "$GH_EVENT" = "pull_request" ]; then
if [ "$IS_FORK" != "true" ]; then
./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonarqube --no-daemon -x build -x test \
-Dsonar.pullrequest.base="$GH_PR_BASE_REF" \
-Dsonar.pullrequest.branch="$GH_PR_HEAD_REF" \
-Dsonar.pullrequest.key="$GH_PR_NUMBER" \
-Dsonar.organization=rsksmart \
-Dsonar.projectKey=rskj \
-Dsonar.host.url="https://sonarcloud.io" \
-Dsonar.junit.reportPaths=rskj-core/build/test-results/ \
-Dsonar.coverage.jacoco.xmlReportPaths=rskj-core/build/reports/jacoco/test/jacocoTestReport.xml \
-Dsonar.token="$SONAR_TOKEN"
else
echo "Skipping SonarQube analysis for pull request from a forked repo."
fi
else
./gradlew -Dorg.gradle.jvmargs=-Xmx5g sonarqube --no-daemon -x build -x test \
-Dsonar.branch.name="$GH_REF" \
-Dsonar.organization=rsksmart \
-Dsonar.projectKey=rskj \
-Dsonar.host.url="https://sonarcloud.io" \
-Dsonar.junit.reportPaths=rskj-core/build/test-results/ \
-Dsonar.coverage.jacoco.xmlReportPaths=rskj-core/build/reports/jacoco/test/jacocoTestReport.xml \
-Dsonar.token="$SONAR_TOKEN"
fi

with:
args: >
-Dsonar.branch.name="$GH_REF"
-Dsonar.verbose=true

mining-tests:
needs: build
Expand Down Expand Up @@ -322,4 +299,4 @@ jobs:

- name: Run tests
run: |
./gradlew --no-daemon --stacktrace integrationTest
./gradlew --no-daemon --stacktrace integrationTest
10 changes: 10 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sonar.organization=rsksmart
sonar.projectKey=rskj
sonar.host.url=https://sonarcloud.io
sonar.junit.reportPaths=./rskj-core/build/test-results/
sonar.coverage.jacoco.xmlReportPaths=./rskj-core/build/reports/jacoco/test/jacocoTestReport.xml

# relative paths to source directories. More details and properties are described
# in https://sonarcloud.io/documentation/project-administration/narrowing-the-focus/
sonar.sources=.
sonar.java.binaries=./rskj-core/build/classes