aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/BuildUtils.kt
blob: c9a2f285051a3301e2b0fb486469094da4f96ef9 (plain)
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
package com.pitchedapps.frost.utils

object BuildUtils {

    data class Data(val versionName: String, val tail: String)

    // Builds
    private const val BUILD_PRODUCTION = "production"
    private const val BUILD_TEST = "releaseTest"
    private const val BUILD_GITHUB = "github"
    private const val BUILD_RELEASE = "release"
    private const val BUILD_UNNAMED = "unnamed"

    fun match(version: String): Data? {
        val regex = Regex("([0-9]+\\.[0-9]+\\.[0-9]+)-?(.*?)")
        val result = regex.matchEntire(version)?.groupValues ?: return null
        return Data(result[1], result[2])
    }

    fun getAllStages(): Array<String> =
            arrayOf(BUILD_PRODUCTION, BUILD_TEST, BUILD_GITHUB, BUILD_RELEASE, BUILD_UNNAMED)

    fun getStage(build: String): String = build.takeIf { it in getAllStages() } ?: BUILD_UNNAMED

}