-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.gradle.kts
164 lines (154 loc) · 4.94 KB
/
ci.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import org.apache.tools.ant.taskdefs.condition.Os
import java.io.File
import java.io.InputStream
import java.util.Properties
val CI_GRADLE = "CI_GRADLE"
tasks.register("ciLint") {
group = CI_GRADLE
doLast {
gradlew(
"ktlintCheck",
"detekt",
"lintDebug",
)
}
}
tasks.register("ciUnitTest") {
group = CI_GRADLE
doLast {
gradlew(
"clean",
"koverXmlReportDebug",
"koverXmlReport",
"koverHtmlReportDebug",
"koverHtmlReport",
"koverVerifyDebug",
"koverVerify",
)
}
}
tasks.register("ciRecordScreenshots") {
group = CI_GRADLE
doLast {
gradlew("updateDebugScreenshotTest")
}
}
tasks.register("ciBuildApp") {
group = CI_GRADLE
doLast {
gradlew("assembleDebug")
copy {
from(rootProject.subprojects.map { it.layout.buildDirectory.asFile.get() })
include("**/*.apk")
exclude("**/apk/androidTest/**")
eachFile { path = name }
includeEmptyDirs = false
into("${layout.buildDirectory.asFile.get().path}/apk/")
}
}
}
tasks.register("ciEmulatorJobsMatrixSetup") {
group = CI_GRADLE
doLast {
EmulatorJobsMatrix().createMatrixJsonFile(rootProject = rootProject)
}
}
tasks.register("ciSdkManagerLicenses") {
group = CI_GRADLE
doLast {
val sdkDirPath = getAndroidSdkPath(rootDir = rootDir)
getSdkmanagerFile(rootDir = rootDir)?.let { sdkmanagerFile ->
val yesInputStream = object : InputStream() {
private val yesString = "y\n"
private var counter = 0
override fun read(): Int = yesString[counter % 2].also { counter++ }.code
}
exec {
executable = sdkmanagerFile.absolutePath
args = listOf("--list", "--sdk_root=$sdkDirPath")
println("exec: ${this.commandLine.joinToString(separator = " ")}")
}.apply { println("ExecResult: $this") }
exec {
executable = sdkmanagerFile.absolutePath
args = listOf("--licenses", "--sdk_root=$sdkDirPath")
standardInput = yesInputStream
println("exec: ${this.commandLine.joinToString(separator = " ")}")
}.apply { println("ExecResult: $this") }
}
}
}
tasks.register("devAll") {
group = CI_GRADLE
doLast {
gradlew("clean")
gradlew("ktlintFormat")
gradlew(
"ciLint",
"ciUnitTest",
"ciRecordScreenshots",
"ciBuildApp",
"assembleAndroidTest",
)
}
}
tasks.register("devAllEmulator") {
group = CI_GRADLE
doLast {
gradlew(
"clean",
"ciEmulatorJobsMatrixSetup",
)
gradlew("cleanManagedDevices", "--unused-only")
EmulatorJobsMatrix().getTaskList(rootProject = rootProject).map { it.split(" ") }
.forEach { tasks -> gradlew(*tasks.toTypedArray()) }
gradlew("cleanManagedDevices")
}
}
fun gradlew(
vararg tasks: String,
addToSystemProperties: Map<String, String>? = null,
) {
exec {
executable = File(
project.rootDir,
if (Os.isFamily(Os.FAMILY_WINDOWS)) "gradlew.bat" else "gradlew",
)
.also { it.setExecutable(true) }
.absolutePath
args = mutableListOf<String>().also { mutableArgs ->
mutableArgs.addAll(tasks)
addToSystemProperties?.toList()?.map { "-D${it.first}=${it.second}" }?.let {
mutableArgs.addAll(it)
}
mutableArgs.add("--stacktrace")
}
val sdkDirPath = Properties().apply {
val propertiesFile = File(rootDir, "local.properties")
if (propertiesFile.exists()) {
load(propertiesFile.inputStream())
}
}.getProperty("sdk.dir")
if (sdkDirPath != null) {
val platformToolsDir = "$sdkDirPath${java.io.File.separator}platform-tools"
val pahtEnvironment = System.getenv("PATH").orEmpty()
if (!pahtEnvironment.contains(platformToolsDir)) {
environment = environment.toMutableMap().apply {
put("PATH", "$platformToolsDir:$pahtEnvironment")
}
}
}
if (System.getenv("JAVA_HOME") == null) {
System.getProperty("java.home")?.let { javaHome ->
environment = environment.toMutableMap().apply {
put("JAVA_HOME", javaHome)
}
}
}
if (System.getenv("ANDROID_HOME") == null) {
environment = environment.toMutableMap().apply {
put("ANDROID_HOME", "$sdkDirPath")
}
}
println("commandLine: ${this.commandLine.joinToString(separator = " ")}")
}.apply { println("ExecResult: $this") }
}