Skip to content

Commit

Permalink
include git branch in alpha builds
Browse files Browse the repository at this point in the history
  • Loading branch information
techno-sam committed Jan 4, 2025
1 parent 05a0fe8 commit ccf1645
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ allprojects {
// example: 1.0.0+fabric-1.19.2-build.100 (or -local)
val build = buildNumber?.let { "-build.${it}" } ?: "-local"

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

version = "${"mod_version"()}${gitBranchLabel}+${project.name}-mc${"minecraft_version"() + if (isRelease) "" else build}"

tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
Expand Down Expand Up @@ -385,6 +391,19 @@ fun calculateGitHash(): String {
}
}

fun calculateGitBranch(): String {
try {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
standardOutput = stdout
}
return stdout.toString().trim()
} catch(ignored: Throwable) {
return "unknown"
}
}

fun hasUnstaged(): Boolean {
try {
val stdout = ByteArrayOutputStream()
Expand Down

0 comments on commit ccf1645

Please sign in to comment.