Skip to content

Commit

Permalink
Merge pull request #59 from hotwired/sonatype-publishing
Browse files Browse the repository at this point in the history
Add Sonatype (Maven Central) publishing support
  • Loading branch information
jayohms authored Sep 25, 2024
2 parents 897c258 + dd9feaa commit 6324ddc
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 12 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/sonatype.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish to Sonatype

on:
release:
types: [released]

jobs:
publish-release:
runs-on: ubuntu-latest
steps:
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Checkout code
uses: actions/checkout@v3

- name: Publish artifact to Sonatype
env:
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }}
run: ./gradlew -Psonatype -Pversion=${{ github.event.release.tag_name }} clean build -x test publish
50 changes: 44 additions & 6 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.serialization")
id("maven-publish")
id("signing")
}

val libVersionName by extra(version as String)
Expand All @@ -21,6 +22,8 @@ val licenseUrl by extra("https://github.com/hotwired/hotwire-native-android/blob
val developerId by extra("basecamp")
val developerEmail by extra("androidteam@basecamp.com")

val isSonatypeRelease by extra(project.hasProperty("sonatype"))

android {
namespace = "dev.hotwire.core"
compileSdk = 34
Expand Down Expand Up @@ -112,9 +115,33 @@ dependencies {
testImplementation("junit:junit:4.13.2")
}

tasks {
// Only sign Sonatype release artifacts
withType<Sign>().configureEach {
onlyIf { isSonatypeRelease }
}
}

// Sign Sonatype published release artifacts
if (isSonatypeRelease) {
signing {
val keyId = System.getenv("GPG_KEY_ID")
val secretKey = System.getenv("GPG_SECRET_KEY")
val password = System.getenv("GPG_PASSWORD")

useInMemoryPgpKeys(keyId, secretKey, password)

setRequired({ gradle.taskGraph.hasTask("publish") })
sign(publishing.publications)
}
}

// Publish to GitHub Packages via:
// ./gradlew -Pversion=<version> clean build publish
// https://github.com/orgs/hotwired/packages?repo_name=hotwire-native-android
// Publish to Maven Central via:
// ./gradlew -Psonatype -Pversion=<version> clean build publish
// https://search.maven.org/artifact/dev.hotwire/core
publishing {
publications {
register<MavenPublication>("release") {
Expand Down Expand Up @@ -152,13 +179,24 @@ publishing {
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/hotwired/hotwire-native-android")
if (isSonatypeRelease) {
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/releases/")

credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
credentials {
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
} else {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/hotwired/hotwire-native-android")

credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
Expand Down
50 changes: 44 additions & 6 deletions navigation-fragments/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("maven-publish")
id("signing")
}

val libVersionName by extra(version as String)
Expand All @@ -20,6 +21,8 @@ val licenseUrl by extra("https://github.com/hotwired/hotwire-native-android/blob
val developerId by extra("basecamp")
val developerEmail by extra("androidteam@basecamp.com")

val isSonatypeRelease by extra(project.hasProperty("sonatype"))

android {
namespace = "dev.hotwire.navigation"
compileSdk = 34
Expand Down Expand Up @@ -104,9 +107,33 @@ dependencies {
testImplementation("junit:junit:4.13.2")
}

tasks {
// Only sign Sonatype release artifacts
withType<Sign>().configureEach {
onlyIf { isSonatypeRelease }
}
}

// Sign Sonatype published release artifacts
if (isSonatypeRelease) {
signing {
val keyId = System.getenv("GPG_KEY_ID")
val secretKey = System.getenv("GPG_SECRET_KEY")
val password = System.getenv("GPG_PASSWORD")

useInMemoryPgpKeys(keyId, secretKey, password)

setRequired({ gradle.taskGraph.hasTask("publish") })
sign(publishing.publications)
}
}

// Publish to GitHub Packages via:
// ./gradlew -Pversion=<version> clean build publish
// https://github.com/orgs/hotwired/packages?repo_name=hotwire-native-android
// Publish to Maven Central via:
// ./gradlew -Psonatype -Pversion=<version> clean build publish
// https://search.maven.org/artifact/dev.hotwire/navigation-fragments
publishing {
publications {
register<MavenPublication>("release") {
Expand Down Expand Up @@ -144,13 +171,24 @@ publishing {
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/hotwired/hotwire-native-android")
if (isSonatypeRelease) {
maven {
url = uri("https://s01.oss.sonatype.org/content/repositories/releases/")

credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
credentials {
username = System.getenv("SONATYPE_USER")
password = System.getenv("SONATYPE_PASSWORD")
}
}
} else {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/hotwired/hotwire-native-android")

credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
Expand Down

0 comments on commit 6324ddc

Please sign in to comment.