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

DOPS-3309: Add sonar & defectdojo analysis #440

Draft
wants to merge 30 commits into
base: iroha2-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
23 changes: 19 additions & 4 deletions .github/workflows/iroha2-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Iroha2-java pull requests workflow
on:
pull_request:
branches: [ iroha2-dev, iroha2-main ]

jobs:
build:
runs-on: self-hosted

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -23,8 +23,23 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: ./gradlew build --info
- name: Build with Gradle & Sonarqube analysis
run: ./gradlew build test testCoverage sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }} --info
- name: DefectDojo
if: always()
uses: C4tWithShell/[email protected]
with:
token: ${{ secrets.DEFECTOJO_TOKEN }}
defectdojo_url: ${{ secrets.DEFECTOJO_URL }}
product_type: iroha2
engagement: ${{ github.ref_name }}
tools: "SonarQube API Import,Github Vulnerability Scan"
sonar_projectKey: hyperledger:iroha-java
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repository: ${{ github.repository }}
product: ${{ github.repository }}
environment: Test
reports: '{"Github Vulnerability Scan": "github.json"}'
- name: Upload build reports
if: failure()
uses: actions/upload-artifact@v3
Expand Down
50 changes: 46 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ plugins {
id 'org.jmailen.kotlinter' version "$kotlinLinterVer"
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'org.sonarqube' version "5.1.0.4882"
id 'jacoco'
}

allprojects {
Expand All @@ -30,6 +32,7 @@ subprojects {
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jmailen.kotlinter'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'jacoco'

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

test {
useJUnitPlatform()
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
Expand Down Expand Up @@ -96,6 +95,49 @@ subprojects {
// uncomment to produce shadowJar build by default
// it is disabled by default to publish original version by CI, not a fat jar
tasks.shadowJar.enabled = false

task testCoverage(type: JacocoReport) {
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")

def sourceDirs = [
"${project.projectDir}/src/main/java",
"${project.projectDir}/src/main/kotlin",
"${project.projectDir}/src/debug/java",
"${project.projectDir}/src/debug/kotlin"
]
sourceDirectories.from = files(sourceDirs)

reports {
xml.required = true
html.required = true
}
}

test {
useJUnitPlatform()
}

jacoco {
toolVersion = "0.8.8"
reportsDirectory = file("$buildDir/reports/")
}

sonar {
properties {
property "sonar.projectKey", "hyperledger:iroha-java"
property "sonar.host.url", "https://sonar.katana.soramitsu.co.jp"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.projectName", "${project.group}:${rootProject.name}.${project.name}"
property "sonar.sources", "${project.projectDir}/src/main/kotlin"
// exclude projects with no tests
if (project.name != "codegen" && project.name != "model" && project.name != "tutorial") {
property "sonar.tests", "${project.projectDir}/src/test"
}
property "sonar.java.test.binaries", "${project.projectDir}/build/test-results/test/binary"
property "sonar.junit.reportPaths", "${project.projectDir}/build/test-results/test/"
property "sonar.coverage.jacoco.xmlReportPaths", "${project.projectDir}/build/reports/testCoverage/*.xml"
}
}
}

task allShadowJars {
Expand Down
9 changes: 9 additions & 0 deletions examples/tutorial/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ dependencies {
implementation(project(":block"))
api(project(":admin-client"))
}

tasks.testCoverage {
mustRunAfter(":admin-client:testCoverage")
mustRunAfter(":block:testCoverage")
mustRunAfter(":client:testCoverage")
mustRunAfter(":codegen:testCoverage")
mustRunAfter(":model:testCoverage")
mustRunAfter(":test-tools:testCoverage")
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ i2pCryptoEddsa=0.3.0
multihashVersion=1.3.0
googleTinkVer=1.9.0
# testing
testContainersVer=1.18.3
testContainersVer=1.20.3
junitVersion=5.9.3
# logging
logbackVer=1.2.3
org.gradle.jvmargs=-XX:MetaspaceSize=128M -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
systemProp.sonar.host.url=https://sonar.katana.soramitsu.co.jp
4 changes: 4 additions & 0 deletions modules/block/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5:$kotlinVer"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVer"
}

testCoverage {
mustRunAfter(":admin-client:testCoverage")
}
5 changes: 5 additions & 0 deletions modules/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ dependencies {

testApi project(":test-tools")
}

testCoverage {
mustRunAfter(":admin-client:testCoverage")
mustRunAfter(":block:testCoverage")
}
6 changes: 6 additions & 0 deletions modules/codegen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ task generate(type: JavaExec) {
args "schemaFileName=schema.json"
finalizedBy ':model:formatKotlin'
}

testCoverage {
mustRunAfter(":admin-client:testCoverage")
mustRunAfter(":block:testCoverage")
mustRunAfter(":client:testCoverage")
}
6 changes: 6 additions & 0 deletions modules/model/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
testCoverage {
mustRunAfter(":admin-client:testCoverage")
mustRunAfter(":block:testCoverage")
mustRunAfter(":client:testCoverage")
mustRunAfter(":codegen:testCoverage")
}
8 changes: 6 additions & 2 deletions modules/test-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVer"
}

test {
useJUnitPlatform()
testCoverage {
mustRunAfter(":admin-client:testCoverage")
mustRunAfter(":block:testCoverage")
mustRunAfter(":client:testCoverage")
mustRunAfter(":codegen:testCoverage")
mustRunAfter(":model:testCoverage")
}
Loading