Skip to content

Commit

Permalink
feature: Publish to OSSRH / MavenCentral
Browse files Browse the repository at this point in the history
Closes: #46
Signed-off-by: Andre Weber <[email protected]>
  • Loading branch information
wba2hi committed Nov 27, 2023
1 parent c0ab1f2 commit 6fd1a87
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/deploy-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
tags:
- 'release/v*'

permissions:
packages: write

jobs:
deployment:
runs-on: ubuntu-latest
Expand All @@ -29,7 +26,9 @@ jobs:
run: ./gradlew setReleaseVersion # Do not chain this command because it writes into a file which needs to be re-read inside the next gradle command

- name: Publish Library
run: ./gradlew publishReleasePublicationToGithubPackagesRepository
-Pgpr.repository=${{ github.repository }}
-Pgpr.user=${{ github.actor }}
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
env:
ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }}
ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
ORG_OSSRH_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }}
ORG_OSSRH_USERNAME: ${{ secrets.ORG_OSSRH_USERNAME }}
run: ./gradlew publishAllPublicationsToOSSRHReleaseRepository
13 changes: 6 additions & 7 deletions .github/workflows/deploy-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
branches:
- main

permissions:
packages: write

jobs:
deployment:
runs-on: ubuntu-latest
Expand All @@ -32,7 +29,9 @@ jobs:
run: ./gradlew setSnapshotVersion # Do not chain this command because it writes into a file which needs to be re-read inside the next gradle command

- name: Publish Library
run: ./gradlew publishReleasePublicationToGithubPackagesRepository
-Pgpr.repository=${{ github.repository }}
-Pgpr.user=${{ github.actor }}
-Pgpr.token=${{ secrets.GITHUB_TOKEN }}
env:
ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }}
ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
ORG_OSSRH_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }}
ORG_OSSRH_USERNAME: ${{ secrets.ORG_OSSRH_USERNAME }}
run: ./gradlew publishAllPublicationsToOSSRHSnapshotRepository
26 changes: 21 additions & 5 deletions buildSrc/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

plugins {
`maven-publish`
signing
}

interface PublishPluginExtension {
Expand All @@ -32,14 +33,21 @@ afterEvaluate {
publishing {
repositories {
maven {
name = "GithubPackages"
name = "OSSRHRelease"

val repository = project.findProperty("gpr.repository") as String? ?: System.getenv("GPR_REPOSITORY")
url = uri("https://maven.pkg.github.com/$repository")
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = System.getenv("ORG_OSSRH_USERNAME")
password = System.getenv("ORG_OSSRH_PASSWORD")
}
}
maven {
name = "OSSRHSnapshot"

url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GPR_USERNAME")
password = project.findProperty("gpr.token") as String? ?: System.getenv("GPR_TOKEN")
username = System.getenv("ORG_OSSRH_USERNAME")
password = System.getenv("ORG_OSSRH_PASSWORD")
}
}
}
Expand All @@ -49,4 +57,12 @@ afterEvaluate {
}
}
}

signing {
val signingKey = System.getenv("ORG_GPG_PASSPHRASE")
val signingPassword = System.getenv("ORG_GPG_PRIVATE_KEY")
useInMemoryPgpKeys(signingKey, signingPassword)

sign(publishing.publications)
}
}

0 comments on commit 6fd1a87

Please sign in to comment.