-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
3 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ plugins { | |
id("org.jetbrains.dokka") version "1.9.10" | ||
id("io.gitlab.arturbosch.detekt") | ||
id("com.saveourtool.diktat") version "2.0.0" | ||
id("com.saveourtool.buildutils.publishing-configuration") | ||
} | ||
|
||
group = "com.saveourtool" | ||
|
@@ -91,142 +92,7 @@ tasks.withType<ReckonCreateTagTask> { | |
} | ||
|
||
configureDetekt() | ||
configurePublishing() | ||
|
||
fun Project.configurePublishing() { | ||
configureGitHubPublishing() | ||
configurePublications() | ||
configureSigning() | ||
} | ||
|
||
fun Project.configureGitHubPublishing() = | ||
publishing { | ||
repositories { | ||
maven { | ||
name = "GitHub" | ||
url = uri("https://maven.pkg.github.com/saveourtool/okio-extras") | ||
credentials { | ||
username = findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") | ||
password = findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Project.configurePublications() { | ||
val dokkaJar = tasks.create<Jar>("dokkaJar") { | ||
group = "documentation" | ||
archiveClassifier.set("javadoc") | ||
from(tasks.findByName("dokkaHtml")) | ||
} | ||
|
||
configure<PublishingExtension> { | ||
publications.withType<MavenPublication>().configureEach { | ||
this.artifact(dokkaJar) | ||
this.pom { | ||
val project = this@configurePublications | ||
|
||
name.set(project.name) | ||
description.set(project.description ?: project.name) | ||
url.set("https://github.com/saveourtool/${project.name}") | ||
licenses { | ||
license { | ||
name.set("MIT License") | ||
url.set("https://opensource.org/license/MIT") | ||
distribution.set("repo") | ||
} | ||
} | ||
developers { | ||
developer { | ||
id.set("0x6675636b796f75676974687562") | ||
name.set("Andrey Shcheglov") | ||
email.set("[email protected]") | ||
} | ||
} | ||
scm { | ||
url.set("https://github.com/saveourtool/${project.name}") | ||
connection.set("scm:git:https://github.com/saveourtool/${project.name}.git") | ||
developerConnection.set("scm:git:[email protected]:saveourtool/${project.name}.git") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Enables signing of the artifacts if the `signingKey` project property is set. | ||
* | ||
* Should be explicitly called after each custom `publishing {}` section. | ||
*/ | ||
fun Project.configureSigning() { | ||
System.getenv("GPG_SEC")?.let { | ||
extra.set("signingKey", it) | ||
} | ||
System.getenv("GPG_PASSWORD")?.let { | ||
extra.set("signingPassword", it) | ||
} | ||
|
||
if (hasProperty("signingKey")) { | ||
/* | ||
* GitHub Actions. | ||
*/ | ||
configureSigningCommon { | ||
useInMemoryPgpKeys(property("signingKey") as String?, findProperty("signingPassword") as String?) | ||
} | ||
} else if ( | ||
hasProperties( | ||
"signing.keyId", | ||
"signing.password", | ||
"signing.secretKeyRingFile", | ||
) | ||
) { | ||
/*- | ||
* Pure-Java signing mechanism via `org.bouncycastle.bcpg`. | ||
* | ||
* Requires an 8-digit (short form) PGP key id and a present `~/.gnupg/secring.gpg` | ||
* (for gpg 2.1, run | ||
* `gpg --keyring secring.gpg --export-secret-keys >~/.gnupg/secring.gpg` | ||
* to generate one). | ||
*/ | ||
configureSigningCommon() | ||
} else if (hasProperty("signing.gnupg.keyName")) { | ||
/*- | ||
* Use an external `gpg` executable. | ||
* | ||
* On Windows, you may need to additionally specify the path to `gpg` via | ||
* `signing.gnupg.executable`. | ||
*/ | ||
configureSigningCommon { | ||
useGpgCmd() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param useKeys the block which configures the PGP keys. Use either | ||
* [SigningExtension.useInMemoryPgpKeys], [SigningExtension.useGpgCmd], or an | ||
* empty lambda. | ||
* @see SigningExtension.useInMemoryPgpKeys | ||
* @see SigningExtension.useGpgCmd | ||
*/ | ||
@Suppress( | ||
"MaxLineLength", | ||
"SpreadOperator", | ||
) | ||
fun Project.configureSigningCommon(useKeys: SigningExtension.() -> Unit = {}) { | ||
configure<SigningExtension> { | ||
useKeys() | ||
val publications = extensions.getByType<PublishingExtension>().publications | ||
val publicationCount = publications.size | ||
val message = "The following $publicationCount publication(s) are getting signed: ${publications.map(Named::getName)}" | ||
val style = when (publicationCount) { | ||
0 -> Failure | ||
else -> Success | ||
} | ||
styledOut(logCategory = "signing").style(style).println(message) | ||
sign(*publications.toTypedArray()) | ||
} | ||
} | ||
|
||
fun Project.styledOut(logCategory: String): StyledTextOutput = | ||
serviceOf<StyledTextOutputFactory>().create(logCategory) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters