Rework registration of release tasks #39

Merged
CommanderTvis merged 1 commits from commandertvis/ios into dev 2022-03-08 21:49:40 +03:00
2 changed files with 37 additions and 35 deletions
Showing only changes of commit 572cbce67f - Show all commits

View File

@ -5,7 +5,7 @@ atomicfu = "0.17.1"
binary-compatibility-validator = "0.8.0" binary-compatibility-validator = "0.8.0"
changelog = "1.3.1" changelog = "1.3.1"
dokka = "1.6.10" dokka = "1.6.10"
kotlin-jupyter = "0.11.0-53" kotlin-jupyter = "0.11.0-62"
kotlinx-benchmark = "0.4.2" kotlinx-benchmark = "0.4.2"
kotlinx-cli = "0.3.4" kotlinx-cli = "0.3.4"
kotlinx-collections-immutable = "0.3.5" kotlinx-collections-immutable = "0.3.5"

View File

@ -4,7 +4,9 @@ import kotlinx.validation.ApiValidationExtension
import kotlinx.validation.BinaryCompatibilityValidatorPlugin import kotlinx.validation.BinaryCompatibilityValidatorPlugin
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.publish.maven.tasks.PublishToMavenLocal
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.changelog.ChangelogPluginExtension import org.jetbrains.changelog.ChangelogPluginExtension
@ -12,11 +14,12 @@ import org.jetbrains.dokka.gradle.AbstractDokkaTask
import org.jetbrains.dokka.gradle.DokkaPlugin import org.jetbrains.dokka.gradle.DokkaPlugin
import ru.mipt.npm.gradle.internal.* import ru.mipt.npm.gradle.internal.*
private fun Project.allTasks(): Set<Task> = allprojects.flatMapTo(HashSet()) { it.tasks } /**
* Simplifies adding repositories for Maven publishing, responds for releasing tasks for projects.
@Suppress("unused") */
public class KSciencePublishingExtension(public val project: Project) { public class KSciencePublishingExtension(public val project: Project) {
private var isVcsInitialized = false private var isVcsInitialized = false
internal val repositoryNames = mutableSetOf<String>()
@Deprecated("Use git function and report an issue if other VCS is used.") @Deprecated("Use git function and report an issue if other VCS is used.")
public fun vcs(vcsUrl: String) { public fun vcs(vcsUrl: String) {
@ -53,22 +56,6 @@ public class KSciencePublishingExtension(public val project: Project) {
} }
} }
private fun linkPublicationsToReleaseTask(name: String) = project.afterEvaluate {
allTasks()
.filter { it.name.startsWith("publish") && it.name.endsWith("To${name.capitalize()}Repository") }
.forEach {
val theName = "release${it.name.removePrefix("publish").removeSuffix("To${name.capitalize()}Repository")}"
logger.info("Making $theName task depend on ${it.name}")
val releaseTask = project.tasks.findByName(theName) ?: project.tasks.create(theName) {
group = KScienceProjectPlugin.RELEASE_GROUP
description = "Publish development or production release based on version suffix"
}
releaseTask.dependsOn(it)
}
}
/** /**
* Adds GitHub as VCS and adds GitHub Packages Maven repository to publishing. * Adds GitHub as VCS and adds GitHub Packages Maven repository to publishing.
* *
@ -89,7 +76,7 @@ public class KSciencePublishingExtension(public val project: Project) {
if (addToRelease) { if (addToRelease) {
try { try {
project.addGithubPublishing(githubOrg, githubProject) project.addGithubPublishing(githubOrg, githubProject)
linkPublicationsToReleaseTask("github") repositoryNames += "github"
} catch (t: Throwable) { } catch (t: Throwable) {
project.logger.error("Failed to set up github publication", t) project.logger.error("Failed to set up github publication", t)
} }
@ -108,15 +95,9 @@ public class KSciencePublishingExtension(public val project: Project) {
) { ) {
project.addSpacePublishing(spaceRepo) project.addSpacePublishing(spaceRepo)
if (addToRelease) linkPublicationsToReleaseTask("space") if (addToRelease) repositoryNames += "space"
} }
// // Bintray publishing
// var bintrayOrg: String? by project.extra
// var bintrayUser: String? by project.extra
// var bintrayApiKey: String? by project.extra
// var bintrayRepo: String? by project.extra
/** /**
* Adds Sonatype Maven repository to publishing. * Adds Sonatype Maven repository to publishing.
* *
@ -128,7 +109,7 @@ public class KSciencePublishingExtension(public val project: Project) {
require(isVcsInitialized) { "The project vcs is not set up use 'git' method to do so" } require(isVcsInitialized) { "The project vcs is not set up use 'git' method to do so" }
project.addSonatypePublishing() project.addSonatypePublishing()
if (addToRelease) linkPublicationsToReleaseTask("sonatype") if (addToRelease) repositoryNames += "sonatype"
} }
} }
@ -139,7 +120,6 @@ public class KSciencePublishingExtension(public val project: Project) {
public open class KScienceProjectPlugin : Plugin<Project> { public open class KScienceProjectPlugin : Plugin<Project> {
override fun apply(target: Project): Unit = target.run { override fun apply(target: Project): Unit = target.run {
apply<ChangelogPlugin>() apply<ChangelogPlugin>()
apply<DokkaPlugin>() apply<DokkaPlugin>()
apply<BinaryCompatibilityValidatorPlugin>() apply<BinaryCompatibilityValidatorPlugin>()
@ -156,7 +136,8 @@ public open class KScienceProjectPlugin : Plugin<Project> {
} }
val rootReadmeExtension = KScienceReadmeExtension(this) val rootReadmeExtension = KScienceReadmeExtension(this)
extensions.add("ksciencePublish", KSciencePublishingExtension(this)) val ksciencePublish = KSciencePublishingExtension(this)
extensions.add("ksciencePublish", ksciencePublish)
extensions.add("readme", rootReadmeExtension) extensions.add("readme", rootReadmeExtension)
//Add readme generators to individual subprojects //Add readme generators to individual subprojects
@ -192,6 +173,29 @@ public open class KScienceProjectPlugin : Plugin<Project> {
} }
} }
allprojects {
afterEvaluate {
ksciencePublish.repositoryNames.forEach { repositoryName ->
val repositoryNameCapitalized = repositoryName.capitalize()
tasks.withType<PublishToMavenRepository>()
.filter { it.name.startsWith("publish") && it.name.endsWith("To${repositoryNameCapitalized}Repository") }
.forEach {
val theName = "release${
it.name.removePrefix("publish").removeSuffix("To${repositoryNameCapitalized}Repository")
}"
val releaseTask = tasks.findByName(theName) ?: tasks.create(theName) {
group = RELEASE_GROUP
description = "Publish development or production release based on version suffix"
}
releaseTask.dependsOn(it)
}
}
}
}
val generateReadme by tasks.creating { val generateReadme by tasks.creating {
group = "documentation" group = "documentation"
description = "Generate a README file and a feature matrix if stub is present" description = "Generate a README file and a feature matrix if stub is present"
@ -228,8 +232,7 @@ public open class KScienceProjectPlugin : Plugin<Project> {
val name = subproject.name val name = subproject.name
val path = subproject.path.replaceFirst(":", "").replace(":", "/") val path = subproject.path.replaceFirst(":", "").replace(":", "/")
val ext = subproject.extensions.findByType<KScienceReadmeExtension>() val ext = subproject.extensions.findByType<KScienceReadmeExtension>()
appendLine("<hr/>") appendLine("\n### [$name]($path)")
appendLine("\n* ### [$name]($path)")
if (ext != null) { if (ext != null) {
appendLine("> ${ext.description}") appendLine("> ${ext.description}")
appendLine(">\n> **Maturity**: ${ext.maturity}") appendLine(">\n> **Maturity**: ${ext.maturity}")
@ -240,7 +243,6 @@ public open class KScienceProjectPlugin : Plugin<Project> {
} }
} }
} }
appendLine("<hr/>")
} }
rootReadmeExtension.property("modules", modulesString) rootReadmeExtension.property("modules", modulesString)