Skip to content

Commit 66c9aec

Browse files
author
ahmetduruer
committed
feat: test release in mvn central
1 parent cde84df commit 66c9aec

File tree

2 files changed

+143
-53
lines changed

2 files changed

+143
-53
lines changed

.github/workflows/release.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,23 @@ jobs:
8484
distribution: temurin
8585
java-version: 21
8686

87-
- name: Build with Gradle
87+
- name: Setup Gradle
8888
uses: gradle/actions/setup-gradle@v4
8989

90-
- name: Import GPG key
91-
env:
92-
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
93-
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
94-
run: |
95-
echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import
96-
echo "$GPG_PASSPHRASE" | gpg --batch --pinentry-mode loopback --passphrase-fd 0 --import-ownertrust
97-
98-
- name: Build & Publish
90+
- name: Build with Gradle
9991
run: |
100-
./gradlew ${{ steps.extract_branch.outputs.branch == 'main' && 'build' || 'buildDev' }} publish \
92+
./gradlew ${{ steps.extract_branch.outputs.branch == 'main' && 'build' || 'buildDev' }} \
10193
-PbuildType=${{ steps.extract_branch.outputs.branch == 'main' && 'release' || steps.extract_branch.outputs.branch }} \
10294
-Pversion=${{ needs.get-next-version.outputs.new_tag_version }} \
10395
-PtimeStamp=${{ steps.time.outputs.time }}
10496
env:
10597
USERNAME_GITHUB: ${{ secrets.USERNAME_GITHUB }}
10698
TOKEN_GITHUB: ${{ secrets.TOKEN_GITHUB }}
107-
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
108-
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
99+
100+
- name: Publish to Maven Central with JReleaser
101+
run: |
102+
./gradlew -Pversion=${{ needs.get-next-version.outputs.new_tag_version }} publish
103+
env:
109104
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
110105
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
111106

@@ -118,7 +113,27 @@ jobs:
118113
run: |
119114
npm install --no-save semantic-release @semantic-release/changelog
120115
121-
- name: Release
116+
- name: Create GitHub Release with Semantic Release
122117
env:
123118
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
124119
run: npx semantic-release
120+
121+
- name: Deploy to Maven Central with JReleaser
122+
run: |
123+
./gradlew -Pversion=${{ needs.get-next-version.outputs.new_tag_version }} jreleaserDeploy
124+
env:
125+
JRELEASER_GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
126+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVENCENTRAL_USERNAME }}
127+
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.MAVENCENTRAL_TOKEN }}
128+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
129+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
130+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
131+
132+
- name: JReleaser output
133+
if: always()
134+
uses: actions/upload-artifact@v4
135+
with:
136+
name: jreleaser-logs
137+
path: |
138+
build/jreleaser/trace.log
139+
build/jreleaser/output.properties

build.gradle.kts

Lines changed: 114 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ plugins {
1818
kotlin("jvm") version "2.0.21"
1919
kotlin("kapt") version "2.0.21"
2020
id("com.github.johnrengelman.shadow") version "8.1.1"
21-
application
21+
id("org.jreleaser") version "1.14.0"
2222
`maven-publish`
2323
signing
24+
application
2425
}
2526

2627
group = "dev.parsek"
@@ -154,45 +155,7 @@ tasks.named("jar").configure {
154155
enabled = defaultJarEnabled.toBoolean()
155156
}
156157

157-
publishing {
158-
repositories {
159-
maven {
160-
name = "Parsek"
161-
url = uri("https://maven.pkg.github.com/ParsekDev/parsek")
162-
credentials {
163-
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME_GITHUB")
164-
password = project.findProperty("gpr.token") as String? ?: System.getenv("TOKEN_GITHUB")
165-
}
166-
}
167-
168-
}
169-
170-
publications {
171-
create<MavenPublication>("shadow") {
172-
project.extensions.configure<ShadowExtension> {
173-
artifactId = "core"
174-
component(this@create)
175-
}
176-
}
177-
}
178-
}
179-
180-
signing {
181-
val signingKey = System.getenv("GPG_PRIVATE_KEY")?.let { String(Base64.getDecoder().decode(it.replace("\n", ""))) }
182-
val signingPassphrase = System.getenv("GPG_PASSPHRASE")
183-
184-
if (!signingKey.isNullOrEmpty() && !signingPassphrase.isNullOrEmpty()) {
185-
useInMemoryPgpKeys(signingKey, signingPassphrase)
186-
sign(publishing.publications)
187-
} else {
188-
logger.warn("Signing is not configured. Skipping signing tasks.")
189-
}
190-
}
191-
192158
java {
193-
withJavadocJar()
194-
withSourcesJar()
195-
196159
// Use Java 21 for compilation
197160
toolchain {
198161
languageVersion.set(JavaLanguageVersion.of(21))
@@ -212,4 +175,116 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
212175
tasks.withType<JavaCompile> {
213176
sourceCompatibility = "1.8"
214177
targetCompatibility = "1.8"
178+
}
179+
180+
// Publishing configuration
181+
publishing {
182+
publications {
183+
create<MavenPublication>("maven") {
184+
groupId = "dev.parsek"
185+
artifactId = "core"
186+
version = project.version.toString()
187+
188+
from(components["java"])
189+
190+
// Include sources and javadoc
191+
artifact(tasks.named("kotlinSourcesJar"))
192+
artifact(tasks.named("javadocJar"))
193+
194+
pom {
195+
name.set("Parsek")
196+
description.set("A lightweight, modular framework for building RESTful APIs with Kotlin and Vert.x")
197+
url.set("https://github.com/Statucorp/parsek-core")
198+
inceptionYear.set("2024")
199+
200+
licenses {
201+
license {
202+
name.set("MIT License")
203+
url.set("https://opensource.org/licenses/MIT")
204+
}
205+
}
206+
207+
developers {
208+
developer {
209+
id.set(" StatuCorp")
210+
name.set("Statu Corporation")
211+
email.set("[email protected]")
212+
}
213+
}
214+
215+
scm {
216+
connection.set("scm:git:git://github.com/Statucorp/parsek-core.git")
217+
developerConnection.set("scm:git:ssh://github.com/Statucorp/parsek-core.git")
218+
url.set("https://github.com/Statucorp/parsek-core")
219+
}
220+
}
221+
}
222+
}
223+
224+
repositories {
225+
maven {
226+
url = layout.buildDirectory.dir("staging-deploy").get().asFile.toURI()
227+
}
228+
}
229+
}
230+
231+
// Configure Kotlin sources jar
232+
tasks.register<Jar>("kotlinSourcesJar") {
233+
archiveClassifier.set("sources")
234+
from(sourceSets["main"].allSource)
235+
}
236+
237+
// Configure Javadoc jar
238+
tasks.register<Jar>("javadocJar") {
239+
archiveClassifier.set("javadoc")
240+
// For Kotlin projects, we can use an empty javadoc jar or generate KDoc
241+
// Empty javadoc is acceptable for Maven Central
242+
}
243+
244+
// Signing configuration
245+
signing {
246+
val signingKey = System.getenv("GPG_PRIVATE_KEY")
247+
val signingPassword = System.getenv("GPG_PASSPHRASE")
248+
249+
if (signingKey != null && signingPassword != null) {
250+
useInMemoryPgpKeys(signingKey, signingPassword)
251+
sign(publishing.publications["maven"])
252+
}
253+
}
254+
255+
// JReleaser configuration
256+
jreleaser {
257+
project {
258+
description.set("A lightweight, modular framework for building RESTful APIs with Kotlin and Vert.x")
259+
authors.add("StatuCorp")
260+
license.set("MIT")
261+
links {
262+
homepage.set("https://github.com/Statucorp/parsek-core")
263+
}
264+
inceptionYear.set("2024")
265+
}
266+
267+
// Disable release (semantic-release handles GitHub releases)
268+
release {
269+
github {
270+
enabled.set(false)
271+
}
272+
}
273+
274+
signing {
275+
active.set(org.jreleaser.model.Active.ALWAYS)
276+
armored.set(true)
277+
}
278+
279+
deploy {
280+
maven {
281+
mavenCentral {
282+
create("sonatype") {
283+
active.set(org.jreleaser.model.Active.ALWAYS)
284+
url.set("https://central.sonatype.com/api/v1/publisher")
285+
stagingRepository("build/staging-deploy")
286+
}
287+
}
288+
}
289+
}
215290
}

0 commit comments

Comments
 (0)