Skip to content

Commit d7fb7dd

Browse files
committed
Add SonarQube analysis
1 parent d88d7ff commit d7fb7dd

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [ "main" ]
66
pull_request:
77
branches: [ "main" ]
8+
types: [opened, synchronize, reopened]
89

910
jobs:
1011
build:
@@ -14,22 +15,41 @@ jobs:
1415
steps:
1516
- name: Checkout Repository
1617
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
1720

1821
- name: Set up JDK 21
1922
uses: actions/setup-java@v4
2023
with:
2124
java-version: '21'
2225
distribution: 'temurin'
23-
24-
- name: Setup Gradle
25-
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
2626

27-
- name: Run PMD Analysis
28-
run: ./gradlew pmdMain pmdTest
29-
continue-on-error: false # Fail if code quality issues are found
27+
- name: Setup & Cache Gradle packages
28+
uses: actions/cache@v4
29+
with:
30+
path: ~/.gradle/caches
31+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
32+
restore-keys: ${{ runner.os }}-gradle
33+
34+
- name: Cache SonarCloud packages
35+
uses: actions/cache@v4
36+
with:
37+
path: ~/.sonar/cache
38+
key: ${{ runner.os }}-sonar
39+
restore-keys: ${{ runner.os }}-sonar
3040

3141
- name: Run Unit Tests
3242
run: ./gradlew test
3343

3444
- name: Build Project
35-
run: ./gradlew build
45+
run: ./gradlew build -x test
46+
47+
- name: Run PMD Analysis
48+
run: ./gradlew pmdMain pmdTest
49+
continue-on-error: false # Fail if code quality issues are found
50+
51+
- name: Run Sonar Analysis
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
55+
run: ./gradlew sonar --info

buildSrc/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ plugins {
55
repositories {
66
gradlePluginPortal()
77
}
8+
9+
dependencies {
10+
implementation(libs.sonarqube.gradle.plugin)
11+
}

buildSrc/src/main/groovy/com.craftsmanshipinsoftware.common-conventions.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'java'
33
id 'pmd'
4+
id "org.sonarqube"
45
}
56

67
repositories {
@@ -28,3 +29,11 @@ pmd {
2829
"category/java/bestpractices.xml",
2930
"category/java/performance.xml"]
3031
}
32+
33+
sonar {
34+
properties {
35+
property "sonar.projectKey", "durimkryeziu_exercises-for-programmers-java"
36+
property "sonar.organization", "durimkryeziu"
37+
property "sonar.host.url", "https://sonarcloud.io"
38+
}
39+
}

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
22
[versions]
33
assertj-core = "3.26.3"
4-
junit-jupiter = "5.11.0"
54
javafxplugin = "0.1.0"
5+
junit-jupiter = "5.11.0"
66
pmd = "7.6.0"
7+
sonarqube = "5.1.0.4882"
78

89
[libraries]
910
assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj-core" }
1011
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
12+
sonarqube-gradle-plugin = { module = "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin", version.ref = "sonarqube" }
1113

1214
[plugins]
1315
javafxplugin = { id = "org.openjfx.javafxplugin", version.ref = "javafxplugin" }

0 commit comments

Comments
 (0)