Skip to content

Commit

Permalink
configure signing
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Apr 8, 2022
1 parent b82c65d commit f4aff73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ jobs:
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
IO_OPENFEEDBACK_PROFILE_ID: ${{ secrets.IO_OPENFEEDBACK_PROFILE_ID }}
OPENFEEDBACK_GPG_PRIVATE_KEY: ${{ secrets.OPENFEEDBACK_GPG_PRIVATE_KEY }}
OPENFEEDBACK_GPG_PRIVATE_KEY_PASSWORD: ${{ secrets.OPENFEEDBACK_GPG_PRIVATE_KEY_PASSWORD }}
16 changes: 16 additions & 0 deletions build-logic/src/main/kotlin/io/openfeedback/build/LibraryPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.external.javadoc.StandardJavadocDocletOptions
import org.gradle.jvm.tasks.Jar
import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningExtension

class LibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.apply(mapOf("plugin" to "com.android.library"))
target.apply(mapOf("plugin" to "org.jetbrains.kotlin.android"))
target.apply(mapOf("plugin" to "maven-publish"))
target.apply(mapOf("plugin" to "signing"))

target.extensions.create("openfeedback", OpenFeedback::class.java, target)
}
Expand Down Expand Up @@ -203,4 +206,17 @@ private fun Project.configurePublishingInternal(artifactName: String) {
}
}
}
extensions.configure(SigningExtension::class.java) { signingExtension ->
// GPG_PRIVATE_KEY should contain the armoured private key that starts with -----BEGIN PGP PRIVATE KEY BLOCK-----
// It can be obtained with gpg --armour --export-secret-keys KEY_ID
signingExtension.useInMemoryPgpKeys(
System.getenv("OPENFEEDBACK_GPG_PRIVATE_KEY"),
System.getenv("OPENFEEDBACK_GPG_PRIVATE_KEY_PASSWORD")
)
val publicationsContainer = (extensions.getByName("publishing") as PublishingExtension).publications
signingExtension.sign(publicationsContainer)
}
tasks.withType(Sign::class.java).configureEach {
it.isEnabled = !System.getenv("OPENFEEDBACK_GPG_PRIVATE_KEY").isNullOrBlank()
}
}

0 comments on commit f4aff73

Please sign in to comment.