Skip to content

Commit

Permalink
Add Sonatype publishing (#154)
Browse files Browse the repository at this point in the history
* Don't infer version from CI env

* Add sonatype publishing
  • Loading branch information
BartArys authored Jan 5, 2021
1 parent df707f1 commit a19423f
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 90 deletions.
78 changes: 65 additions & 13 deletions .github/workflows/deployment-ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,81 @@
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java#publishing-using-gradle
# This workflow will build a package using Gradle and then publish it to maven

name: Kotlin CI

name: Deployment
on:
release:
types: [created]
push:
paths:
- '**.gradle'
- '**.properties'
- '**/src/**'
branches:
- 'master'
- '0.7.x'
- '0.8.x'
tags-ignore:
- '*.*'
pull_request:
paths:
- '**.gradle'
- '**.properties'
- '**/src/**'
types: [ opened, synchronize, reopened ]

jobs:
deploy:
build:
name: Build Kord
runs-on: ubuntu-latest
env:
KORD_TEST_TOKEN: ${{ secrets.KORD_TEST_TOKEN }}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8
- name: Build with Gradle
run: ./gradlew --stacktrace --info build
if: |
!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.pull_request.title, '[ci skip]')
release:
name: Publish artifacts
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs: build
env:
KORD_TEST_TOKEN: ${{ secrets.KORD_TEST_TOKEN }}
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
NEXUS_USER: ${{ secrets.NEXUS_USER }}
NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

steps:
- uses: actions/checkout@v2
- run: echo "name=RELEASE_TAG::${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Set up JDK 1.8
with:
fetch-depth: 0
- uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Build with Gradle
run: gradle --stacktrace --info bintrayUpload
java-version: 8
- name: Publish with Gradle
run: ./gradlew -x test publish
# Disabled for now
#
# - name: Close and Release Repository
# run: ./gradlew closeAndReleaseRepository
8 changes: 4 additions & 4 deletions .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ on:

jobs:
upload_docs:
name: upload docs
name: update docs docs
runs-on: ubuntu-latest
env:
GRGIT_USER: ${{ secrets.GRGIT_USER }}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 8

- name: Publish docs with Gradle
run: gradle --stacktrace --info gitPublishPush
run: ./gradlew --stacktrace --info gitPublishPush
61 changes: 0 additions & 61 deletions .github/workflows/github-ci.yml

This file was deleted.

92 changes: 86 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ buildscript {

classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}")
classpath("com.jfrog.bintray.gradle:gradle-bintray-plugin:${Versions.bintray}")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.atomicFu}")
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:${Versions.binaryCompatibilityValidator}")
}
Expand All @@ -24,12 +23,16 @@ plugins {
id("org.jetbrains.kotlin.jvm") version Versions.kotlin
id("org.jetbrains.dokka") version "1.4.0"
id("org.ajoberstar.git-publish") version "2.1.3"
id("com.jfrog.bintray") version "1.8.5"

signing
`maven-publish`
id("io.codearte.nexus-staging") version "0.22.0"
}

apply(plugin = "binary-compatibility-validator")

repositories {
maven(url = "https://dl.bintray.com/kotlin/kotlin-dev/")
mavenCentral()
jcenter()
mavenLocal()
Expand All @@ -50,6 +53,7 @@ subprojects {
apply(plugin = "maven-publish")
apply(plugin = "kotlinx-atomicfu")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "signing")

repositories {
mavenCentral()
Expand All @@ -76,7 +80,7 @@ subprojects {
testRuntimeOnly(Dependencies.sl4j)
}

tasks.getByName("apiCheck").onlyIf { Library.stableApi }
tasks.getByName("apiCheck").onlyIf { Library.isStableApi }

val compileKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
compileKotlin.kotlinOptions.jvmTarget = Jvm.target
Expand Down Expand Up @@ -114,25 +118,99 @@ subprojects {
from(sourceSets.main.get().allSource)
}

val dokkaJar by tasks.registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml)
dependsOn(tasks.dokkaHtml)
}

apply<BintrayPlugin>()

configure<PublishingExtension> {
publishing {
publications {
register("kord", MavenPublication::class) {
create<MavenPublication>(Library.name) {
from(components["kotlin"])
groupId = Library.group
artifactId = "kord-${project.name}"
version = Library.version

artifact(sourcesJar.get())
artifact(dokkaJar.get())

pom {
name.set(Library.name)
description.set(Library.description)
url.set(Library.description)

organization {
name.set("Kord")
url.set("https://github.com/kordlib")
}

developers {
developer {
name.set("The Kord Team")
}
}

issueManagement {
system.set("GitHub")
url.set("https://github.com/kordlib/kord/issues")
}

withXml {
val repoNode = asNode().appendNode("repositories").appendNode("repository")

with(repoNode) {
appendNode("id", "jcenter")
appendNode("name", "jcenter-bintray")
appendNode("url", "https://jcenter.bintray.com")
}
}
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
}
}
scm {
connection.set("scm:git:ssh://github.com/kordlib/kord.git")
developerConnection.set("scm:git:ssh://[email protected]:kordlib/kord.git")
url.set(Library.projectUrl)
}
}

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

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

}
}

}

if (!isJitPack) {
signing {
sign(publishing.publications[Library.name])
}
}

configure<BintrayExtension> {
user = System.getenv("BINTRAY_USER")
key = System.getenv("BINTRAY_KEY")
setPublications("kord")
setPublications(Library.name)
publish = true

pkg = PackageConfig().apply {
Expand Down Expand Up @@ -188,3 +266,5 @@ configure<GitPublishExtension> {

commitMessage.set("Update Docs")
}

nexusStaging { }
26 changes: 20 additions & 6 deletions buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,31 @@ val DependencyHandlerScope.rest get() = project(":rest")
val DependencyHandlerScope.gateway get() = project(":gateway")
val DependencyHandlerScope.core get() = project(":core")


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

object Library {
private const val releaseVersion = "0.7.0-SNAPSHOT"
val isSnapshot: Boolean get() = releaseVersion.endsWith("-SNAPSHOT")

const val name = "kord"
const val group = "dev.kord"
val version = System.getenv("RELEASE_TAG") ?: System.getenv("GITHUB_SHA") ?: "undefined"
val version: String = if (isJitPack) System.getenv("RELEASE_TAG")
else releaseVersion

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

/**
* Whether the current API is considered stable, and should be compared to the 'golden' API dump.
*
* Settings this flag to `false` disables the `apiCheck` tasks that compares binary compatibility.
* Whenever a new development cycle starts, this flag should be set to `false`, and set to
* `true` together with a new API dump whenever that cycle ends.
*/
const val stableApi: Boolean = false
val isStableApi: Boolean get() = !isSnapshot
}

object Repo {
const val releasesUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
const val snapshotsUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
}

0 comments on commit a19423f

Please sign in to comment.