@@ -3,7 +3,6 @@ import com.vanniktech.maven.publish.SonatypeHost
33import helpers.configureMavenCentralMetadata
44import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
55import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
6- import kotlin.io.encoding.Base64
76import kotlin.io.encoding.ExperimentalEncodingApi
87
98val kotlinJvmTarget: String by project
@@ -72,30 +71,32 @@ subprojects {
7271 }
7372}
7473
75- @OptIn(ExperimentalEncodingApi ::class )
76- private fun MavenPublishBaseExtension.signIfKeyPresent (project : Project ) {
77- val keyId = System .getenv(" KEY_ID" )
78- val keyBytes = runCatching {
79- Base64 .decode(System .getenv(" SECRING" ).toByteArray()).decodeToString()
80- }.getOrNull()
81- val keyPassword = System .getenv(" PASSWORD" )
74+ fun MavenPublishBaseExtension.signIfKeyPresent (project : Project ) {
75+ val keyId = System .getenv(" SIGNING_KEY_ID" )
76+ val signingKey = System .getenv(" SIGNING_KEY" )
77+ val signingKeyPassphrase = System .getenv(" SIGNING_KEY_PASSPHRASE" )
8278
83- if (keyBytes != null && keyPassword != null ) {
84- project.logger.info(" Signing artifacts with in-memory PGP key (.gpg) " )
79+ if (! signingKey.isNullOrBlank() ) {
80+ project.logger.info(" Signing artifacts with in-memory PGP key for ${project.path} " )
8581 project.extensions.configure<SigningExtension >(" signing" ) {
86- // For binary .gpg keys
87- if (keyId == null ) {
88- useInMemoryPgpKeys(keyBytes, keyPassword)
89- } else {
90- useInMemoryPgpKeys(keyId, keyBytes, keyPassword)
91- }
82+ useInMemoryPgpKeys(keyId, preprocessPrivateGpgKey(signingKey), signingKeyPassphrase)
9283 signAllPublications()
9384 }
9485 } else {
95- project.logger.info (" Skipping signing of artifacts: PGP key or password not found in environment variables" )
86+ project.logger.warn (" Skipping signing of artifacts: PGP key or password not found in environment variables for ${project.path} " )
9687 }
9788}
9889
90+ private fun preprocessPrivateGpgKey (key : String ): String {
91+ val prefix = " -----BEGIN PGP PRIVATE KEY BLOCK-----"
92+ val suffix = " -----END PGP PRIVATE KEY BLOCK-----"
93+ val delimiter = " \r\n "
94+ return prefix + delimiter + key
95+ .replace(prefix, " " )
96+ .replace(suffix, " " )
97+ .replace(" " , " \r\n " ) + delimiter + suffix
98+ }
99+
99100tasks.register(" printVersion" ) {
100101 doLast {
101102 println (projectVersion)
0 commit comments