From 05ae0ef138bbc93668c01385743d6a132845f442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Doleg=C5=82o?= Date: Mon, 22 Feb 2021 16:33:32 +0100 Subject: [PATCH] Add publication version assertion --- .../kotlin/org/jetbrains/DokkaPublicationChannel.kt | 10 ++++++++++ .../src/main/kotlin/org/jetbrains/DokkaVersion.kt | 4 ++++ .../main/kotlin/org/jetbrains/DokkaVersionType.kt | 5 +++++ .../src/main/kotlin/org/jetbrains/publication.kt | 12 ++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt index 853267f742..c4f22a9083 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt @@ -26,6 +26,16 @@ enum class DokkaPublicationChannel { else -> false } + val acceptedDokkaVersionTypes: List + get() = when(this) { + MavenCentral -> listOf(DokkaVersionType.Release) + MavenCentralSnapshot -> listOf(DokkaVersionType.Snapshot) + SpaceDokkaDev -> listOf(DokkaVersionType.Release, DokkaVersionType.Dev, DokkaVersionType.MC, DokkaVersionType.Snapshot) + BintrayKotlinDev -> listOf(DokkaVersionType.Dev, DokkaVersionType.MC, DokkaVersionType.Snapshot) + BintrayKotlinEap -> listOf(DokkaVersionType.MC) + BintrayKotlinDokka -> listOf(DokkaVersionType.Release) + } + companion object { fun fromPropertyString(value: String): DokkaPublicationChannel = when (value) { "space-dokka-dev" -> SpaceDokkaDev diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt index 2a5c21a73f..3ee348c017 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt @@ -24,3 +24,7 @@ private fun dokkaVersionFromBase(baseVersion: String): String { val Project.dokkaVersion: String get() = configureDokkaVersion() + +val Project.dokkaVersionType: DokkaVersionType + get() = DokkaVersionType.values().find { it.suffix.matches(dokkaVersion.substringAfter("-")) } + ?: throw IllegalStateException("Unrecognized version type: $dokkaVersion") diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt new file mode 100644 index 0000000000..dbf2d31264 --- /dev/null +++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt @@ -0,0 +1,5 @@ +package org.jetbrains + +enum class DokkaVersionType(val suffix: Regex) { + Release("^$".toRegex()), Snapshot("SNAPSHOT".toRegex()), Dev("dev-\\d+".toRegex()), MC("mc-\\d+".toRegex()) +} diff --git a/buildSrc/src/main/kotlin/org/jetbrains/publication.kt b/buildSrc/src/main/kotlin/org/jetbrains/publication.kt index 44ced34eb0..9187c5a209 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/publication.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/publication.kt @@ -40,6 +40,7 @@ fun Project.registerDokkaArtifactPublication(publicationName: String, configure: } } + assertPublicationVersion() configureBintrayPublicationIfNecessary(publicationName) configureSpacePublicationIfNecessary(publicationName) configureSonatypePublicationIfNecessary(publicationName) @@ -152,6 +153,17 @@ private fun Project.configureSonatypePublication(vararg publications: String) { } } +private fun Project.assertPublicationVersion() { + if (System.getenv("SKIP_VERSION_CHECK")?.contains("true", ignoreCase = true) == true) + return + + if (!publicationChannels.all { publicationChannel -> + publicationChannel.acceptedDokkaVersionTypes.any { acceptedVersionType -> + acceptedVersionType == dokkaVersionType + } + }) { throw AssertionError("Wrong version $dokkaVersion for configured publication channels $publicationChannels") } +} + fun MavenPublication.configurePom(projectName: String) { pom { name.set(projectName)