Skip to content

Commit

Permalink
Add GitHub workflows for testing and publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWoodworth committed Oct 22, 2023
1 parent 977df4d commit d946291
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 17 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
95 changes: 81 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -7,8 +11,10 @@ repositories {
mavenCentral()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
explicitApi()
targetHierarchy.default()

jvm {
compilations.all {
Expand 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
Expand All @@ -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<KotlinTargetWithTests<*, *>>()
.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)
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ version=0.1-SNAPSHOT

kotlin.code.style=official
kotlin.js.compiler=ir
kotlin.native.ignoreDisabledTargets=true

0 comments on commit d946291

Please sign in to comment.