Skip to content

Commit 05c2f7e

Browse files
authored
feat: release on maven-central (#4)
* make openapi generate depend on sourcesJar * feat: add proper signing for jreleaser * feat: add proper signing for jreleaser * fix: use only env vars * fix: add description * fix: set correct distributions * fix: attempt to release * fix: split build into steps * fix: build and release in one go * fix: pass secrets to signing module * fix: base64 decode secrets * fix: base64 decode secrets * fix: check if newlines is the problem * fix: credentials * fix: signing keys * fix: remove oss repository * fix: publish to local repository staged * fix: path of staging repository * fix: add scm section * fix: rename artifact and try to reupload * fix: name distribution properly * fix: apply maven central rules * fix: rename app to sonatype * fix: latest working build.gradle.kts * fix: remove build from PR, run only on tags
1 parent 865c2af commit 05c2f7e

File tree

2 files changed

+64
-53
lines changed

2 files changed

+64
-53
lines changed

.github/workflows/publish.yml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Publish to Maven Central
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- '*'
77
workflow_dispatch:
88

99
jobs:
@@ -27,25 +27,23 @@ jobs:
2727
- name: Setup Gradle
2828
uses: gradle/gradle-build-action@v2
2929

30-
- name: Build with Gradle
31-
run: ./gradlew build
32-
33-
- name: Setup GPG
34-
env:
35-
GPG_PRIVATE_KEY: ${{ secrets.GPG_SIGNING_KEY }}
36-
GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSWORD }}
37-
run: |
38-
echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import
39-
echo "allow-preset-passphrase" > ~/.gnupg/gpg-agent.conf
40-
echo "default-cache-ttl 34560000" >> ~/.gnupg/gpg-agent.conf
41-
gpg-connect-agent reloadagent /bye
42-
43-
- name: Release to Maven Central
30+
- name: Check release configuration
4431
env:
45-
JRELEASER_NEXUS2_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
46-
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
47-
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSWORD }}
48-
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
49-
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SIGNING_KEY }}
32+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
33+
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }}
34+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
35+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
36+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
5037
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5138
run: ./gradlew jreleaserPublish
39+
40+
- name: Build and Publish
41+
env:
42+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
43+
JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }}
44+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
45+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
46+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
47+
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
run: ./gradlew publish jreleaserFullRelease
49+

build.gradle.kts

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -75,84 +75,97 @@ openApiGenerate {
7575
)
7676
}
7777

78-
// Publishing
78+
79+
tasks.getByName("openApiGenerate").dependsOn(tasks.named<Jar>("sourcesJar"))
80+
81+
7982
jreleaser {
8083
signing {
8184
setActive("ALWAYS")
8285
armored = true
8386
}
84-
project {
85-
authors.set(listOf("UPCI NTUA"))
86-
license.set("MIT")
87-
links {
88-
homepage = "https://api.jaqpot.org"
89-
}
90-
inceptionYear = "2024"
87+
88+
checksum {
89+
// The name of the grouping checksums file.
90+
// Defaults to `checksums.txt`.
91+
//
92+
name.set("{{projectName}}-{{projectVersion}}_checksums.txt")
93+
94+
// Uploads individual checksum files.
95+
// Defaults to `false`.
96+
//
97+
individual = true
98+
99+
// Whether to checksum artifacts in the `distributions` section or not.
100+
// Defaults to `true`.
101+
//
102+
artifacts = true
103+
104+
// Whether to checksum files in the `files` section or not.
105+
// Defaults to `true`.
106+
//
107+
files = true
91108
}
92109

93110
deploy {
94111
maven {
95112
mavenCentral {
96-
register("app") {
113+
register("sonatype") {
97114
setActive("ALWAYS")
98115
url.set("https://central.sonatype.com/api/v1/publisher")
99-
stagingRepository("target/staging-deploy")
116+
stagingRepository("${layout.buildDirectory.get()}/staging-deploy")
100117
username = System.getenv("SONATYPE_USERNAME")
101118
password = System.getenv("SONATYPE_PASSWORD")
119+
applyMavenCentralRules = true
120+
verifyPom = true
102121
}
103122
}
104123
}
105124
}
106-
107-
108-
distributions {
109-
register("app") {
110-
artifact {
111-
path.set(file("build/distributions/{{distributionName}}-{{projectVersion}}.zip"))
112-
}
113-
}
114-
}
115125
}
116126

117-
118127
publishing {
119128
publications {
120129
create<MavenPublication>("mavenJava") {
121-
artifactId = "jaqpot-kotlin-sdk"
130+
artifactId = "kotlin-sdk"
122131
from(components["java"])
123132
pom {
124133
name.set("Jaqpot Kotlin SDK")
125134
description.set("Java/Kotlin SDK for the Jaqpot API")
126-
url.set("https://github.com/ntua-unit-of-control-and-informatics/jaqpot-kotlin-sdk")
135+
url.set("https://github.com/ntua-unit-of-control-and-informatics/kotlin-sdk")
127136
licenses {
128137
license {
129-
name.set("The Apache License, Version 2.0")
130-
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
138+
name.set("MIT License")
139+
url.set("https://opensource.org/licenses/MIT")
140+
distribution.set("repo")
131141
}
132142
}
133143
developers {
134144
developer {
135-
id.set("your-username")
136-
name.set("Your Name")
137-
email.set("your.email@example.com")
145+
id.set("upci")
146+
name.set("Alex Arvanitidis")
147+
email.set("upci.ntua@gmail.com")
138148
}
139149
}
150+
scm {
151+
connection.set("scm:git:git://github.com/ntua-unit-of-control-and-informatics/jaqpot-kotlin-sdk.git")
152+
developerConnection.set("scm:git:ssh://github.com:ntua-unit-of-control-and-informatics/jaqpot-kotlin-sdk.git")
153+
url.set("https://github.com/ntua-unit-of-control-and-informatics/jaqpot-kotlin-sdk")
154+
}
140155
}
141156
}
142157
}
143158
repositories {
144159
maven {
145-
name = "OSSRH"
146-
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
147-
credentials {
148-
username = System.getenv("OSSRH_USERNAME")
149-
password = System.getenv("OSSRH_PASSWORD")
150-
}
160+
url = layout.buildDirectory.dir("staging-deploy").get().asFile.toURI()
151161
}
152162
}
153163
}
154164

155165
signing {
166+
val signingKey = System.getenv("JRELEASER_GPG_SECRET_KEY")
167+
val signingPassword = System.getenv("JRELEASER_GPG_PASSPHRASE")
168+
useInMemoryPgpKeys(signingKey, signingPassword)
156169
sign(publishing.publications["mavenJava"])
157170
}
158171

0 commit comments

Comments
 (0)