This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
build.gradle.kts
82 lines (67 loc) · 2.11 KB
/
build.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
import org.codehaus.groovy.runtime.IOGroovyMethods
import org.codehaus.groovy.runtime.ProcessGroovyMethods.closeStreams
import java.io.BufferedReader
import java.io.IOException
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
val kotlinVersion: String by extra("1.6.10")
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.2.2")
classpath(kotlin("gradle-plugin", version = kotlinVersion))
classpath(kotlin("serialization", version = kotlinVersion))
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
}
task("clean", Delete::class) {
delete(rootProject.buildDir)
}
tasks.register<WriteDebugUpdate>("androidDebugUpdateXML")
/** Creates an update XML to be used by the application */
open class WriteDebugUpdate : DefaultTask() {
companion object {
@Throws(IOException::class)
private fun String.execute(): Process = Runtime.getRuntime().exec(this)
@Throws(IOException::class)
private fun Process.getText(): String =
IOGroovyMethods.getText(BufferedReader(java.io.InputStreamReader(inputStream))).also {
closeStreams(this)
}
@Throws(IOException::class)
private fun getCommitCount(): String =
"git rev-list --count HEAD".execute().getText().trim()
@Throws(IOException::class)
private fun getLatestCommitMsg(): String =
"git log -1 --pretty=%B".execute().getText().trim()
}
/** Task of this task */
@Throws(IOException::class)
@TaskAction
fun main() {
val file = File("android/src/debug/assets/update.json")
// up the commit by one for when shosetsu-preview builds
val commitCount = getCommitCount().toInt()
file.writeText(
"""
{
"latestVersion":"$commitCount",
"url":"https://github.com/shosetsuorg/shosetsu-preview/releases/download/r$commitCount/shosetsu-r$commitCount.apk",
"releaseNotes":[
"${getLatestCommitMsg().replace("\n", "\",\n\t\t\t\t\"")}"
]
}
""".trimIndent()
)
}
}