Skip to content

Commit 78c7644

Browse files
committed
ci: add signing of artifacts and sonatype as maven repo
1 parent 071025c commit 78c7644

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

.github/workflows/publish-release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@ jobs:
2828
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
2929
restore-keys: |
3030
${{ runner.os }}-gradle-
31+
- name: Import gpg key
32+
env:
33+
GPG_KEY_BASE64: ${{ secrets.GPG_KEY_BASE64 }}
34+
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
35+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
36+
run: echo $GPG_KEY_BASE64 | base64 --decode | gpg --yes --batch --import
3137
- name: Publish artifact
3238
env:
3339
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
41+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
42+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
43+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
3444

3545
# The GITHUB_REF tag comes in the format 'refs/tags/xxx'.
3646
# So if we split on '/' and take the 3rd value, we can get the release name.

build.gradle.kts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dependencies {
5959
publishing {
6060
publications {
6161
create<MavenPublication>("mavenJava") {
62-
artifactId = "${rootProject.name}"
62+
artifactId = rootProject.name
6363
from(components["java"])
6464
versionMapping {
6565
usage("java-api") {
@@ -71,7 +71,7 @@ publishing {
7171
}
7272
}
7373
pom {
74-
name.set("${rootProject.name}")
74+
name.set(rootProject.name)
7575
description.set("A simple mock oauth2 server based on OkHttp MockWebServer")
7676
url.set("https://github.com/navikt/${rootProject.name}")
7777

@@ -86,11 +86,6 @@ publishing {
8686
organization.set("NAV (Arbeids- og velferdsdirektoratet) - The Norwegian Labour and Welfare Administration")
8787
organizationUrl.set("https://www.nav.no")
8888
}
89-
developer {
90-
id.set("tommytroen")
91-
name.set("Tommy Trøen")
92-
email.set("tommy.troen@nav.no")
93-
}
9489
}
9590
scm {
9691
connection.set("scm:git:git://github.com/navikt/${rootProject.name}.git")
@@ -108,18 +103,28 @@ publishing {
108103
username = System.getenv("GITHUB_ACTOR")
109104
password = System.getenv("GITHUB_TOKEN")
110105
}
111-
/*
112-
// change URLs to point to your repos, e.g. http://my.org/repo
106+
}
107+
maven {
108+
name = "Sonatype"
113109
val releasesRepoUrl = uri("$mavenRepoBaseUrl/service/local/staging/deploy/maven2/")
114110
val snapshotsRepoUrl = uri("$mavenRepoBaseUrl/content/repositories/snapshots")
115-
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl*/
111+
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
112+
credentials {
113+
username = System.getenv("SONATYPE_USERNAME")
114+
password = System.getenv("SONATYPE_PASSWORD")
115+
}
116116
}
117117
}
118118
}
119119

120-
/*signing {
120+
ext["signing.gnupg.keyName"] = System.getenv("GPG_KEY_NAME")
121+
ext["signing.gnupg.passphrase"] = System.getenv("GPG_PASSPHRASE")
122+
ext["signing.gnupg.useLegacyGpg"] = true
123+
124+
signing {
125+
useGpgCmd()
121126
sign(publishing.publications["mavenJava"])
122-
}*/
127+
}
123128

124129
tasks.javadoc {
125130
if (JavaVersion.current().isJava9Compatible) {
@@ -166,13 +171,15 @@ tasks {
166171
"jibDockerBuild" {
167172
dependsOn("shadowJar")
168173
}
169-
/*
170-
"publish" {
174+
175+
/* "publish" {
171176
dependsOn("shadowJar")
172177
dependsOn("jibDockerBuild")
173-
}
174-
*/
178+
}*/
179+
175180
withType<Sign>().configureEach {
176-
onlyIf { !version.toString().endsWith("SNAPSHOT") }
181+
onlyIf {
182+
project.hasProperty("signing.gnupg.keyName")
183+
}
177184
}
178185
}

0 commit comments

Comments
 (0)