Skip to content

Commit a0b1988

Browse files
committed
Update publish script
1 parent ef34537 commit a0b1988

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

publish.gradle

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,26 @@ afterEvaluate {
6565
}
6666

6767
signing {
68-
useInMemoryPgpKeys(
69-
new String(Base64.decoder.decode(System.getenv("SIGNING_KEY")), "UTF-8"),
70-
System.getenv("SIGNING_PASSWORD")
71-
)
72-
sign publishing.publications.release
68+
signing {
69+
def base64Key = System.getenv("SIGNING_KEY") ?: project.findProperty("signing.key")
70+
def password = System.getenv("SIGNING_PASSWORD") ?: project.findProperty("signing.password")
71+
72+
if (!base64Key) throw new GradleException("SIGNING_KEY is missing or null.")
73+
if (!password) throw new GradleException("SIGNING_PASSWORD is missing or null.")
74+
75+
def decodedKey = new String(Base64.decoder.decode(base64Key as String), "UTF-8")
76+
77+
if (!decodedKey.startsWith("-----BEGIN PGP PRIVATE KEY BLOCK-----")) {
78+
throw new GradleException("SIGNING_KEY does not decode into a valid key block.")
79+
}
80+
81+
try {
82+
useInMemoryPgpKeys(decodedKey, password)
83+
} catch (MissingMethodException e) {
84+
throw new GradleException("`useInMemoryPgpKeys()` not found. Is the signing plugin applied?")
85+
}
86+
87+
sign publishing.publications.release
88+
}
7389
}
7490
}

0 commit comments

Comments
 (0)