Skip to content

Commit

Permalink
fix(ci): migrate to new sonatype publisher API
Browse files Browse the repository at this point in the history
  • Loading branch information
CatCoderr committed Oct 9, 2024
1 parent 257a682 commit fe69c12
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 32 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ name: Build

on: [ push ]

env:
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_OSSRH_DEPLOYER }}
SONATYPE_TOKEN: ${{ secrets.SONATYPE_OSSRH_TOKEN }}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -23,14 +16,22 @@ jobs:
distribution: 'adopt'
cache: 'gradle'

- name: Build with Gradle
run: ./gradlew test build --no-daemon
- name: Build and publish with Gradle
if: github.ref == 'refs/heads/master'
env:
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }}
run: ./gradlew -i jreleaserConfig build test publish --no-daemon

- name: Publish to Sonatype
- name: Release
if: github.ref == 'refs/heads/master'
env:
GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
run: ./gradlew publish --no-daemon
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }}
run: ./gradlew -i jreleaserFullRelease --no-daemon
59 changes: 42 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import org.jreleaser.model.Active

plugins {
id("java-library")
id("maven-publish")
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("signing")
id("org.jreleaser") version "1.14.0"
}

group = "me.catcoder"
Expand Down Expand Up @@ -63,17 +64,49 @@ val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

publishing {
jreleaser {
signing {
active = Active.ALWAYS
armored = true
verify = false
}
project {
inceptionYear = "2021"
author("@CatCoderr")
}
deploy {
maven {
mavenCentral.create("sonatype") {
active = Active.ALWAYS
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository(layout.buildDirectory.dir("staging-deploy").get().toString())
setAuthorization("Basic")
sign = true
checksums = true
sourceJar = true
javadocJar = true
retryDelay = 60
}
}
}

release {
github {
skipRelease = true
skipTag = true
}
}
}


// Configure all publications
publishing {
publications {

create<MavenPublication>("mavenJava") {
create<MavenPublication>("release") {
from(components["java"])

artifact(javadocJar.get())

// Provide artifacts information requited by Maven Central
pom {
name.set("ProtocolSidebar")
description.set(project.description)
Expand Down Expand Up @@ -105,22 +138,14 @@ publishing {
}
}
}
}

nexusPublishing {
repositories {
sonatype()
maven {
setUrl(layout.buildDirectory.dir("staging-deploy"))
}
}
}

signing {
val signingKey = System.getenv("GPG_SECRET_KEY")
val signingPassword = System.getenv("GPG_PASSPHRASE")

useInMemoryPgpKeys(signingKey, signingPassword)

sign(publishing.publications["mavenJava"])
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
Expand Down

0 comments on commit fe69c12

Please sign in to comment.