summaryrefslogtreecommitdiff
path: root/src/android/app/build.gradle.kts
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/app/build.gradle.kts')
-rw-r--r--src/android/app/build.gradle.kts83
1 files changed, 26 insertions, 57 deletions
diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts
index 53aafa08c..06e59d1ac 100644
--- a/src/android/app/build.gradle.kts
+++ b/src/android/app/build.gradle.kts
@@ -188,8 +188,15 @@ tasks.create<Delete>("ktlintReset") {
188 delete(File(buildDir.path + File.separator + "intermediates/ktLint")) 188 delete(File(buildDir.path + File.separator + "intermediates/ktLint"))
189} 189}
190 190
191val showFormatHelp = {
192 logger.lifecycle(
193 "If this check fails, please try running \"gradlew ktlintFormat\" for automatic " +
194 "codestyle fixes"
195 )
196}
197tasks.getByPath("ktlintKotlinScriptCheck").doFirst { showFormatHelp.invoke() }
198tasks.getByPath("ktlintMainSourceSetCheck").doFirst { showFormatHelp.invoke() }
191tasks.getByPath("loadKtlintReporters").dependsOn("ktlintReset") 199tasks.getByPath("loadKtlintReporters").dependsOn("ktlintReset")
192tasks.getByPath("preBuild").dependsOn("ktlintCheck")
193 200
194ktlint { 201ktlint {
195 version.set("0.47.1") 202 version.set("0.47.1")
@@ -228,71 +235,33 @@ dependencies {
228 implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") 235 implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
229} 236}
230 237
231fun getGitVersion(): String { 238fun runGitCommand(command: List<String>): String {
232 var versionName = "0.0" 239 return try {
233 240 ProcessBuilder(command)
234 try {
235 versionName = ProcessBuilder("git", "describe", "--always", "--long")
236 .directory(project.rootDir) 241 .directory(project.rootDir)
237 .redirectOutput(ProcessBuilder.Redirect.PIPE) 242 .redirectOutput(ProcessBuilder.Redirect.PIPE)
238 .redirectError(ProcessBuilder.Redirect.PIPE) 243 .redirectError(ProcessBuilder.Redirect.PIPE)
239 .start().inputStream.bufferedReader().use { it.readText() } 244 .start().inputStream.bufferedReader().use { it.readText() }
240 .trim() 245 .trim()
241 .replace(Regex("(-0)?-[^-]+$"), "")
242 } catch (e: Exception) { 246 } catch (e: Exception) {
243 logger.error("Cannot find git, defaulting to dummy version number") 247 logger.error("Cannot find git")
248 ""
244 } 249 }
245
246 if (System.getenv("GITHUB_ACTIONS") != null) {
247 val gitTag = System.getenv("GIT_TAG_NAME")
248 versionName = gitTag ?: versionName
249 }
250
251 return versionName
252} 250}
253 251
254fun getGitHash(): String { 252fun getGitVersion(): String {
255 try { 253 val versionName = if (System.getenv("GITHUB_ACTIONS") != null) {
256 val processBuilder = ProcessBuilder("git", "rev-parse", "--short", "HEAD") 254 val gitTag = System.getenv("GIT_TAG_NAME") ?: ""
257 processBuilder.directory(project.rootDir) 255 gitTag
258 val process = processBuilder.start() 256 } else {
259 val inputStream = process.inputStream 257 runGitCommand(listOf("git", "describe", "--always", "--long"))
260 val errorStream = process.errorStream 258 .replace(Regex("(-0)?-[^-]+$"), "")
261 process.waitFor()
262
263 return if (process.exitValue() == 0) {
264 inputStream.bufferedReader()
265 .use { it.readText().trim() } // return the value of gitHash
266 } else {
267 val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
268 logger.error("Error running git command: $errorMessage")
269 "dummy-hash" // return a dummy hash value in case of an error
270 }
271 } catch (e: Exception) {
272 logger.error("$e: Cannot find git, defaulting to dummy build hash")
273 return "dummy-hash" // return a dummy hash value in case of an error
274 } 259 }
260 return versionName.ifEmpty { "0.0" }
275} 261}
276 262
277fun getBranch(): String { 263fun getGitHash(): String =
278 try { 264 runGitCommand(listOf("git", "rev-parse", "--short", "HEAD")).ifEmpty { "dummy-hash" }
279 val processBuilder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD") 265
280 processBuilder.directory(project.rootDir) 266fun getBranch(): String =
281 val process = processBuilder.start() 267 runGitCommand(listOf("git", "rev-parse", "--abbrev-ref", "HEAD")).ifEmpty { "dummy-hash" }
282 val inputStream = process.inputStream
283 val errorStream = process.errorStream
284 process.waitFor()
285
286 return if (process.exitValue() == 0) {
287 inputStream.bufferedReader()
288 .use { it.readText().trim() } // return the value of gitHash
289 } else {
290 val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
291 logger.error("Error running git command: $errorMessage")
292 "dummy-hash" // return a dummy hash value in case of an error
293 }
294 } catch (e: Exception) {
295 logger.error("$e: Cannot find git, defaulting to dummy build hash")
296 return "dummy-hash" // return a dummy hash value in case of an error
297 }
298}