Skip to content

Commit

Permalink
Add: Github actions for running ios build and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acrusage-iaik committed Apr 29, 2024
1 parent b91bf8e commit aa2186f
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 32 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build iOS Framework
on: workflow_dispatch
jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Build klibs
run: ./gradlew iosArm64MainKlibrary iosX64MainKlibrary
- name: Build XCFrameworks
run: ./gradlew assembleJsonPathXCFramework
- name: Upload debug XCFramework jsonpath
uses: actions/upload-artifact@v3
with:
name: JsonPath-debug.xcframework
path: |
jsonpath/build/XCFrameworks/debug/
- name: Upload release XCFramework jsonpath
uses: actions/upload-artifact@v3
with:
name: JsonPath-release.xcframework
path: |
jsonpath/build/XCFrameworks/release/
25 changes: 25 additions & 0 deletions .github/workflows/test-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test iOS implementation
on: [push]
jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Build klibs
run: ./gradlew iosArm64MainKlibrary iosX64MainKlibrary
- name: Run tests
run: ./gradlew iosX64Test
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: jsonpath Tests
path: jsonpath/build/test-results/**/TEST*.xml
reporter: java-junit
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

Release 1.0.0:
- Add `JsonPathDependencyManager`: Dependency manager for the library
- Add `JsonPathFunctionExtensionRepository`: Give users a way to add custom function extensions
- Add `JsonPath`: JsonPath compiler and query functionality

1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kotest = "5.8.1"
jetbrains-kotlin = "1.9.23"
jetbrains-kotlinx-serialization = "1.6.3"
jetbrains-dokka = "1.9.20"
napier-version = "2.7.1"


[libraries]
Expand Down
102 changes: 70 additions & 32 deletions jsonpath/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import com.strumenta.antlrkotlin.gradle.AntlrKotlinTask
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyTransformationTask
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkConfig

plugins {
alias(libs.plugins.jetbrains.kotlin.multiplatform)
Expand Down Expand Up @@ -56,35 +61,7 @@ kotlin {
}
}

/**
* taken from vclib conventions plugin at https://github.com/a-sit-plus/gradle-conventions-plugin
*/
fun Project.setupDokka(
outputDir: String = layout.buildDirectory.dir("dokka").get().asFile.canonicalPath,
baseUrl: String,
multiModuleDoc: Boolean = false,
remoteLineSuffix: String = "#L"
): TaskProvider<Jar> {
val dokkaHtml = (tasks["dokkaHtml"] as DokkaTask).apply { outputDirectory.set(file(outputDir)) }

val deleteDokkaOutput = tasks.register<Delete>("deleteDokkaOutputDirectory") {
delete(outputDir)
}
val sourceLinktToConfigure = if (multiModuleDoc) (tasks["dokkaHtmlPartial"] as DokkaTaskPartial) else dokkaHtml
sourceLinktToConfigure.dokkaSourceSets.configureEach {
sourceLink {
localDirectory.set(file("src/$name/kotlin"))
remoteUrl.set(uri("$baseUrl/${project.name}/src/$name/kotlin").toURL())
this@sourceLink.remoteLineSuffix.set(remoteLineSuffix)
}
}

return tasks.register<Jar>("javadocJar") {
dependsOn(deleteDokkaOutput, dokkaHtml)
archiveClassifier.set("javadoc")
from(outputDir)
}
}
exportIosFramework("JsonPath")

val javadocJar = setupDokka(
baseUrl = "https://github.com/a-sit-plus/jsonpath/tree/main/",
Expand Down Expand Up @@ -150,9 +127,7 @@ val generateKotlinGrammarSource = tasks.register<AntlrKotlinTask>("generateKotli
dependsOn(tasks.withType<ProcessResources>())
dependsOn(tasks.withType<MetadataDependencyTransformationTask>())

// ANTLR .g4 files are under {example-project}/antlr
// Only include *.g4 files. This allows tools (e.g., IDE plugins)
// to generate temporary files inside the base path
// compiling any *.g4 files within the project
source = fileTree(layout.projectDirectory) {
include("**/*.g4")
}
Expand All @@ -176,4 +151,67 @@ tasks.withType<KotlinCompile<*>> {

tasks.named<Test>("jvmTest") {
useJUnitPlatform()
}




/**
* taken from vclib conventions plugin at https://github.com/a-sit-plus/gradle-conventions-plugin
*/
fun Project.exportIosFramework(
name: String,
vararg additionalExports: Any
) = exportIosFramework(name, bitcodeEmbeddingMode = BitcodeEmbeddingMode.BITCODE, additionalExports = additionalExports)

fun Project.exportIosFramework(
name: String,
bitcodeEmbeddingMode: BitcodeEmbeddingMode,
vararg additionalExports: Any
) {
val iosTargets = kotlinExtension.let {
if (it is KotlinMultiplatformExtension) {
it.targets.filterIsInstance<KotlinNativeTarget>().filter { it.name.startsWith("ios") }
} else throw StopExecutionException("No iOS Targets found! Declare them explicitly before calling exportIosFramework!")
}

extensions.getByType<KotlinMultiplatformExtension>().apply {
XCFrameworkConfig(project, name).also { xcf ->
logger.lifecycle(" \u001B[1mXCFrameworks will be exported for the following iOS targets: ${iosTargets.joinToString { it.name }}\u001B[0m")
iosTargets.forEach {
it.binaries.framework {
baseName = name
embedBitcode(bitcodeEmbeddingMode)
additionalExports.forEach { export(it) }
xcf.add(this)
}
}
}
}
}
fun Project.setupDokka(
outputDir: String = layout.buildDirectory.dir("dokka").get().asFile.canonicalPath,
baseUrl: String,
multiModuleDoc: Boolean = false,
remoteLineSuffix: String = "#L"
): TaskProvider<Jar> {
val dokkaHtml = (tasks["dokkaHtml"] as DokkaTask).apply { outputDirectory.set(file(outputDir)) }

val deleteDokkaOutput = tasks.register<Delete>("deleteDokkaOutputDirectory") {
delete(outputDir)
}
val sourceLinktToConfigure = if (multiModuleDoc) (tasks["dokkaHtmlPartial"] as DokkaTaskPartial) else dokkaHtml
sourceLinktToConfigure.dokkaSourceSets.configureEach {
sourceLink {
localDirectory.set(file("src/$name/kotlin"))
remoteUrl.set(uri("$baseUrl/${project.name}/src/$name/kotlin").toURL())
this@sourceLink.remoteLineSuffix.set(remoteLineSuffix)
}
}

return tasks.register<Jar>("javadocJar") {
dependsOn(deleteDokkaOutput, dokkaHtml)
archiveClassifier.set("javadoc")
from(outputDir)
}
}

0 comments on commit aa2186f

Please sign in to comment.