Re-add git.properties (#3287)

Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com>
This commit is contained in:
Konicai 2022-09-19 11:22:09 -04:00 committed by GitHub
parent 9791e7b544
commit c84d53c827
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 13 deletions

View file

@ -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") ?: ""
}
}

View 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}