Skip to content

Commit ccf1645

Browse files
committed
include git branch in alpha builds
1 parent 05a0fe8 commit ccf1645

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

build.gradle.kts

+20-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ allprojects {
7272
// example: 1.0.0+fabric-1.19.2-build.100 (or -local)
7373
val build = buildNumber?.let { "-build.${it}" } ?: "-local"
7474

75-
version = "${"mod_version"()}+${project.name}-mc${"minecraft_version"() + if (isRelease) "" else build}"
75+
var gitBranchLabel = "";
76+
if ("mod_version"().endsWith("-alpha")) {
77+
// gitBranchLabel should be "-" + the current git branch (replacing any slashes with underscores)
78+
gitBranchLabel = "-" + calculateGitBranch().replace("/", "_")
79+
}
80+
81+
version = "${"mod_version"()}${gitBranchLabel}+${project.name}-mc${"minecraft_version"() + if (isRelease) "" else build}"
7682

7783
tasks.withType<JavaCompile>().configureEach {
7884
options.encoding = "UTF-8"
@@ -385,6 +391,19 @@ fun calculateGitHash(): String {
385391
}
386392
}
387393

394+
fun calculateGitBranch(): String {
395+
try {
396+
val stdout = ByteArrayOutputStream()
397+
exec {
398+
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
399+
standardOutput = stdout
400+
}
401+
return stdout.toString().trim()
402+
} catch(ignored: Throwable) {
403+
return "unknown"
404+
}
405+
}
406+
388407
fun hasUnstaged(): Boolean {
389408
try {
390409
val stdout = ByteArrayOutputStream()

0 commit comments

Comments
 (0)