Skip to content

Commit b1f06ad

Browse files
Update jacoco and github actions (commons-app#4639)
* Fix jacoco setup * Fix task name * Update CI yml file for codecov * Fix syntax error * Use all branch instead of just master * Fix report upload issue * Remove returnDefaultValues * Add Github Action and Codecov badge
1 parent fea5abd commit b1f06ad

File tree

6 files changed

+69
-6
lines changed

6 files changed

+69
-6
lines changed

.github/workflows/android.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: Android CI
22

3-
on:
4-
push
3+
on: [push, pull_request]
54

65
jobs:
76
build:
@@ -14,4 +13,6 @@ jobs:
1413
with:
1514
java-version: 1.8
1615
- name: Build with Gradle
17-
run: ./gradlew -Pcoverage jacocoTestBetaDebugUnitTestReport
16+
run: ./gradlew -Pcoverage testBetaDebugUnitTestCoverage
17+
- name: Upload Test Report
18+
run: bash <(curl -s https://codecov.io/bash) -f "app/build/reports/jacoco/testBetaDebugUnitTestCoverage/testBetaDebugUnitTestCoverage.xml"

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ android:
2323
licenses:
2424
- android-sdk-license-.+
2525
script:
26-
- "./gradlew -Pcoverage jacocoTestBetaDebugUnitTestReport"
26+
- "./gradlew -Pcoverage testBetaDebugUnitTestCoverage"
2727
- if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
2828
mkdir -p app/src/prodRelease/play/release-notes/en-US;
2929
fi

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Wikimedia Commons Android app
22
[![Build status](https://api.travis-ci.org/commons-app/apps-android-commons.svg?branch=master)](https://travis-ci.org/commons-app/apps-android-commons)
3+
[![Build status](https://github.com/commons-app/apps-android-commons/actions/workflows/android.yml/badge.svg?branch=master)](https://github.com/commons-app/apps-android-commons/actions?query=branch%3Amaster)
34
[![Preview the app](https://img.shields.io/badge/Preview-Appetize.io-orange.svg)](https://appetize.io/app/8ywtpe9f8tb8h6bey11c92vkcw)
5+
[![codecov](https://codecov.io/gh/commons-app/apps-android-commons/branch/master/graph/badge.svg)](https://codecov.io/gh/commons-app/apps-android-commons)
46

57
The Wikimedia Commons Android app allows users to upload pictures from their Android phone/tablet to Wikimedia Commons. Download the app [here][1], or view our [website][2].
68

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ apply plugin: 'com.android.application'
66
apply plugin: 'kotlin-android'
77
apply plugin: 'kotlin-kapt'
88
apply plugin: 'kotlin-android-extensions'
9-
apply plugin: "com.hiya.jacoco-android"
9+
apply from: "$rootDir/jacoco.gradle"
1010

1111
def isRunningOnTravisAndIsNotPRBuild = System.getenv("CI") == "true" && file('../play.p12').exists()
1212

build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ buildscript {
88
}
99
dependencies {
1010
classpath 'com.android.tools.build:gradle:4.0.1'
11-
classpath "com.hiya:jacoco-android:0.2"
1211
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
1312
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
1413
classpath 'org.codehaus.groovy:groovy-all:2.4.15'

jacoco.gradle

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
apply plugin: 'jacoco'
2+
3+
jacoco {
4+
toolVersion = "0.8.7"
5+
}
6+
7+
android {
8+
testOptions {
9+
unitTests.all {
10+
jacoco {
11+
includeNoLocationClasses = true
12+
}
13+
}
14+
}
15+
}
16+
17+
project.afterEvaluate {
18+
19+
android.applicationVariants.all { variant ->
20+
def name = variant.name
21+
def testTaskName = "test${name.capitalize()}UnitTest"
22+
23+
tasks.create(name: "${testTaskName}Coverage", type: JacocoReport, dependsOn: "$testTaskName") {
24+
group = "Reporting"
25+
description = "Generate Jacoco coverage reports for the ${name.capitalize()} build."
26+
27+
def fileFilter = ['**/R.class',
28+
'**/R$*.class',
29+
'**/*$ViewInjector*.*',
30+
'**/*$ViewBinder*.*',
31+
'**/BuildConfig.*',
32+
'**/Manifest*.*',
33+
'**/*Test*.*',
34+
'android/**/*.*']
35+
36+
//java compiled classes
37+
def javaTree = fileTree(
38+
dir: "${buildDir}/intermediates/classes/${name}",
39+
excludes: fileFilter
40+
)
41+
//kotlin compiled classes
42+
def kotlinTree = fileTree(
43+
dir: "${buildDir}/tmp/kotlin-classes/${name}",
44+
excludes: fileFilter
45+
)
46+
def mainSrc = "${project.projectDir}/src/main/java"
47+
48+
sourceDirectories.setFrom(files([mainSrc]))
49+
classDirectories.setFrom(files([javaTree, kotlinTree]))
50+
executionData.setFrom(fileTree(dir: "${buildDir}", includes: [
51+
"jacoco/${testTaskName}.exec",
52+
"outputs/code-coverage/connected/*coverage.ec"
53+
]))
54+
55+
reports {
56+
xml.enabled = true
57+
html.enabled = true
58+
}
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)