mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-29 15:49:09 +01: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")
|
||||
}
|
||||
|
||||
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> {
|
||||
val indra = the<IndraGitExtension>()
|
||||
|
||||
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 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"}"
|
||||
val info = GitInfo()
|
||||
|
||||
replaceToken("\${version}", "${project.version} ($gitVersion)", mainFile)
|
||||
replaceToken("\${gitVersion}", gitVersion, mainFile)
|
||||
replaceToken("\${buildNumber}", buildNumber(), mainFile)
|
||||
replaceToken("\${branch}", branchName, mainFile)
|
||||
if (commit != null && commit.name != null) replaceToken("\${commit}", commit.name, mainFile)
|
||||
if (git != null) replaceToken("\${repository}", git.repository.config.getString("remote", "origin", "url"))
|
||||
replaceToken("\${version}", "${project.version} (${info.gitVersion})", mainFile)
|
||||
replaceToken("\${gitVersion}", info.gitVersion, mainFile)
|
||||
replaceToken("\${buildNumber}", info.buildNumber, mainFile)
|
||||
replaceToken("\${branch}", info.branch, mainFile)
|
||||
replaceToken("\${commit}", info.commit, mainFile)
|
||||
replaceToken("\${repository}", info.repository, mainFile)
|
||||
}
|
||||
|
||||
fun Project.buildNumber(): Int =
|
||||
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