Skip to content

Commit

Permalink
Add publication version assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
kamildoleglo committed Mar 15, 2021
1 parent 29e052a commit 05ae0ef
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ enum class DokkaPublicationChannel {
else -> false
}

val acceptedDokkaVersionTypes: List<DokkaVersionType>
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
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/org/jetbrains/DokkaVersionType.kt
Original file line number Diff line number Diff line change
@@ -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())
}
12 changes: 12 additions & 0 deletions buildSrc/src/main/kotlin/org/jetbrains/publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fun Project.registerDokkaArtifactPublication(publicationName: String, configure:
}
}

assertPublicationVersion()
configureBintrayPublicationIfNecessary(publicationName)
configureSpacePublicationIfNecessary(publicationName)
configureSonatypePublicationIfNecessary(publicationName)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 05ae0ef

Please sign in to comment.