Skip to content

Commit

Permalink
:Version is now taken from a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
romanowski committed Sep 11, 2020
1 parent 4fffcc6 commit 1a74cc4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Fetch tags and full project history
- run: |
git fetch --prune --unshallow --tags
git describe --tags
- name: Set Up JDK 1.8
uses: actions/setup-java@v1.4.0
with:
Expand Down
29 changes: 28 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.BufferedInputStream
import java.io.BufferedReader
import java.io.ByteArrayOutputStream
import java.io.InputStreamReader
import kotlin.collections.toByteArray

plugins {
kotlin("jvm")
Expand All @@ -9,7 +14,29 @@ plugins {
}

group = "com.virtuslab.dokka"
version = "0.1.3"


fun String.run(): String? {
val proc = Runtime.getRuntime()?.exec(this)
if (proc?.waitFor() != 0) return null
val os = proc.inputStream
return os.let {
val line = BufferedReader(InputStreamReader(it)).readLines().joinToString("\n")
os.close()
return line.trim()
}
}

fun getVersion(): String {
val base = "git describe --tags --exact-match".run() ?: "git describe --tags".run() ?: "0.1.0-SNAPSHOT"

val statusStr = "git status --porcelain".run()?.let { if (it.trim().length > 2) "-SNAPSHOT" else "" } ?: "-SNAPSHOT"
val v = base + statusStr
println("Using $v version.")
return v
}

version = getVersion()

tasks.withType(KotlinCompile::class).all {
val language_version: String by project
Expand Down

0 comments on commit 1a74cc4

Please sign in to comment.