Skip to content

Commit

Permalink
Migrate central publish plugin (Workaround) (LotsOfPixelsStudios#113)
Browse files Browse the repository at this point in the history
* update publish plugin to use the Portal Publisher API

* disable github release

* update secrets in env

* update maven secrets in env

* fix maven secrets in env

* update GitHub releases

* create jreleaser dir in build dir when realising if not existing

* debug paths

* debug paths

* remove debug and switch gradle tasks

* remove clean task

* get build dir from gradle

* skip release + tag in github while publishing to maven central

* debug

* debug

* more debug

* more debug

* more debug

* more debug

* more debug

* update build action

* split action into multiple steps
  • Loading branch information
12rcu authored Jul 21, 2024
1 parent aff6b28 commit 6413a83
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 35 deletions.
31 changes: 20 additions & 11 deletions .github/workflows/monstera-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ on:

jobs:
build:

env:
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.JRELEASER_MAVENCENTRAL_USERNAME }}
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.JRELEASER_MAVENCENTRAL_TOKEN }}
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -20,14 +26,17 @@ jobs:
java-version: '11'
distribution: 'temurin'

- name: Publish to Maven Central
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
- name: Create Config
uses: gradle/gradle-build-action@v3
with:
arguments: jreleaserConfig

- name: Publish to local staging repo
uses: gradle/gradle-build-action@v3
with:
arguments: publish

- name: Release to Maven Central
uses: gradle/gradle-build-action@v3
with:
arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
MAVEN_USER_NAME: ${{ secrets.MAVEN_USER_NAME }}
MAVEN_USER_PASSWORD: ${{ secrets.MAVEN_USER_PASSWORD }}
arguments: jreleaserFullRelease
55 changes: 31 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
plugins {
kotlin("jvm") version "2.0.0"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
`maven-publish`
signing
`java-library`
id("org.jreleaser") version "1.13.1"
}

group = "com.lotsofpixelsstudios"
version = System.getenv("GITHUB_REF")?.removePrefix("refs/tags/") ?: "local" //use tag name as version
/*group = "com.lotsofpixelsstudios"*/
group = "de.matthiasklenz"
version = System.getenv("GITHUB_REF")?.removePrefix("refs/tags/") ?: "0.5.0-SNAPSHOT1"//"0.1-local" //use tag name as version

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
Expand Down Expand Up @@ -34,19 +35,6 @@ java {
withSourcesJar()
}

signing {
gradle.taskGraph.whenReady {
isRequired = allTasks.any { it is PublishToMavenRepository }
}

useInMemoryPgpKeys(
System.getenv("ORG_GRADLE_PROJECT_signingKey"),
System.getenv("ORG_GRADLE_PROJECT_signingPassword")
)

sign(publishing.publications)
}

//set the version in the resource files to access it from projects
gradle.taskGraph.whenReady {
layout
Expand All @@ -72,13 +60,27 @@ repositories {
mavenCentral()
}

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/"))
username = System.getenv("MAVEN_USER_NAME")
password = System.getenv("MAVEN_USER_PASSWORD")
jreleaser {
release {
github {
skipTag = true
skipRelease = true
}
}
signing {
setActive("ALWAYS")
armored = true
}
deploy {
maven {
//Portal Publisher API
mavenCentral {
register("sonatype") {
setActive("ALWAYS")
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository(layout.buildDirectory.dir("staging-deploy").get().asFile.path)
}
}
}
}
}
Expand Down Expand Up @@ -111,4 +113,9 @@ publishing {
}
}
}
repositories {
maven {
url = layout.buildDirectory.dir("staging-deploy").get().asFile.toURI()
}
}
}

0 comments on commit 6413a83

Please sign in to comment.