Skip to content

Commit 29e5694

Browse files
authored
DOPS-3309: Add sonar & defectdojo analysis (#440)
* Add sonar & defectdojo analysis Signed-off-by: BAStos525 <[email protected]> * fix sonar key Signed-off-by: BAStos525 <[email protected]> * ci: redice gradlew commands amount Signed-off-by: BAStos525 <[email protected]> --------- Signed-off-by: BAStos525 <[email protected]> Signed-off-by: BAStos525 <[email protected]>
1 parent 6558191 commit 29e5694

File tree

10 files changed

+94
-12
lines changed

10 files changed

+94
-12
lines changed

.github/workflows/iroha2-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ on:
55
branches: [ iroha2-dev, iroha2-main ]
66
jobs:
77
build:
8-
runs-on: self-hosted
9-
8+
runs-on: ubuntu-latest
9+
1010
env:
1111
IROHA_IMAGE_TAG: "2.0.0-pre-rc.22.2" # Place "dev" to run on the last iroha
1212

.github/workflows/iroha2.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212
- name: Set up JDK 17
1313
uses: actions/setup-java@v3
1414
with:
@@ -23,8 +23,26 @@ jobs:
2323
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
2424
restore-keys: |
2525
${{ runner.os }}-gradle-
26-
- name: Build with Gradle
27-
run: ./gradlew build
26+
- name: Build with Gradle & Sonarqube analysis
27+
run: |
28+
./gradlew build
29+
./gradlew jacocoTestReport
30+
./gradlew sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }}
31+
- name: DefectDojo
32+
if: always()
33+
uses: C4tWithShell/[email protected]
34+
with:
35+
token: ${{ secrets.DEFECTOJO_TOKEN }}
36+
defectdojo_url: ${{ secrets.DEFECTOJO_URL }}
37+
product_type: iroha2
38+
engagement: ${{ github.ref_name }}
39+
tools: "SonarQube API Import,Github Vulnerability Scan"
40+
sonar_projectKey: iroha2-java
41+
github_token: ${{ secrets.GITHUB_TOKEN }}
42+
github_repository: ${{ github.repository }}
43+
product: ${{ github.repository }}
44+
environment: Test
45+
reports: '{"Github Vulnerability Scan": "github.json"}'
2846
- name: Cleanup Gradle Cache
2947
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
3048
# Restoring these files from a GitHub Actions cache might cause problems for future builds.

build.gradle

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ plugins {
1515
id 'org.jmailen.kotlinter' version "$kotlinLinterVer"
1616
id 'maven-publish'
1717
id 'com.github.johnrengelman.shadow' version '8.1.1'
18+
id 'org.sonarqube' version "5.1.0.4882"
19+
id 'jacoco'
1820
}
1921

2022
allprojects {
@@ -30,6 +32,7 @@ subprojects {
3032
apply plugin: 'org.jetbrains.kotlin.jvm'
3133
apply plugin: 'org.jmailen.kotlinter'
3234
apply plugin: 'com.github.johnrengelman.shadow'
35+
apply plugin: 'jacoco'
3336

3437
publishing {
3538
publications {
@@ -53,10 +56,6 @@ subprojects {
5356
group = 'jp.co.soramitsu.iroha2-java'
5457
version = 'git rev-parse --short HEAD'.execute().text.trim()
5558

56-
test {
57-
useJUnitPlatform()
58-
}
59-
6059
java {
6160
toolchain {
6261
languageVersion = JavaLanguageVersion.of(8)
@@ -96,6 +95,36 @@ subprojects {
9695
// uncomment to produce shadowJar build by default
9796
// it is disabled by default to publish original version by CI, not a fat jar
9897
tasks.shadowJar.enabled = false
98+
99+
test {
100+
useJUnitPlatform()
101+
}
102+
103+
jacocoTestReport {
104+
reports {
105+
xml.required = true
106+
}
107+
}
108+
109+
plugins.withType(JacocoPlugin) {
110+
tasks["test"].finalizedBy 'jacocoTestReport'
111+
}
112+
113+
sonar {
114+
properties {
115+
property "sonar.projectKey", "iroha-java"
116+
property "sonar.host.url", "https://sonar.katana.soramitsu.co.jp"
117+
property "sonar.java.coveragePlugin", "jacoco"
118+
property "sonar.projectName", "${project.group}:${rootProject.name}.${project.name}"
119+
property "sonar.sources", "${project.projectDir}/src/main/kotlin"
120+
// exclude projects with no tests
121+
if (project.name != "codegen" && project.name != "model" && project.name != "tutorial") {
122+
property "sonar.tests", "${project.projectDir}/src/test"
123+
}
124+
property "sonar.java.test.binaries", "${project.projectDir}/build/test-results/test/binary"
125+
property "sonar.junit.reportPaths", "${project.projectDir}/build/test-results/test/"
126+
}
127+
}
99128
}
100129

101130
task allShadowJars {

examples/tutorial/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ dependencies {
1010
implementation(project(":block"))
1111
api(project(":admin-client"))
1212
}
13+
14+
tasks.jacocoTestReport {
15+
mustRunAfter(":admin-client:jacocoTestReport")
16+
mustRunAfter(":block:jacocoTestReport")
17+
mustRunAfter(":client:jacocoTestReport")
18+
mustRunAfter(":codegen:jacocoTestReport")
19+
mustRunAfter(":model:jacocoTestReport")
20+
mustRunAfter(":test-tools:jacocoTestReport")
21+
}

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ i2pCryptoEddsa=0.3.0
1313
multihashVersion=1.3.0
1414
googleTinkVer=1.9.0
1515
# testing
16-
testContainersVer=1.18.3
16+
testContainersVer=1.20.3
1717
junitVersion=5.9.3
1818
# logging
1919
logbackVer=1.2.3
2020
org.gradle.jvmargs=-XX:MetaspaceSize=128M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
21+
systemProp.sonar.host.url=https://sonar.katana.soramitsu.co.jp

modules/block/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ dependencies {
77
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5:$kotlinVer"
88
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVer"
99
}
10+
11+
jacocoTestReport {
12+
mustRunAfter(":admin-client:jacocoTestReport")
13+
}

modules/client/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ dependencies {
3131

3232
testApi project(":test-tools")
3333
}
34+
35+
jacocoTestReport {
36+
mustRunAfter(":admin-client:jacocoTestReport")
37+
mustRunAfter(":block:jacocoTestReport")
38+
}

modules/codegen/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ task generate(type: JavaExec) {
2020
args "schemaFileName=schema.json"
2121
finalizedBy ':model:formatKotlin'
2222
}
23+
24+
jacocoTestReport {
25+
mustRunAfter(":admin-client:jacocoTestReport")
26+
mustRunAfter(":block:jacocoTestReport")
27+
mustRunAfter(":client:jacocoTestReport")
28+
}

modules/model/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
jacocoTestReport {
2+
mustRunAfter(":admin-client:jacocoTestReport")
3+
mustRunAfter(":block:jacocoTestReport")
4+
mustRunAfter(":client:jacocoTestReport")
5+
mustRunAfter(":codegen:jacocoTestReport")
6+
}

modules/test-tools/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ dependencies {
1818
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVer"
1919
}
2020

21-
test {
22-
useJUnitPlatform()
21+
jacocoTestReport {
22+
mustRunAfter(":admin-client:jacocoTestReport")
23+
mustRunAfter(":block:jacocoTestReport")
24+
mustRunAfter(":client:jacocoTestReport")
25+
mustRunAfter(":codegen:jacocoTestReport")
26+
mustRunAfter(":model:jacocoTestReport")
2327
}

0 commit comments

Comments
 (0)