Skip to content

Commit

Permalink
Updating publish to sonatype action
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzemehdi committed Jul 27, 2024
1 parent a5eb589 commit ebc6053
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 82 deletions.
72 changes: 14 additions & 58 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
distribution: 'temurin'

- name: Setup gradle
uses: gradle/gradle-build-action@v2.4.2
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1

- name: Check api
run: ./gradlew apiCheck
Expand All @@ -59,7 +59,7 @@ jobs:
distribution: 'temurin'

- name: Setup gradle
uses: gradle/gradle-build-action@v2.4.2
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1

- name: Test ${{ matrix.config.target }} targets
continue-on-error: ${{ matrix.config.continueOnError }}
Expand All @@ -84,7 +84,7 @@ jobs:
distribution: 'temurin'

- name: Setup gradle
uses: gradle/gradle-build-action@v2.4.2
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1

- name: Setup Pages
uses: actions/configure-pages@v3
Expand All @@ -101,47 +101,6 @@ jobs:
id: deployment
uses: actions/deploy-pages@v1

- name: Create new release from tag
env:
github_token: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
token: ${{ env.github_token }}


create-staging-repository:
runs-on: ubuntu-latest
name: Create staging repository
needs: release
outputs:
repository_id: ${{ steps.create.outputs.repository_id }}
steps:
- id: create
uses: nexus-actions/create-nexus-staging-repo@v1.3.0
with:
username: mirzemehdi
password: ${{ secrets.SONATYPE_PASSWORD }}
staging_profile_id: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
description: Created by GitHub Actions
base_url: https://s01.oss.sonatype.org/service/local/

publish:
name: Publish to Maven
runs-on: macos-latest
needs: create-staging-repository
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Setup gradle
uses: gradle/gradle-build-action@v2.4.2

- name: Write secrets to local.properties
run: |
echo sonatypeUsername="${SONATYPE_USERNAME}" >> "local.properties"
Expand All @@ -155,19 +114,16 @@ jobs:
GPG_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }}
GPG_KEY_SECRET: ${{ secrets.GPG_KEY_SECRET }}

- name: Release to sonatype
run: ./gradlew publishAllPublicationsToMavenRepository
- name: Publish to sonatype
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository

close-staging-repository:
name: Close staging repository
runs-on: ubuntu-latest
needs: [ create-staging-repository, publish ]
if: ${{ always() && needs.create-staging-repository.result == 'success' }}
steps:
- name: Close staging repository
uses: nexus-actions/release-nexus-staging-repo@6632a81bfab63557b2717e8423b0a620ae5aa414
- name: Create new release from tag
env:
github_token: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v1
with:
username: mirzemehdi
password: ${{ secrets.SONATYPE_PASSWORD }}
staging_repository_id: ${{ needs.create-staging-repository.outputs.repository_id }}
base_url: https://s01.oss.sonatype.org/service/local/
generate_release_notes: true
token: ${{ env.github_token }}


37 changes: 15 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
alias(libs.plugins.dokka) apply false
alias(libs.plugins.googleServices) apply false
alias(libs.plugins.kotlinx.binary.validator)
alias(libs.plugins.nexusPublish)
}


Expand All @@ -21,38 +22,18 @@ plugins {
allprojects {
group = "io.github.mirzemehdi"
version = project.properties["kmpAuthVersion"] as String
val sonatypeUsername = gradleLocalProperties(rootDir).getProperty("sonatypeUsername")
val sonatypePassword = gradleLocalProperties(rootDir).getProperty("sonatypePassword")

val gpgKeySecret = gradleLocalProperties(rootDir).getProperty("gpgKeySecret")
val gpgKeyPassword = gradleLocalProperties(rootDir).getProperty("gpgKeyPassword")

val excludedModules = listOf(":sampleApp:composeApp",":sampleApp")
val excludedModules = listOf(":sampleApp:composeApp", ":sampleApp")
if (project.path in excludedModules) return@allprojects

apply(plugin = "org.jetbrains.dokka")
apply(plugin = "maven-publish")
apply(plugin = "signing")


extensions.configure<PublishingExtension> {
repositories {
maven {
val isSnapshot = version.toString().endsWith("SNAPSHOT")
val repositoryId = System.getenv("SONATYPE_REPOSITORY_ID") ?: ""
url = uri(
when{
isSnapshot.not() && repositoryId.isNotEmpty() -> "https://s01.oss.sonatype.org/service/local/staging/deployByRepositoryId/${repositoryId}/"
isSnapshot.not() -> "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2"
else -> "https://s01.oss.sonatype.org/content/repositories/snapshots"
}
)
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}

val javadocJar = tasks.register<Jar>("javadocJar") {
dependsOn(tasks.getByName<DokkaTask>("dokkaHtml"))
archiveClassifier.set("javadoc")
Expand Down Expand Up @@ -103,5 +84,17 @@ allprojects {
dependsOn(project.tasks.withType(Sign::class.java))
}
}
nexusPublishing {
repositories {
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
val sonatypeUsername = gradleLocalProperties(rootDir).getProperty("sonatypeUsername")
val sonatypePassword = gradleLocalProperties(rootDir).getProperty("sonatypePassword")
username = sonatypeUsername
password = sonatypePassword
}
}
}


2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ kotlin.mpp.enableCInteropCommonization=true
#Development
development=true

kmpAuthVersion=2.0.0
kmpAuthVersion=2.1.0-alpha01
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ koinCompose = "4.0.0-RC1"
googleServices = "4.4.2"
firebaseGitLiveAuth = "1.12.0"
androidLegacyPlayServices = "21.2.0"
nexusPublish = "2.0.0"


[libraries]
Expand Down Expand Up @@ -69,3 +70,4 @@ kotlinNativeCocoaPods = { id = "org.jetbrains.kotlin.native.cocoapods", version.
kotlinx-binary-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinx-binary-validator" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
googleServices = { id = "com.google.gms.google-services", version.ref = "googleServices" }
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublish" }
2 changes: 1 addition & 1 deletion kmpauth-google/kmpauth_google.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'kmpauth_google'
spec.version = '2.0.0'
spec.version = '2.1.0-alpha01'
spec.homepage = ''
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit ebc6053

Please sign in to comment.