INNER CODE UNIT · Kotlin
GitFullVersionNameSource
ProtonVPN/android-app · buildSrc/src/main/kotlin/GitFullVersionNameSource.kt:27
abstract class GitFullVersionNameSource : ValueSource<String, GitFullVersionNameSource.Parameters> {
@get:Inject
abstract val execOperations: ExecOperations
override fun obtain(): String? {
// Find last tag in the form M.m.D.R, D and R are optional
val tag = exec("git", "tag", "--sort=v:refname", "--merged", "HEAD")
.trim()
.split("\n")
.reversed()
.find { it.matches(Regex("\\d+(\\.\\d+){1,3}")) }
val tagSplit = tag
?.split(".")
?.map { it.toInt() }
if (tagSplit == null || tagSplit.size < 2)
throw IllegalArgumentException("Tag doesn't match the version name pattern: $tag")