diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..88e4e0e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,33 @@ +name: Publish + +on: + push: + tags: [ 'v*' ] + branches: [ 'main', 'publishing' ] + +env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + +jobs: + publish: + strategy: + matrix: + runner: [ubuntu-latest, macos-latest, windows-latest] + + name: 'Publish: ${{ matrix.runner }}' + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + + - name: Publish to Maven + run: ./gradlew ciPublish diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4232662 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: Test + +on: [ push, pull_request ] + +jobs: + publish: + strategy: + matrix: + runner: [ ubuntu-latest, macos-latest, windows-latest ] + + name: 'Test: ${{ matrix.runner }}' + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + + - name: Test + run: ./gradlew ciTest diff --git a/README.md b/README.md index 6ce6039..c51bca1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Parameterize -[![Maven Central](https://img.shields.io/maven-central/v/com.benwoodworth.parameterize/parameterize)](https://search.maven.org/artifact/com.benwoodworth.parameterize/parameterize) -[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/com.benwoodworth.parameterize/parameterize?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://s01.oss.sonatype.org/content/repositories/snapshots/com/benwoodworth/parameterize/parameterize/) +[![Maven Central](https://img.shields.io/maven-central/v/com.benwoodworth.parameterize/parameterize)](https://search.maven.org/search?q=g:com.benwoodworth.parameterize) +[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/com.benwoodworth.parameterize/parameterize?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://s01.oss.sonatype.org/content/repositories/snapshots/com/benwoodworth/parameterize/) [![KDoc](https://img.shields.io/badge/api-KDoc-blue)](https://benwoodworth.github.io/parameterize) -[![Kotlin](https://img.shields.io/badge/kotlin-1.9.10-blue.svg?logo=kotlin)](http://kotlinlang.org) +[![Kotlin](https://img.shields.io/badge/kotlin-1.9.0-blue.svg?logo=kotlin)](http://kotlinlang.org) [![Slack channel](https://img.shields.io/badge/chat-slack-blue.svg?logo=slack)](https://kotlinlang.slack.com/messages/parameterize/) Parameterize is a multiplatform Kotlin library that brings a concise syntax for parameterizing code. diff --git a/build.gradle.kts b/build.gradle.kts index 519207c..f7ab0b2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,7 @@ +import org.gradle.kotlin.dsl.support.uppercaseFirstChar +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests + plugins { kotlin("multiplatform") version "1.9.0" id("parameterize.library-conventions") @@ -7,8 +11,10 @@ repositories { mavenCentral() } +@OptIn(ExperimentalKotlinGradlePluginApi::class) kotlin { explicitApi() + targetHierarchy.default() jvm { compilations.all { @@ -22,15 +28,27 @@ kotlin { browser() nodejs() } - val hostOs = System.getProperty("os.name") - val isMingwX64 = hostOs.startsWith("Windows") - val nativeTarget = when { - hostOs == "Mac OS X" -> macosX64("native") - hostOs == "Linux" -> linuxX64("native") - isMingwX64 -> mingwX64("native") - else -> throw GradleException("Host OS is not supported in Kotlin/Native.") - } + linuxX64() + linuxArm64() + androidNativeArm32() + androidNativeArm64() + androidNativeX86() + androidNativeX64() + macosX64() + macosArm64() + iosSimulatorArm64() + iosX64() + watchosSimulatorArm64() + watchosX64() + watchosArm32() + watchosArm64() + tvosSimulatorArm64() + tvosX64() + tvosArm64() + iosArm64() + watchosDeviceArm64() + mingwX64() sourceSets { val commonMain by getting @@ -39,11 +57,60 @@ kotlin { implementation(kotlin("test")) } } - val jvmMain by getting - val jvmTest by getting - val jsMain by getting - val jsTest by getting - val nativeMain by getting - val nativeTest by getting } } + +val ciHostTargets = run { + val hostTargetPrefixes = mapOf( + "linux" to listOf("metadata", "jvm", "js", "linux", "android"), + "macos" to listOf("macos", "ios", "watchos", "tvos"), + "windows" to listOf("mingw") + ) + + val hostTargets = hostTargetPrefixes.mapValues { (_, prefixes) -> + kotlin.targets.filter { target -> + prefixes.any { target.name.startsWith(it) } + } + } + + val envCiHost = System.getenv("CI_HOST") + val osName = System.getProperty("os.name") + val host = when { + envCiHost != null -> envCiHost.also { + require(envCiHost in hostTargets) { "Invalid CI_HOST: $envCiHost. Must be one of: ${hostTargets.keys}" } + } + osName == "Linux" -> "linux" + osName == "Mac OS X" -> "macos" + osName.startsWith("Windows") -> "windows" + else -> error("Unable to determine CI Host for OS: $osName. CI_HOST env can be set instead.") + } + + // Check for non-existent, unaccounted for, or double-counted targets + val allTargets = kotlin.targets.map { it.name }.sorted() + val groupedTargets = hostTargets.values.flatten().map { it.name }.sorted() + check(groupedTargets == allTargets) { + "Bad host target grouping.\n\tExpected: $allTargets\n\tActual: $groupedTargets" + } + + hostTargets[host]!!.asSequence() +} + +tasks.create("ciTest") { + ciHostTargets + .filterIsInstance>() + .map { target -> "${target.name}Test" } + .forEach { targetTest -> + dependsOn(targetTest) + } +} + +tasks.create("ciPublish") { + ciHostTargets + .map { it.name.uppercaseFirstChar() } + .filter { !it.startsWith("Android") } + .map { if (it == "Metadata") "KotlinMultiplatform" else it } + .map { target -> "publish${target}PublicationToMavenRepository" } + .forEach { publishTarget -> + dependsOn(publishTarget) + } +} diff --git a/gradle.properties b/gradle.properties index ea4ea31..e6e955c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,3 +3,4 @@ version=0.1-SNAPSHOT kotlin.code.style=official kotlin.js.compiler=ir +kotlin.native.ignoreDisabledTargets=true