diff --git a/app/build.gradle.kts b/app/build.gradle.kts index be9b8d06..18583820 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -36,7 +36,7 @@ android { minSdk = Android.minSdk targetSdk = Android.targetSdk versionCode = 238 - versionName = "17" + versionName = latestTagName() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/kotlin/com/svenjacobs/app/leon/ui/screens/settings/SettingsScreen.kt b/app/src/main/kotlin/com/svenjacobs/app/leon/ui/screens/settings/SettingsScreen.kt index 66ca795d..a47f8169 100644 --- a/app/src/main/kotlin/com/svenjacobs/app/leon/ui/screens/settings/SettingsScreen.kt +++ b/app/src/main/kotlin/com/svenjacobs/app/leon/ui/screens/settings/SettingsScreen.kt @@ -160,7 +160,7 @@ private fun Content( bottom = 8.dp, end = 8.dp, ), - text = BuildConfig.VERSION_NAME, + text = "v${BuildConfig.VERSION_NAME}", style = MaterialTheme.typography.bodySmall, ) } diff --git a/buildSrc/src/main/kotlin/Git.kt b/buildSrc/src/main/kotlin/Git.kt new file mode 100644 index 00000000..60f4ff64 --- /dev/null +++ b/buildSrc/src/main/kotlin/Git.kt @@ -0,0 +1,33 @@ +/* + * Léon - The URL Cleaner + * Copyright (C) 2022 Sven Jacobs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +fun latestTagName(): String { + val tag = execute("git", "describe", "--tags", "--abbrev=0", "--match", "v*") + if (tag.isBlank()) throw IllegalArgumentException("Could not determine tag") + return tag.substring(1) +} + +private fun execute(vararg cmd: String): String { + var output: String + val process = ProcessBuilder(*cmd).start() + process.inputStream.reader(Charsets.UTF_8).use { + output = it.readText() + } + process.waitFor() + return output.trim() +}