Skip to content

Commit

Permalink
Fully switch to grgit
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Apr 25, 2023
1 parent b2119b2 commit e945daf
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 33 deletions.
1 change: 0 additions & 1 deletion .teamcity/Shared.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ fun KordBuild(name: String, configure: BuildType.() -> Unit) = object : BuildTyp

params {
checkbox(debugParamName, false.toString(), "Debug Mode", "Run build with debug logging enabled")
param("env.GITHUB_BRANCH_NAME", "%teamcity.build.branch%")
password("env.KORD_TEST_TOKEN", "credentialsJSON:6f4d984c-83d2-4914-8dea-dc0ed996d81d")
password("env.NEXUS_USER", "credentialsJSON:8e4c071b-df9d-4701-b8df-85058c1bf7ef")
password("env.NEXUS_PASSWORD", "credentialsJSON:69d63bf7-8064-4062-a01b-96aa50fdc890")
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ repositories {
}

group = Library.group
version = Library.version
version = kordVersion
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Documentation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fun AbstractDokkaLeafTask.applyKordDokkaOptions() {

sourceLink {
localDirectory = project.projectDir
remoteUrl = URL("https://github.com/kordlib/kord/blob/${Library.commitHash}/${project.name}")
remoteUrl = URL("https://github.com/kordlib/kord/blob/${project.commitHash}/${project.name}")
remoteLineSuffix = "#L"
}

Expand Down
54 changes: 31 additions & 23 deletions buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
import org.ajoberstar.grgit.Grgit
import org.gradle.api.Project

/**
* whether the process has been invoked by JitPack
*/
val isJitPack get() = "true" == System.getenv("JITPACK")

private
private var grgit: Grgit? = null
private val Project.git: Grgit
get() {
return grgit ?: Grgit.open {
dir = rootProject.rootDir.absolutePath
}.also {
grgit = it
}
}

object Library {
private val git = Grgit.open()
private val head = git.head()
const val name = "kord"
const val group = "dev.kord"

val version: String
get() = if (isJitPack) System.getenv("RELEASE_TAG")
else {
val tag = git.tag.list().firstOrNull {
it.commit == head
}
val branch = git.branch.current().name
when {
tag != null -> tag.name
!branch.isNullOrBlank() -> branch.replace("/", "-") + "-SNAPSHOT"
else -> "undefined"
}
const val description = "Idiomatic Kotlin Wrapper for The Discord API"
const val projectUrl = "https://github.com/kordlib/kord"
}

val Project.kordVersion: String
get() = if (isJitPack) System.getenv("RELEASE_TAG")
else {
val head = git.head()
val tag = git.tag.list().firstOrNull {
it.commit == head
}
val branch = git.branch.current().name
when {
tag != null -> tag.name
!branch.isNullOrBlank() -> branch.replace("/", "-") + "-SNAPSHOT"
else -> "undefined"
}

val commitHash get() = head.id
}

val shortCommitHash get() = head.abbreviatedId
val Project.commitHash get() = git.head().id

const val description = "Idiomatic Kotlin Wrapper for The Discord API"
const val projectUrl = "https://github.com/kordlib/kord"
val Project.shortCommitHash get() = git.head().abbreviatedId

val isSnapshot: Boolean get() = version.endsWith("-SNAPSHOT")
val Project.isSnapshot: Boolean get() = kordVersion.endsWith("-SNAPSHOT")

val isRelease: Boolean get() = !isSnapshot && !isUndefined
val Project.isRelease: Boolean get() = !isSnapshot && !isUndefined

val isUndefined get() = version == "undefined"
}
val Project.isUndefined get() = version == "undefined"

object Repo {
const val releasesUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tasks {
}

withType<PublishToMavenRepository>().configureEach {
doFirst { require(!Library.isUndefined) { "No release/snapshot version found." } }
doFirst { require(!isUndefined) { "No release/snapshot version found." } }
}
}

Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/kord-publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ publishing {

groupId = Library.group
artifactId = "kord-$artifactId"
version = Library.version
version = kordVersion

pom {
name = Library.name
Expand Down Expand Up @@ -61,7 +61,7 @@ publishing {
if (!isJitPack) {
repositories {
maven {
url = uri(if (Library.isSnapshot) Repo.snapshotsUrl else Repo.releasesUrl)
url = uri(if (isSnapshot) Repo.snapshotsUrl else Repo.releasesUrl)

credentials {
username = System.getenv("NEXUS_USER")
Expand All @@ -72,7 +72,7 @@ publishing {
}
}

if (!isJitPack && Library.isRelease) {
if (!isJitPack && isRelease) {
signing {
val signingKey = findProperty("signingKey")?.toString()
val signingPassword = findProperty("signingPassword")?.toString()
Expand Down
6 changes: 3 additions & 3 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ buildConfig {
internalVisibility = true
}

buildConfigField("String", "BUILD_CONFIG_GENERATED_LIBRARY_VERSION", "\"${Library.version}\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_COMMIT_HASH", "\"${Library.commitHash}\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH", "\"${Library.shortCommitHash}\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_LIBRARY_VERSION", "\"${kordVersion}\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_COMMIT_HASH", "\"${commitHash}\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH", "\"${shortCommitHash}\"")
}

0 comments on commit e945daf

Please sign in to comment.