Skip to content

Commit

Permalink
[Add] Try Sun* CI
Browse files Browse the repository at this point in the history
  • Loading branch information
namnh-0652 committed Jun 12, 2020
1 parent 402f409 commit 22872b6
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -37,4 +37,5 @@ buildSrc/build/
gkc_*

# captured images or li
captures/
captures/
.framgia-ci-reports/
83 changes: 82 additions & 1 deletion app/build.gradle.kts
Expand Up @@ -6,12 +6,91 @@ plugins {
kotlin(Plugins.kotlinExt)
kotlin(Plugins.kotlinApt)
id(Plugins.detekt).version(Versions.detekt)
jacoco
}

buildscript {
apply(from = "ktlint.gradle.kts")
}

jacoco {
toolVersion = "0.8.1"
reportsDir = file("${project.rootDir}/.framgia-ci-reports/coverage/")
}

project.afterEvaluate {
// Grab all build types and product flavors
val buildTypeNames: List<String> = android.buildTypes.map { it.name }
val productFlavorNames: ArrayList<String> = ArrayList(android.productFlavors.map { it.name })
// When no product flavors defined, use empty
if (productFlavorNames.isEmpty()) productFlavorNames.add("")
productFlavorNames.forEach { productFlavorName ->
buildTypeNames.forEach { buildTypeName ->
val sourceName: String
val sourcePath: String
if (productFlavorName.isEmpty()) {
sourcePath = buildTypeName
sourceName = buildTypeName
} else {
sourcePath = "$productFlavorName/$buildTypeName"
sourceName = "$productFlavorName${buildTypeName.capitalize()}"
}
val testTaskName = "test${sourceName.capitalize()}UnitTest"
// Create coverage task of form 'testFlavorTypeCoverage' depending on 'testFlavorTypeUnitTest'
task<JacocoReport>("${testTaskName}Coverage") {
//where store all test to run follow second way above
group = "coverage"
description =
"Generate Jacoco coverage reports on the ${sourceName.capitalize()} build."
val excludeFiles = arrayListOf(
"**/R.class", "**/R$*.class", "**/BuildConfig.*", "**/Manifest*.*",
"**/*Test*.*", "android/**/*.*",
"**/*Application*.*",
"**/*Activity*.*",
"**/*Fragment*.*",
"**/*Adapter*.*",
"**/*Dialog*.*",
"**/*Args*.*",
"**/*Companion*.*",
"**/*Kt*.*"
)

//Explain to Jacoco where are you .class file java and kotlin
classDirectories.setFrom(
fileTree("${project.buildDir}/intermediates/classes/$sourcePath").exclude(
excludeFiles
),
fileTree("${project.buildDir}/tmp/kotlin-classes/$sourceName").exclude(
excludeFiles
)
)
val coverageSourceDirs = arrayListOf(
"src/main/java",
"src/$productFlavorName/java",
"src/$buildTypeName/java"
)

additionalSourceDirs.setFrom(files(coverageSourceDirs))

//Explain to Jacoco where is your source code
sourceDirectories.setFrom(files(coverageSourceDirs))

//execute file .exec to generate data report
executionData.setFrom(files("${project.buildDir}/jacoco/$testTaskName.exec"))

reports {
xml.isEnabled = true
html.isEnabled = true
xml.destination =
File("${project.rootDir}/.framgia-ci-reports/coverage/coverage.xml")
html.destination = File("${project.rootDir}/.framgia-ci-reports/coverage")
}
dependsOn(testTaskName)
}
}
}
}

android {
compileSdkVersion(Versions.compile_sdk_version)
buildToolsVersion(Versions.build_tools_version)
Expand Down Expand Up @@ -55,7 +134,9 @@ detekt {
reports {
html.enabled = true // observe findings in your browser with structure and code snippets
xml.enabled = false // checkstyle like format mainly for integrations like Jenkins
txt.enabled = false // similar to the console output, contains issue signature to manually edit baseline files
txt.enabled =
false // similar to the console output, contains issue signature to manually edit baseline files
html.destination = File("${project.rootDir}/.framgia-ci-reports/detekt/detekt.html")
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/ktlint.gradle.kts
Expand Up @@ -8,7 +8,7 @@ val ktlintCheck by tasks.creating(JavaExec::class) {
description = "Check Kotlin code style."
classpath = configurations.getByName("ktlint")
main = "com.pinterest.ktlint.Main"
args = listOf("src/**/*.kt", "--reporter=html,output=$buildDir/reports/ktlint/ktlint.html")
args = listOf("src/**/*.kt", "--reporter=html,output=${project.rootDir}/.framgia-ci-reports/ktlint/ktlint.html")
}

val ktlintFormat by tasks.creating(JavaExec::class) {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/namnh/androidsetup/logic/MainLogic.kt
@@ -0,0 +1,13 @@
package com.namnh.androidsetup.logic

class MainLogic {
fun add(a: Int, b: Int) = a + b
fun greet(name: String = "World"): String {
return "Hello, $name!"
}

fun hasDuplicatedNumber(list: List<Int>, checkNum: Int): Boolean {
val count = list.count { i -> i == checkNum }
return count > 1
}
}
58 changes: 58 additions & 0 deletions app/src/test/java/com/namnh/androidsetup/logic/MainLogicTest.kt
@@ -0,0 +1,58 @@
package com.namnh.androidsetup.logic

import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(JUnit4::class)
class MainLogicTest {
private lateinit var mainLogic: MainLogic
@Before
fun setup() {
mainLogic = MainLogic()
}

@Test
fun `hello world`() {
assertEquals("Hello, World!", mainLogic.greet())
}

@Test
fun `hello NamNH`() {
assertEquals("Hello, NamNH!", mainLogic.greet("NamNH"))
}

@Test
fun `add positive`() {
assertEquals(2, mainLogic.add(1, 1))
assertEquals(4, mainLogic.add(1, 3))
}

@Test
fun `add negative`() {
assertEquals(2, mainLogic.add(-1, 3))
assertEquals(4, mainLogic.add(-1, 5))
}

@Test
fun `add positive and negative`() {
assertEquals(-1, mainLogic.add(-3, 2))
assertEquals(2, mainLogic.add(-3, 5))
}

@Test
fun `has duplicated number`() {
assertTrue(mainLogic.hasDuplicatedNumber(listOf(1, 2, 3, 4, 2), 2))
assertTrue(mainLogic.hasDuplicatedNumber(listOf(1, 4, 3, 4, 2), 4))
}

@Test
fun `has no duplicated number`() {
assertFalse(mainLogic.hasDuplicatedNumber(listOf(1, 2, 3, 4), 1))
assertFalse(mainLogic.hasDuplicatedNumber(listOf(1, 2, 3, 4), 2))
assertFalse(mainLogic.hasDuplicatedNumber(listOf(1, 2, 3, 4), 0))
assertFalse(mainLogic.hasDuplicatedNumber(listOf(), 0))
}
}
24 changes: 24 additions & 0 deletions framgia-ci.yml
@@ -0,0 +1,24 @@
project_type: android
build:
configurations:
image: framgiaciteam/android:latest

test:
download_dependencies:
ignore: false
command: ./gradlew androidDependencies
run_unit_test:
ignore: false
command: ./gradlew testDebugUnitTestCoverage
check_style:
ignore: false
command: ./gradlew ktlintCheck
check_lint:
ignore: false
command: ./gradlew detekt

cache:
gradle:
folder: ~/.gradle
file: app/build.gradle.kts

0 comments on commit 22872b6

Please sign in to comment.