Skip to content

Commit

Permalink
Add sonar & defectdojo analysis
Browse files Browse the repository at this point in the history
Signed-off-by: BAStos525 <jungle.vas@yandex.ru>
  • Loading branch information
BAStos525 committed Nov 12, 2024
1 parent 021cbf6 commit b1552e7
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/iroha2-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ on:
branches: [ iroha2-dev, iroha2-main ]
jobs:
build:
runs-on: self-hosted
runs-on: ubuntu-latest

env:
IROHA_IMAGE_TAG: "2.0.0-pre-rc.22.2" # Place "dev" to run on the last iroha

steps:
- uses: actions/checkout@v3
Expand Down
25 changes: 22 additions & 3 deletions .github/workflows/iroha2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest

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,27 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: ./gradlew build
- name: Build with Gradle & Sonarqube analysis
run: |
./gradlew build --info
./gradlew test --info
./gradlew jacocoTestReport --info
./gradlew sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }} --info
- name: DefectDojo
if: always()
uses: C4tWithShell/defectdojo-action@1.0.5
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: iroha2-java
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repository: ${{ github.repository }}
product: ${{ github.repository }}
environment: Test
reports: '{"Github Vulnerability Scan": "github.json"}'
- name: Cleanup Gradle Cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
Expand Down
37 changes: 33 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,36 @@ 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

test {
useJUnitPlatform()
}

jacocoTestReport {
reports {
xml.required = true
}
}

plugins.withType(JacocoPlugin) {
tasks["test"].finalizedBy 'jacocoTestReport'
}

sonar {
properties {
property "sonar.projectKey", "hyperledger-iroha: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/"
}
}
}

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.jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
mustRunAfter(":codegen:jacocoTestReport")
mustRunAfter(":model:jacocoTestReport")
mustRunAfter(":test-tools:jacocoTestReport")
}
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"
}

jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
}
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")
}

jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
}
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'
}

jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
}
6 changes: 6 additions & 0 deletions modules/model/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
mustRunAfter(":codegen:jacocoTestReport")
}
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()
jacocoTestReport {
mustRunAfter(":admin-client:jacocoTestReport")
mustRunAfter(":block:jacocoTestReport")
mustRunAfter(":client:jacocoTestReport")
mustRunAfter(":codegen:jacocoTestReport")
mustRunAfter(":model:jacocoTestReport")
}

0 comments on commit b1552e7

Please sign in to comment.