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

Add Sonatype (Maven Central) publishing support #59

Merged
merged 2 commits into from
Sep 25, 2024
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
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("[email protected]")

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("[email protected]")

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
Loading