Skip to content

Commit

Permalink
Update target setup and build-test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed May 11, 2024
1 parent 8eccc90 commit 26b1935
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 46 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ jobs:
with:
distribution: 'zulu'
java-version: 21
- name: API check
run: ./gradlew apiCheck
- name: Debug build
run: ./gradlew assembleDebug --stacktrace
- name: API check
run: ./gradlew apiCheck
- name: Unit test
run: ./gradlew allTests --stacktrace
run: ./gradlew allTests test --stacktrace
env:
IS_CI_TEST: yup
- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: test-results
path: '*/build/reports/tests'
path: '*/build/reports/tests'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport

class KmpLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
Expand All @@ -17,45 +16,19 @@ class KmpLibraryConventionPlugin : Plugin<Project> {
}

configure<KotlinMultiplatformExtension> {
// Create Kotlin Multiplatform targets
applyDefaultHierarchyTemplate()

androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
}

if (target.isNotJustAndroid()) {
jvm()
iosArm64()
iosSimulatorArm64()
iosX64()
js {
browser()
nodejs()
}
linuxArm64()
linuxX64()
macosArm64()
macosX64()
tvosArm64()
tvosSimulatorArm64()
tvosX64()
wasmJs()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
watchosX64()
when {
isAndroidOnly() -> configureAndroid()
isCiTest() -> configureCiTestTargets()
else -> configureAllTargets()
}

// Create jbMain source set (all - android)
val commonMain by sourceSets.commonMain
val jbMain by sourceSets.creating {
dependsOn(commonMain)
}

targets.forEach { target ->
if (target.platformType !in listOf(KotlinPlatformType.androidJvm, KotlinPlatformType.common)) {
target.compilations.getByName("main").defaultSourceSet {
Expand All @@ -64,11 +37,11 @@ class KmpLibraryConventionPlugin : Plugin<Project> {
}
}

// Create jbTest source set (all - android)
val commonTest by sourceSets.commonTest
val jbTest by sourceSets.creating {
dependsOn(commonTest)
}

targets.forEach { target ->
if (target.platformType !in listOf(KotlinPlatformType.androidJvm, KotlinPlatformType.common)) {
target.compilations.getByName("test").defaultSourceSet {
Expand All @@ -77,13 +50,8 @@ class KmpLibraryConventionPlugin : Plugin<Project> {
}
}

val allTestsTask = tasks.findByName("allTests")
allTestsTask?.doFirst {
(allTestsTask as KotlinTestReport).ignoreFailures = true
}

// Compiler settings
explicitApi()

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.add("-progressive")
Expand All @@ -102,6 +70,53 @@ class KmpLibraryConventionPlugin : Plugin<Project> {
}
}
}
}

private fun Project.isNotJustAndroid() = hasProperty("android-only").not()
private fun KotlinMultiplatformExtension.configureAndroid() {
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
}
}

private fun KotlinMultiplatformExtension.configureCiTestTargets() {
configureAndroid()
jvm()
iosSimulatorArm64()
js {
browser()
nodejs()
}
macosArm64()
}

private fun KotlinMultiplatformExtension.configureAllTargets() {
configureAndroid()
jvm()
iosArm64()
iosSimulatorArm64()
iosX64()
js {
browser()
nodejs()
}
linuxArm64()
linuxX64()
macosArm64()
macosX64()
tvosArm64()
tvosSimulatorArm64()
tvosX64()
wasmJs()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
watchosX64()
}

private fun Project.isAndroidOnly() = hasProperty("android-only")
private fun Project.isCiTest() = System.getenv("IS_CI_TEST") != null || hasProperty("is-ci-test")
}

0 comments on commit 26b1935

Please sign in to comment.