Skip to content

Commit

Permalink
migrate to new sonatype publishing workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Jul 5, 2024
1 parent 21053a1 commit 0563193
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 191 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ jobs:
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Create local properties
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > local.properties

- name: set up JDK
uses: actions/setup-java@v4
with:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ jobs:
- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v3

- name: Create local properties
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > local.properties

- name: Update docs/README.md
run: cp ./README.md ./docs/README.md

Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,14 @@ jobs:
with:
xcode-version: latest

- name: Create local properties
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > local.properties

- name: Publish to sonatype
env:
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
# It's important to not upload in parallel or duplicate repos will be created
# repository creds are broken with gradle 8.6 https://github.com/gradle/gradle/issues/24040
run: ./gradlew publishAllPublicationsToSonatypeRepository -Dorg.gradle.parallel=false --stacktrace --no-configuration-cache
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache

- name: Generate Changelog
uses: mikepenz/release-changelog-builder-action@v4
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Config {
const val licenseName = "The Apache Software License, Version 2.0"
const val licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0.txt"
const val scmUrl = "https://github.com/respawn-app/ApiResult.git"
const val name = "ApiResult"
const val description = """
ApiResult is a Kotlin Multiplatform declarative error handling framework that is performant, easy to use and
feature-rich.
Expand Down
73 changes: 0 additions & 73 deletions buildSrc/src/main/kotlin/ConfigurePublication.kt

This file was deleted.

91 changes: 0 additions & 91 deletions buildSrc/src/main/kotlin/PublishingExt.kt

This file was deleted.

10 changes: 8 additions & 2 deletions buildSrc/src/main/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ fun String.toBase64() = Base64.getEncoder().encodeToString(toByteArray())

fun Project.localProperties() = Properties().apply {
val file = File(rootProject.rootDir.absolutePath, "local.properties")
require(file.exists()) { "Please create root local.properties file" }
load(FileInputStream(file))
if (file.exists()) {
load(FileInputStream(file))
}
}

fun stabilityLevel(version: String): Int {
Expand All @@ -62,3 +63,8 @@ fun stabilityLevel(version: String): Int {
}
return Config.stabilityLevels.size
}

fun Config.version(isRelease: Boolean) = buildString {
append(versionName)
if (!isRelease) append("-SNAPSHOT")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
plugins {
kotlin("multiplatform")
id("com.android.library")
id("maven-publish")
signing
}

Expand All @@ -17,5 +16,3 @@ kotlin {
android {
configureAndroidLibrary(this)
}

publishMultiplatform()
36 changes: 36 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id("pro.respawn.shared-library")
alias(libs.plugins.maven.publish)
}

android {
Expand All @@ -10,3 +13,36 @@ dependencies {
commonMainApi(libs.kotlin.coroutines.core)
jvmTestImplementation(libs.bundles.unittest)
}

mavenPublishing {
val properties = localProperties()
val isReleaseBuild = properties["release"]?.toString().toBoolean()
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, false)
signAllPublications()
coordinates(Config.group, Config.artifact, Config.version(isReleaseBuild))
pom {
name = Config.name
description = Config.description
url = Config.url
licenses {
license {
name = Config.licenseName
url = Config.licenseUrl
distribution = Config.licenseUrl
}
}
developers {
developer {
id = Config.vendorId
name = Config.vendorName
url = Config.developerUrl
email = Config.supportEmail
organizationUrl = Config.developerUrl
}
}
scm {
url = Config.scmUrl
}

}
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ kotlinx-atomicfu = "0.23.1"
lifecycle = "2.8.2"
turbine = "1.0.0"
versionCatalogUpdatePlugin = "0.8.4"
maven-publish-plugin = "0.29.0"

[libraries]
android-gradle = { module = "com.android.tools.build:gradle", version.ref = "gradleAndroid" }
Expand Down Expand Up @@ -58,6 +59,7 @@ unittest = [
]

[plugins]
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publish-plugin" }
atomicfu = { id = "kotlinx-atomicfu", version.ref = "kotlinx-atomicfu" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
dependencyAnalysis = { id = "com.autonomousapps.dependency-analysis", version.ref = "dependencyAnalysisPlugin" }
Expand Down

0 comments on commit 0563193

Please sign in to comment.