mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Include git metadata in manifest, commit hash in snapshot platform versions
This commit is contained in:
2 files changed
+37
-1
No files matched your search
@@ -3,6 +3,8 @@ plugins {
|
|||||||
id("com.modrinth.minotaur")
|
id("com.modrinth.minotaur")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decorateVersion()
|
||||||
|
|
||||||
val runtimeDownload: Configuration by configurations.creating {
|
val runtimeDownload: Configuration by configurations.creating {
|
||||||
isCanBeResolved = true
|
isCanBeResolved = true
|
||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
@@ -41,6 +43,15 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
"carbon-version" to project.version,
|
||||||
|
"carbon-commit" to lastCommitHash(),
|
||||||
|
"carbon-branch" to currentBranch(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
val copyJar = register<FileCopyTask>("copyJar") {
|
val copyJar = register<FileCopyTask>("copyJar") {
|
||||||
fileToCopy.set(platformExtension.jarTask.flatMap { it.archiveFile })
|
fileToCopy.set(platformExtension.jarTask.flatMap { it.archiveFile })
|
||||||
destination.set(rootProject.layout.buildDirectory.dir("libs").flatMap {
|
destination.set(rootProject.layout.buildDirectory.dir("libs").flatMap {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
import net.kyori.indra.git.IndraGitExtension
|
import net.kyori.indra.git.IndraGitExtension
|
||||||
import org.apache.tools.ant.filters.ReplaceTokens
|
import org.apache.tools.ant.filters.ReplaceTokens
|
||||||
|
import org.eclipse.jgit.lib.Repository
|
||||||
import org.gradle.accessors.dm.LibrariesForLibs
|
import org.gradle.accessors.dm.LibrariesForLibs
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
@@ -108,8 +109,32 @@ fun ShadowJar.configureShadowJar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Project.latestGitHash(): String? =
|
fun Project.lastCommitHash(): String =
|
||||||
the<IndraGitExtension>().commit()?.name?.substring(0, 7)
|
the<IndraGitExtension>().commit()?.name?.substring(0, 7)
|
||||||
|
?: error("Could not determine commit hash")
|
||||||
|
|
||||||
|
fun Project.decorateVersion() {
|
||||||
|
val versionString = version as String
|
||||||
|
version = if (versionString.endsWith("-SNAPSHOT")) {
|
||||||
|
"$versionString+${lastCommitHash()}"
|
||||||
|
} else {
|
||||||
|
versionString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Project.currentBranch(): String {
|
||||||
|
System.getenv("GITHUB_HEAD_REF")?.takeIf { it.isNotEmpty() }
|
||||||
|
?.let { return it }
|
||||||
|
System.getenv("GITHUB_REF")?.takeIf { it.isNotEmpty() }
|
||||||
|
?.let { return it.replaceFirst("refs/heads/", "") }
|
||||||
|
|
||||||
|
val indraGit = the<IndraGitExtension>().takeIf { it.isPresent }
|
||||||
|
|
||||||
|
val ref = indraGit?.git()?.repository?.exactRef("HEAD")?.target
|
||||||
|
?: return "detached-head"
|
||||||
|
|
||||||
|
return Repository.shortenRefName(ref.name)
|
||||||
|
}
|
||||||
|
|
||||||
val Project.libs: LibrariesForLibs
|
val Project.libs: LibrariesForLibs
|
||||||
get() = the()
|
get() = the()
|
||||||
Reference in new issue
Block a user