Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CI #823

Merged
merged 6 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/deployment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
with:
distribution: temurin
java-version: 8
- name: Set SHORT_SHA environment variable to short commit hash
run: echo "SHORT_SHA=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
Expand All @@ -44,10 +42,8 @@ jobs:
KORD_TEST_TOKEN: ${{ secrets.KORD_TEST_TOKEN }}
NEXUS_USER: ${{ secrets.NEXUS_USER }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.signingKey }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.signingPassword }}
GITHUB_TAG_NAME: ${{ github.event.release.tag_name }}
GITHUB_BRANCH_NAME: ${{ github.ref }}
SIGNING_KEY: ${{ secrets.signingKey }}
SIGNING_PASSWORD: ${{ secrets.signingPassword }}
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -57,8 +53,6 @@ jobs:
with:
distribution: temurin
java-version: 8
- name: Set SHORT_SHA environment variable to short commit hash
run: echo "SHORT_SHA=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
concurrency: # Allow one concurrent deployment
group: pages
cancel-in-progress: true
env:
GITHUB_TAG_NAME: ${{ github.event.release.tag_name }}
GITHUB_BRANCH_NAME: ${{ github.ref }}
steps:
- uses: actions/checkout@v3
- name: Set up JDK
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 = libraryVersion
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.commitHashOrDefault("0.9.x")}/${project.name}")
remoteUrl = URL("https://github.com/kordlib/kord/blob/${project.commitHash}/${project.name}")
remoteLineSuffix = "#L"
}

Expand Down
13 changes: 13 additions & 0 deletions buildSrc/src/main/kotlin/Git.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import org.gradle.api.Project
import java.io.ByteArrayOutputStream

internal fun Project.git(vararg command: String): String {
val output = ByteArrayOutputStream()
exec {
commandLine("git", *command)
standardOutput = output
errorOutput = output
workingDir = rootDir
}.rethrowFailure().assertNormalExitValue()
return output.toString().trim()
}
40 changes: 12 additions & 28 deletions buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
/**
* whether the process has been invoked by JitPack
*/
val isJitPack get() = "true" == System.getenv("JITPACK")
import org.gradle.api.Project

object Library {
const val name = "kord"
const val group = "dev.kord"
val version: String
get() = if (isJitPack) System.getenv("RELEASE_TAG")
else {
val tag = System.getenv("GITHUB_TAG_NAME")
val branch = System.getenv("GITHUB_BRANCH_NAME")
when {
!tag.isNullOrBlank() -> tag
!branch.isNullOrBlank() && branch.startsWith("refs/heads/") ->
branch.substringAfter("refs/heads/").replace("/", "-") + "-SNAPSHOT"
else -> "undefined"
}

}

val commitHash get() = System.getenv("GITHUB_SHA") ?: "unknown"
fun commitHashOrDefault(default: String) = System.getenv("GITHUB_SHA") ?: default

// this environment variable isn't available out of the box, we set it ourselves
val shortCommitHash get() = System.getenv("SHORT_SHA") ?: "unknown"

const val description = "Idiomatic Kotlin Wrapper for The Discord API"
const val projectUrl = "https://github.com/kordlib/kord"
}

val isSnapshot: Boolean get() = version.endsWith("-SNAPSHOT")
private val Project.tag
get() = git("tag", "--no-column", "--points-at", "HEAD")
.takeIf { it.isNotBlank() }
?.lines()
?.single()

val isRelease: Boolean get() = !isSnapshot && !isUndefined
val Project.libraryVersion get() = tag ?: "${git("branch", "--show-current").replace('/', '-')}-SNAPSHOT"

val isUndefined get() = version == "undefined"
}
val Project.commitHash get() = git("rev-parse", "--verify", "HEAD")
val Project.shortCommitHash get() = git("rev-parse", "--short", "HEAD")

val Project.isRelease get() = tag != null

object Repo {
const val releasesUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
Expand Down
4 changes: 0 additions & 4 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ tasks {
withType<AbstractDokkaLeafTask>().configureEach {
applyKordDokkaOptions()
}

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

publishing {
Expand Down
27 changes: 12 additions & 15 deletions buildSrc/src/main/kotlin/kord-publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.lang.System.getenv
import java.util.Base64

plugins {
Expand All @@ -19,7 +20,7 @@ publishing {

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

pom {
name = Library.name
Expand Down Expand Up @@ -58,27 +59,23 @@ publishing {
}
}

if (!isJitPack) {
repositories {
maven {
url = uri(if (Library.isSnapshot) Repo.snapshotsUrl else Repo.releasesUrl)
repositories {
maven {
url = uri(if (isRelease) Repo.releasesUrl else Repo.snapshotsUrl)

credentials {
username = System.getenv("NEXUS_USER")
password = System.getenv("NEXUS_PASSWORD")
}
credentials {
username = getenv("NEXUS_USER")
password = getenv("NEXUS_PASSWORD")
}
}
}
}

if (!isJitPack && Library.isRelease) {
if (isRelease) {
signing {
val signingKey = findProperty("signingKey")?.toString()
val signingPassword = findProperty("signingPassword")?.toString()
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(String(Base64.getDecoder().decode(signingKey)), signingPassword)
}
val secretKey = String(Base64.getDecoder().decode(getenv("SIGNING_KEY")))
val password = getenv("SIGNING_PASSWORD")
useInMemoryPgpKeys(secretKey, password)
sign(publishing.publications)
}
}
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", "\"$libraryVersion\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_COMMIT_HASH", "\"$commitHash\"")
buildConfigField("String", "BUILD_CONFIG_GENERATED_SHORT_COMMIT_HASH", "\"$shortCommitHash\"")
}