Skip to content

Commit

Permalink
Fix release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jGleitz committed Jan 12, 2020
1 parent 793ccef commit 1c0327d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 13
java-version: 8
- name: Prepare
run: ./gradlew clean dependencies
- name: Assemble
Expand All @@ -63,10 +63,10 @@ jobs:
PUBLISH_DIR: ./build/dokka
with:
emptyCommits: false
- name: Publish Snapshot JAR
run: ./gradlew publish
- name: Publish Snapshot Artifacts
run: ./gradlew publishSnapshot
env:
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
ORG_GRADLE_PROJECT_githubToken: ${{ github.token }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PACKAGE_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.PACKAGE_SIGNING_KEY_PASSWORD }}
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
ORG_GRADLE_PROJECT_githubToken: ${{ github.token }}
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Java CI
name: Release

on:
release:
Expand All @@ -18,16 +18,17 @@ jobs:
restore-keys: |
gradle-${{ runner.os }}
gradle-
- name: Set up JDK 13
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 13
java-version: 8
- name: Prepare
run: ./gradlew clean dependencies
- name: Release to Maven Central
run: ./gradlew release
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PACKAGE_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.PACKAGE_SIGNING_KEY_PASSWORD }}
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrtes.OSSRH_PASSWORD }}
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }}
64 changes: 42 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import de.marcphilipp.gradle.nexus.NexusRepository

plugins {
kotlin("jvm").version("1.3.61")
id("org.jetbrains.dokka") version "0.10.0"
`maven-publish`
signing
id("de.marcphilipp.nexus-publish") version "0.4.0"
id("io.codearte.nexus-staging") version "0.21.2"
id("com.palantir.git-version") version "0.12.2"
idea
}

group = "de.joshuagleitze"
version = project.findProperty("releaseVersion") ?: "SNAPSHOT"
version = if (isSnapshot) versionDetails.gitHash else versionDetails.lastTag.drop("v")
status = if (isSnapshot) "snapshot" else "release"

repositories {
jcenter()
Expand Down Expand Up @@ -74,6 +78,8 @@ artifacts {
}

lateinit var publication: MavenPublication
lateinit var snapshotRepository: ArtifactRepository
lateinit var releaseRepository: NexusRepository

publishing {
publications {
Expand Down Expand Up @@ -117,26 +123,25 @@ publishing {
}
}
repositories {
if (project.isSnapshot) {
maven("https://maven.pkg.github.com/$githubRepository") {
name = "GitHub-Packages"
credentials {
username = githubOwner
password = githubToken
}
}
} else {
maven("https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
name = "OSSRH-Staging"
credentials {
username = ossrhUsername
password = ossrhPassword
}
snapshotRepository = maven("https://maven.pkg.github.com/$githubRepository") {
name = "GitHubPackages"
credentials {
username = githubOwner
password = githubToken
}
}
}
}

nexusPublishing {
repositories {
releaseRepository = sonatype {
username.set(ossrhUsername)
password.set(ossrhPassword)
}
}
}

signing {
val signingKey: String? by project
val signingKeyPassword: String? by project
Expand All @@ -149,15 +154,21 @@ nexusStaging {
password = ossrhPassword
}

val closeAndPromoteRepository by project.tasks
val closeAndReleaseRepository by project.tasks
val publish by tasks

task("publishSnapshot") {
group = "publishing"
description = "Publishes a snapshot of the project to GitHub Packages"
dependsOn(snapshotRepository.publishTask)
}

task("release") {
group = "release"
description = "Publishes the project to Maven Central"
dependsOn(publish)
dependsOn(closeAndPromoteRepository)
closeAndPromoteRepository.mustRunAfter(publish)
description = "Releases the project to Maven Central"
dependsOn(releaseRepository.publishTask)
dependsOn(closeAndReleaseRepository)
closeAndReleaseRepository.mustRunAfter(releaseRepository.publishTask)
}

idea {
Expand All @@ -167,4 +178,13 @@ idea {
}
}

val Project.isSnapshot get() = this.version == "SNAPSHOT"
val Project.isSnapshot get() = versionDetails.commitDistance != 0

fun String.drop(prefix: String) = if (this.startsWith(prefix)) this.drop(prefix.length) else this

val Project.versionDetails
get() = (this.extra["versionDetails"] as groovy.lang.Closure<*>)() as com.palantir.gradle.gitversion.VersionDetails


val ArtifactRepository.publishTask get() = tasks["publishAllPublicationsTo${this.name}Repository"]
val NexusRepository.publishTask get() = tasks["publishTo${this.name.capitalize()}"]

0 comments on commit 1c0327d

Please sign in to comment.