mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Re-add git.properties (#3287)
Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com>
This commit is contained in:
parent
9791e7b544
commit
c84d53c827
2 changed files with 62 additions and 13 deletions
|
@ -79,23 +79,65 @@ configurations.api {
|
||||||
exclude(group = "io.netty.incubator", module = "netty-incubator-transport-native-io_uring")
|
exclude(group = "io.netty.incubator", module = "netty-incubator-transport-native-io_uring")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.processResources {
|
||||||
|
// This is solely for backwards compatibility for other programs that used this file before the switch to gradle.
|
||||||
|
// It used to be generated by the maven Git-Commit-Id-Plugin
|
||||||
|
filesMatching("git.properties") {
|
||||||
|
val info = GitInfo()
|
||||||
|
expand(
|
||||||
|
"branch" to info.branch,
|
||||||
|
"buildNumber" to info.buildNumber,
|
||||||
|
"projectVersion" to project.version,
|
||||||
|
"commit" to info.commit,
|
||||||
|
"commitAbbrev" to info.commitAbbrev,
|
||||||
|
"commitMessage" to info.commitMessage,
|
||||||
|
"repository" to info.repository
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
configure<BlossomExtension> {
|
configure<BlossomExtension> {
|
||||||
val indra = the<IndraGitExtension>()
|
|
||||||
|
|
||||||
val mainFile = "src/main/java/org/geysermc/geyser/GeyserImpl.java"
|
val mainFile = "src/main/java/org/geysermc/geyser/GeyserImpl.java"
|
||||||
// On Jenkins, a detached head is checked out, so indra cannot determine the branch. Fortunately, this environment variable is available.
|
val info = GitInfo()
|
||||||
val branchName = indra.branchName() ?: System.getenv("BRANCH_NAME") ?: "DEV"
|
|
||||||
val commit = indra.commit()
|
|
||||||
val git = indra.git()
|
|
||||||
val gitVersion = "git-${branchName}-${commit?.name?.substring(0, 7) ?: "0000000"}"
|
|
||||||
|
|
||||||
replaceToken("\${version}", "${project.version} ($gitVersion)", mainFile)
|
replaceToken("\${version}", "${project.version} (${info.gitVersion})", mainFile)
|
||||||
replaceToken("\${gitVersion}", gitVersion, mainFile)
|
replaceToken("\${gitVersion}", info.gitVersion, mainFile)
|
||||||
replaceToken("\${buildNumber}", buildNumber(), mainFile)
|
replaceToken("\${buildNumber}", info.buildNumber, mainFile)
|
||||||
replaceToken("\${branch}", branchName, mainFile)
|
replaceToken("\${branch}", info.branch, mainFile)
|
||||||
if (commit != null && commit.name != null) replaceToken("\${commit}", commit.name, mainFile)
|
replaceToken("\${commit}", info.commit, mainFile)
|
||||||
if (git != null) replaceToken("\${repository}", git.repository.config.getString("remote", "origin", "url"))
|
replaceToken("\${repository}", info.repository, mainFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Project.buildNumber(): Int =
|
fun Project.buildNumber(): Int =
|
||||||
Integer.parseInt(System.getenv("BUILD_NUMBER") ?: "-1")
|
Integer.parseInt(System.getenv("BUILD_NUMBER") ?: "-1")
|
||||||
|
|
||||||
|
inner class GitInfo {
|
||||||
|
val branch: String
|
||||||
|
val commit: String
|
||||||
|
val commitAbbrev: String
|
||||||
|
|
||||||
|
val gitVersion: String
|
||||||
|
val version: String
|
||||||
|
val buildNumber: Int
|
||||||
|
|
||||||
|
val commitMessage: String
|
||||||
|
val repository: String
|
||||||
|
|
||||||
|
init {
|
||||||
|
// On Jenkins, a detached head is checked out, so indra cannot determine the branch.
|
||||||
|
// Fortunately, this environment variable is available.
|
||||||
|
branch = indraGit.branchName() ?: System.getenv("BRANCH_NAME") ?: "DEV"
|
||||||
|
|
||||||
|
val commit = indraGit.commit()
|
||||||
|
this.commit = commit?.name ?: "0".repeat(40)
|
||||||
|
commitAbbrev = commit?.name?.substring(0, 7) ?: "0".repeat(7)
|
||||||
|
|
||||||
|
gitVersion = "git-${branch}-${commitAbbrev}"
|
||||||
|
version = "${project.version} ($gitVersion)"
|
||||||
|
buildNumber = buildNumber()
|
||||||
|
|
||||||
|
val git = indraGit.git()
|
||||||
|
commitMessage = git?.commit()?.message ?: ""
|
||||||
|
repository = git?.repository?.config?.getString("remote", "origin", "url") ?: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
7
core/src/main/resources/git.properties
Normal file
7
core/src/main/resources/git.properties
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
git.branch=${branch}
|
||||||
|
git.build.number=${buildNumber}
|
||||||
|
git.build.version=${projectVersion}
|
||||||
|
git.commit.id=${commit}
|
||||||
|
git.commit.id.abbrev=${commitAbbrev}
|
||||||
|
git.commit.message.full=${commitMessage}
|
||||||
|
git.remote.origin.url=${repository}
|
Loading…
Reference in a new issue