Merge pull request #5413 from vector-im/michaelk/code_cov_alt
Code coverage using jacoco (and xml report)
This commit is contained in:
commit
b25d11244b
|
@ -308,15 +308,8 @@ jobs:
|
||||||
emulator.log
|
emulator.log
|
||||||
failure_screenshots/
|
failure_screenshots/
|
||||||
|
|
||||||
sonarqube:
|
codecov-units:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
if: always()
|
|
||||||
needs:
|
|
||||||
- integration-tests
|
|
||||||
- ui-tests
|
|
||||||
# - unit-tests TODO: code coverage from here too
|
|
||||||
- build-android-test-matrix-sdk
|
|
||||||
- build-android-test-app
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-java@v2
|
- uses: actions/setup-java@v2
|
||||||
|
@ -331,6 +324,39 @@ jobs:
|
||||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-gradle-
|
${{ runner.os }}-gradle-
|
||||||
|
- run: ./gradlew allCodeCoverageReport $CI_GRADLE_ARG_PROPERTIES
|
||||||
|
- name: Upload Codecov data
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: codecov-xml
|
||||||
|
path: |
|
||||||
|
build/reports/jacoco/allCodeCoverageReport/allCodeCoverageReport.xml
|
||||||
|
|
||||||
|
sonarqube:
|
||||||
|
runs-on: macos-latest
|
||||||
|
if: always()
|
||||||
|
needs:
|
||||||
|
- codecov-units
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
distribution: 'adopt'
|
||||||
|
java-version: '11'
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.gradle/caches
|
||||||
|
~/.gradle/wrapper
|
||||||
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-gradle-
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: codecov-xml # will restore to allCodeCoverageReport.xml by default; we restore to the same location in following tasks
|
||||||
|
- run: mkdir -p build/reports/jacoco/allCodeCoverageReport/
|
||||||
|
- run: mv allCodeCoverageReport.xml build/reports/jacoco/allCodeCoverageReport/
|
||||||
- run: ./gradlew sonarqube $CI_GRADLE_ARG_PROPERTIES
|
- run: ./gradlew sonarqube $CI_GRADLE_ARG_PROPERTIES
|
||||||
env:
|
env:
|
||||||
ORG_GRADLE_PROJECT_SONAR_LOGIN: ${{ secrets.SONAR_TOKEN }}
|
ORG_GRADLE_PROJECT_SONAR_LOGIN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
|
14
build.gradle
14
build.gradle
|
@ -105,6 +105,16 @@ task clean(type: Delete) {
|
||||||
delete rootProject.buildDir
|
delete rootProject.buildDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def launchTask = getGradle()
|
||||||
|
.getStartParameter()
|
||||||
|
.getTaskRequests()
|
||||||
|
.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
|
||||||
|
if (launchTask.contains("codeCoverageReport".toLowerCase())) {
|
||||||
|
apply from: 'coverage.gradle'
|
||||||
|
}
|
||||||
|
|
||||||
apply plugin: 'org.sonarqube'
|
apply plugin: 'org.sonarqube'
|
||||||
|
|
||||||
// To run a sonar analysis:
|
// To run a sonar analysis:
|
||||||
|
@ -119,10 +129,12 @@ sonarqube {
|
||||||
property "sonar.projectVersion", project(":vector").android.defaultConfig.versionName
|
property "sonar.projectVersion", project(":vector").android.defaultConfig.versionName
|
||||||
property "sonar.sourceEncoding", "UTF-8"
|
property "sonar.sourceEncoding", "UTF-8"
|
||||||
property "sonar.links.homepage", "https://github.com/vector-im/element-android/"
|
property "sonar.links.homepage", "https://github.com/vector-im/element-android/"
|
||||||
property "sonar.links.ci", "https://buildkite.com/matrix-dot-org/element-android"
|
property "sonar.links.ci", "https://github.com/vector-im/element-android/actions"
|
||||||
property "sonar.links.scm", "https://github.com/vector-im/element-android/"
|
property "sonar.links.scm", "https://github.com/vector-im/element-android/"
|
||||||
property "sonar.links.issue", "https://github.com/vector-im/element-android/issues"
|
property "sonar.links.issue", "https://github.com/vector-im/element-android/issues"
|
||||||
property "sonar.organization", "new_vector_ltd_organization"
|
property "sonar.organization", "new_vector_ltd_organization"
|
||||||
|
property "sonar.java.coveragePlugin", "jacoco"
|
||||||
|
property "sonar.coverage.jacoco.xmlReportPaths", "${project.buildDir}/reports/jacoco/allCodeCoverageReport/allCodeCoverageReport.xml"
|
||||||
property "sonar.login", project.hasProperty("SONAR_LOGIN") ? SONAR_LOGIN : "invalid"
|
property "sonar.login", project.hasProperty("SONAR_LOGIN") ? SONAR_LOGIN : "invalid"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
def excludes = [ ]
|
||||||
|
|
||||||
|
def initializeReport(report, projects, classExcludes) {
|
||||||
|
projects.each { project -> project.apply plugin: 'jacoco' }
|
||||||
|
report.executionData { fileTree(rootProject.rootDir.absolutePath).include("**/build/jacoco/*.exec") }
|
||||||
|
|
||||||
|
report.reports {
|
||||||
|
xml.enabled true
|
||||||
|
html.enabled true
|
||||||
|
csv.enabled false
|
||||||
|
}
|
||||||
|
|
||||||
|
gradle.projectsEvaluated {
|
||||||
|
def androidSourceDirs = []
|
||||||
|
def androidClassDirs = []
|
||||||
|
|
||||||
|
projects.each { project ->
|
||||||
|
switch (project) {
|
||||||
|
case { project.plugins.hasPlugin("com.android.application") }:
|
||||||
|
androidClassDirs.add("${project.buildDir}/tmp/kotlin-classes/debug")
|
||||||
|
androidSourceDirs.add("${project.projectDir}/src/main/kotlin")
|
||||||
|
androidSourceDirs.add("${project.projectDir}/src/main/java")
|
||||||
|
break
|
||||||
|
case { project.plugins.hasPlugin("com.android.library") }:
|
||||||
|
androidClassDirs.add("${project.buildDir}/tmp/kotlin-classes/debug")
|
||||||
|
androidSourceDirs.add("${project.projectDir}/src/main/kotlin")
|
||||||
|
androidSourceDirs.add("${project.projectDir}/src/main/java")
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
report.sourceSets project.sourceSets.main
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
report.sourceDirectories.setFrom(report.sourceDirectories + files(androidSourceDirs))
|
||||||
|
def classFiles = androidClassDirs.collect { files(it).files }.flatten()
|
||||||
|
report.classDirectories.setFrom(files((report.classDirectories.files + classFiles).collect {
|
||||||
|
fileTree(dir: it, excludes: classExcludes)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def collectProjects(predicate) {
|
||||||
|
return subprojects.findAll { it.buildFile.isFile() && predicate(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
task allCodeCoverageReport(type: JacocoReport) {
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
|
rootProject.apply plugin: 'jacoco'
|
||||||
|
// to limit projects in a specific report, add
|
||||||
|
// def excludedProjects = [ ... ]
|
||||||
|
// def projects = collectProjects { !excludedProjects.contains(it.name) }
|
||||||
|
def projects = collectProjects { true }
|
||||||
|
dependsOn { projects*.test }
|
||||||
|
initializeReport(it, projects, excludes)
|
||||||
|
}
|
|
@ -156,6 +156,7 @@ ext.groups = [
|
||||||
'org.ec4j.core',
|
'org.ec4j.core',
|
||||||
'org.glassfish.jaxb',
|
'org.glassfish.jaxb',
|
||||||
'org.hamcrest',
|
'org.hamcrest',
|
||||||
|
'org.jacoco',
|
||||||
'org.jetbrains',
|
'org.jetbrains',
|
||||||
'org.jetbrains.intellij.deps',
|
'org.jetbrains.intellij.deps',
|
||||||
'org.jetbrains.kotlin',
|
'org.jetbrains.kotlin',
|
||||||
|
|
Loading…
Reference in New Issue