Skip to content

Commit

Permalink
fix(publish): regex doesn't match double digit releases (#283)
Browse files Browse the repository at this point in the history
* update

* update

* update

* test

* formatting

* Update upload-artifacts.yml

* Update upload-artifacts.yml

* Update .craft.yml

* clean up
  • Loading branch information
buenaflor authored Oct 15, 2024
1 parent a8cebc1 commit bcd7a1b
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ targets:
mavenRepoUrl: https://oss.sonatype.org/service/local/staging/deploy/maven2/
android:
distDirRegex: /^(sentry-android-|.*-android).*$/
fileReplaceeRegex: /\d\.\d\.\d(-\w+(\.\d)?)?(-SNAPSHOT)?/
fileReplaceeRegex: /\d+\.\d+\.\d+(-\w+(\.\d+)?)?(-SNAPSHOT)?/
fileReplacerStr: release.aar
kmp:
rootDistDirRegex: /^(?!.*(?:jvm|android|ios|watchos|tvos|macos)).*$/
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/upload-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
cd sentry-kotlin-multiplatform-gradle-plugin
./gradlew distZip sentryPluginMarkerDistZip
- name: Validate distributions
run: |
./gradlew validateDistributions
- name: Archive packages
uses: actions/upload-artifact@v4
with:
Expand Down
100 changes: 97 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import com.diffplug.spotless.LineEnding
import com.vanniktech.maven.publish.MavenPublishPlugin
import com.vanniktech.maven.publish.MavenPublishPluginExtension
import io.gitlab.arturbosch.detekt.Detekt
import java.util.zip.ZipFile

plugins {
id(Config.gradleMavenPublishPlugin).version(Config.gradleMavenPublishPluginVersion)
Expand All @@ -15,7 +16,8 @@ plugins {
id(Config.BuildPlugins.buildConfig).version(Config.BuildPlugins.buildConfigVersion).apply(false)
kotlin(Config.kotlinSerializationPlugin).version(Config.kotlinVersion).apply(false)
id(Config.QualityPlugins.kover).version(Config.QualityPlugins.koverVersion).apply(false)
id(Config.QualityPlugins.binaryCompatibility).version(Config.QualityPlugins.binaryCompatibilityVersion).apply(false)
id(Config.QualityPlugins.binaryCompatibility).version(Config.QualityPlugins.binaryCompatibilityVersion)
.apply(false)
}

allprojects {
Expand All @@ -39,8 +41,8 @@ subprojects {
val distributionFilePath =
"${this.project.buildDir}${sep}distributions${sep}${this.project.name}-${this.project.version}.zip"
val file = File(distributionFilePath)
if (!file.exists()) throw IllegalStateException("Distribution file: $distributionFilePath does not exist")
if (file.length() == 0L) throw IllegalStateException("Distribution file: $distributionFilePath is empty")
if (!file.exists()) throw GradleException("Distribution file: $distributionFilePath does not exist")
if (file.length() == 0L) throw GradleException("Distribution file: $distributionFilePath is empty")
}
}

Expand All @@ -61,6 +63,98 @@ subprojects {
}
}

tasks.register("validateDistributions") {
subprojects {
val subproject = this@subprojects
if (subproject.name == "sentry-kotlin-multiplatform") {
subproject.validateKotlinMultiplatformCoreArtifacts()
}
}
}

private fun Project.validateKotlinMultiplatformCoreArtifacts() {
val distributionDir = project.layout.buildDirectory.dir("distributions").get().asFile
val expectedNumOfFiles = 15
val filesList = distributionDir.listFiles()
val actualNumOfFiles = filesList?.size ?: 0

if (actualNumOfFiles == expectedNumOfFiles) {
println("✅ Found $actualNumOfFiles distribution files as expected.")
} else {
throw GradleException("❌ Expected $expectedNumOfFiles distribution files, but found $actualNumOfFiles")
}

val baseFileName = "sentry-kotlin-multiplatform"
val platforms = listOf(
"watchosx64", "watchossimulatorarm64", "watchosarm64", "watchosarm32",
"tvosx64", "tvossimulatorarm64", "tvosarm64",
"macosx64", "macosarm64",
"jvm",
"iosx64", "iossimulatorarm64", "iosarm64",
"android"
)

val artifactPaths = buildList {
add(distributionDir.resolve("$baseFileName-$version.zip"))
addAll(
platforms.map { platform ->
distributionDir.resolve("$baseFileName-$platform-$version.zip")
}
)
}

val commonRequiredEntries = listOf(
"javadoc",
"sources",
"module",
"pom-default.xml"
)

artifactPaths.forEach { artifactFile ->
if (!artifactFile.exists()) {
throw GradleException("❌ Artifact file: ${artifactFile.path} does not exist")
}
if (artifactFile.length() == 0L) {
throw GradleException("❌ Artifact file: ${artifactFile.path} is empty")
}

ZipFile(artifactFile).use { zip ->
val entries = zip.entries().asSequence().map { it.name }.toList()

commonRequiredEntries.forEach { requiredEntry ->
if (entries.none { it.contains(requiredEntry) }) {
throw GradleException("$requiredEntry not found in ${artifactFile.name}")
} else {
println("✅ Found $requiredEntry in ${artifactFile.name}")
}
}

when {
artifactFile.name.contains("ios", ignoreCase = true) ||
artifactFile.name.contains("macos", ignoreCase = true) ||
artifactFile.name.contains("watchos", ignoreCase = true) ||
artifactFile.name.contains("tvos", ignoreCase = true) -> {
val expectedNumOfKlibFiles = 3
val actualKlibFiles = entries.count { it.contains("klib") }
if (actualKlibFiles != expectedNumOfKlibFiles) {
throw GradleException("❌ Expected $expectedNumOfKlibFiles klib files in ${artifactFile.name}, but found $actualKlibFiles")
} else {
println("✅ Found $expectedNumOfKlibFiles klib files in ${artifactFile.name}")
}
}

artifactFile.name.contains("android", ignoreCase = true) -> {
if (entries.none { it.contains("aar") }) {
throw GradleException("❌ aar file not found in ${artifactFile.name}")
} else {
println("✅ Found aar file in ${artifactFile.name}")
}
}
}
}
}
}

subprojects {
if (project.name.contains("sentry-kotlin-multiplatform")) {
apply(plugin = Config.dokka)
Expand Down

0 comments on commit bcd7a1b

Please sign in to comment.