diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml new file mode 100644 index 0000000..7a5fd97 --- /dev/null +++ b/.github/workflows/Test.yml @@ -0,0 +1,33 @@ +name: Release + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: write + +jobs: + test: + strategy: + matrix: + os: [macos-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} + if: github.repository == 'ttypic/swift-klib-plugin' + timeout-minutes: 25 + + steps: + - uses: actions/checkout@v4 + - uses: gradle/wrapper-validation-action@v2 + - uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + check-latest: true + + - name: Run tests + run: ./gradlew test diff --git a/plugin/src/main/kotlin/io/github/ttypic/swiftklib/gradle/SwiftKlibPlugin.kt b/plugin/src/main/kotlin/io/github/ttypic/swiftklib/gradle/SwiftKlibPlugin.kt index 161a8b9..9c93385 100644 --- a/plugin/src/main/kotlin/io/github/ttypic/swiftklib/gradle/SwiftKlibPlugin.kt +++ b/plugin/src/main/kotlin/io/github/ttypic/swiftklib/gradle/SwiftKlibPlugin.kt @@ -7,6 +7,7 @@ import org.gradle.api.Project import org.gradle.api.model.ObjectFactory import org.gradle.configurationcache.extensions.capitalized import org.jetbrains.kotlin.gradle.tasks.CInteropProcess +import org.jetbrains.kotlin.konan.target.HostManager const val EXTENSION_NAME = "swiftklib" @@ -22,6 +23,11 @@ class SwiftKlibPlugin : Plugin { project.extensions.add(EXTENSION_NAME, swiftKlibEntries) + if (!HostManager.hostIsMac) { + logger.warn("Current host OS is not macOS. Disabling SwiftKlib plugin") + return + } + swiftKlibEntries.all { entry -> val name: String = entry.name diff --git a/plugin/src/test/kotlin/io/github/ttypic/swiftklib/gradle/CinteropModulesTest.kt b/plugin/src/test/kotlin/io/github/ttypic/swiftklib/gradle/CinteropModulesTest.kt index 6cc15c5..dd1d6a5 100644 --- a/plugin/src/test/kotlin/io/github/ttypic/swiftklib/gradle/CinteropModulesTest.kt +++ b/plugin/src/test/kotlin/io/github/ttypic/swiftklib/gradle/CinteropModulesTest.kt @@ -2,12 +2,15 @@ package io.github.ttypic.swiftklib.gradle import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldContain import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner import org.gradle.testkit.runner.TaskOutcome import org.intellij.lang.annotations.Language +import org.junit.jupiter.api.Assumptions.assumeTrue import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.junit.jupiter.api.condition.OS import org.junit.jupiter.api.io.TempDir import java.io.File @@ -35,6 +38,8 @@ class CinteropModulesTest { @Test fun `build with imported UIKit framework is successful`() { + assumeMacos() + testBuild( swiftCode = """ import UIKit @@ -53,11 +58,28 @@ class CinteropModulesTest { } } + + @Test + fun `build on linux results in warning about unsupported OS`() { + assumeLinux() + testBuild { + output.shouldContain("Current host OS is not macOS. Disabling SwiftKlib plugin") + } + } + + private fun assumeMacos() { + assumeTrue(OS.MAC.isCurrentOs) + } + + private fun assumeLinux() { + assumeTrue(OS.LINUX.isCurrentOs) + } + private fun testBuild( @Language("swift") - swiftCode: String, + swiftCode: String? = null, @Language("kotlin") - kotlinCode: String = "", + kotlinCode: String? = null, swiftklibName: String = "test", swiftklibPackage: String = "test", asserter: BuildResult.() -> Unit, @@ -120,8 +142,12 @@ class CinteropModulesTest { swiftLocation.mkdirs() kotlinLocation.mkdirs() - swiftCodeFile.writeText(swiftCode) - kotlinCodeFile.writeText(kotlinCode) + if (swiftCode != null) { + swiftCodeFile.writeText(swiftCode) + } + if (kotlinCode != null) { + kotlinCodeFile.writeText(kotlinCode) + } GradleRunner.create() .withProjectDir(testProjectDir)