|
1 | 1 | import io.gitlab.arturbosch.detekt.Detekt |
2 | 2 | import io.gitlab.arturbosch.detekt.report.ReportMergeTask |
3 | 3 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
| 4 | +import java.io.ByteArrayOutputStream |
4 | 5 |
|
5 | 6 | plugins { |
6 | 7 | val kotlinVersion = "1.9.21" |
@@ -40,8 +41,8 @@ dependencies { |
40 | 41 | implementation("io.ktor:ktor-client-websockets:$ktorVersion") |
41 | 42 |
|
42 | 43 | val mokoMvvmVersion = "0.16.1" |
43 | | - implementation("dev.icerock.moko:mvvm-core:${mokoMvvmVersion}") |
44 | | - implementation("dev.icerock.moko:mvvm-compose:${mokoMvvmVersion}") |
| 44 | + implementation("dev.icerock.moko:mvvm-core:$mokoMvvmVersion") |
| 45 | + implementation("dev.icerock.moko:mvvm-compose:$mokoMvvmVersion") |
45 | 46 |
|
46 | 47 | implementation("io.insert-koin:koin-core:3.5.3") |
47 | 48 | implementation("io.insert-koin:koin-compose:1.1.2") |
@@ -112,3 +113,106 @@ configurations.all { |
112 | 113 | attribute(Attribute.of("ui", String::class.java), "awt") |
113 | 114 | } |
114 | 115 | } |
| 116 | + |
| 117 | +tasks.register("release") { |
| 118 | + val versionParam = findProperty("v")?.toString() |
| 119 | + |
| 120 | + doLast { |
| 121 | + val versionTag = "v" + getNewVersion(versionParam) |
| 122 | + |
| 123 | + println() |
| 124 | + println("Creating git tag $versionTag") |
| 125 | + exec { |
| 126 | + commandLine("git", "tag", versionTag) |
| 127 | + } |
| 128 | + |
| 129 | + println("Push git tag $versionTag to origin") |
| 130 | + exec { |
| 131 | + commandLine("git", "push", "origin", versionTag) |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +fun getNewVersion(version: String?): VersionNumber { |
| 137 | + val lastTagVersion = getLastTag() |
| 138 | + |
| 139 | + val newVersion = if (version != null) { |
| 140 | + VersionNumber.fromString(version) |
| 141 | + } else { |
| 142 | + println( |
| 143 | + """ |
| 144 | + The latest version tag is: $lastTagVersion |
| 145 | + What do you want to increase? |
| 146 | + 1): Major |
| 147 | + 2): Minor |
| 148 | + 3): Patch (default) |
| 149 | + """.trimIndent() |
| 150 | + ) |
| 151 | + |
| 152 | + when (readln()) { |
| 153 | + "1" -> lastTagVersion.nextMajor() |
| 154 | + "2" -> lastTagVersion.nextMinor() |
| 155 | + else -> lastTagVersion.nextPatch() |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + require(newVersion > lastTagVersion) { |
| 160 | + "New version ($newVersion) must be grater than the latest version ($lastTagVersion)." |
| 161 | + } |
| 162 | + |
| 163 | + return newVersion |
| 164 | +} |
| 165 | + |
| 166 | +fun getLastTag(): VersionNumber { |
| 167 | + // Fetch all the remote tags |
| 168 | + exec { |
| 169 | + commandLine("git", "fetch", "--tags") |
| 170 | + } |
| 171 | + |
| 172 | + // Capture the names of all tags |
| 173 | + val osAllTags = ByteArrayOutputStream() |
| 174 | + exec { |
| 175 | + commandLine("git", "tag", "-l") |
| 176 | + standardOutput = osAllTags |
| 177 | + } |
| 178 | + val allTags: List<String> = osAllTags.toString(Charsets.UTF_8) |
| 179 | + .trim() |
| 180 | + .split("\n") |
| 181 | + .filter { it.matches(Regex("""v\d+\.\d+\.\d+""")) } |
| 182 | + .map { it.removePrefix("v") } |
| 183 | + |
| 184 | + return VersionNumber.fromString(allTags.last()) |
| 185 | +} |
| 186 | + |
| 187 | +data class VersionNumber(val major: Int, val minor: Int, val patch: Int) { |
| 188 | + override fun toString(): String = "$major.$minor.$patch" |
| 189 | + |
| 190 | + fun nextMajor() = VersionNumber(major + 1, 0, 0) |
| 191 | + |
| 192 | + fun nextMinor() = VersionNumber(major, minor + 1, 0) |
| 193 | + |
| 194 | + fun nextPatch() = VersionNumber(major, minor, patch + 1) |
| 195 | + |
| 196 | + operator fun compareTo(other: VersionNumber): Int { |
| 197 | + return when { |
| 198 | + this.major != other.major -> this.major.compareTo(other.major) |
| 199 | + this.minor != other.minor -> this.minor.compareTo(other.minor) |
| 200 | + else -> this.patch.compareTo(other.patch) |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + companion object { |
| 205 | + fun fromString(version: String): VersionNumber { |
| 206 | + val split = version.removePrefix("v").split('.') |
| 207 | + require(split.count() == 3) { |
| 208 | + "The provided version '$version' is not valid. It must follow the pattern of x.y.z (e.g. 1.2.3)" |
| 209 | + } |
| 210 | + |
| 211 | + return VersionNumber( |
| 212 | + major = split[0].toInt(), |
| 213 | + minor = split[1].toInt(), |
| 214 | + patch = split[2].toInt() |
| 215 | + ) |
| 216 | + } |
| 217 | + } |
| 218 | +} |
0 commit comments