Skip to content

Feature/cm 1212/add jvm target #43

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 9 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ "main" ]
pull_request:
branches: '*'
workflow_dispatch:

env:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
run: chmod +x gradlew

- name: Publish to Repository
run: ./gradlew :ychat:clean publishReleasePublicationToYChatRepository
run: ./gradlew :ychat:clean publish

env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD}}
MEMORY_KEY: ${{ secrets.MEMORY_KEY}}
SIGNINGKEY: ${{ secrets.SIGNINGKEY}}
SIGNINGPASSWORD: ${{ secrets.SIGNINGPASSWORD}}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_PASSWORD}}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MEMORY_KEY}}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNINGKEY}}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNINGPASSWORD}}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
//trick: for the same plugin versions in all sub-modules
id("com.android.application").version(Versions.GRADLE_PLUGIN).apply(false)
id("com.android.library").version(Versions.GRADLE_PLUGIN).apply(false)
id("com.vanniktech.maven.publish").version(Versions.PUBLISH_PLUGIN).apply(false)
id("io.gitlab.arturbosch.detekt").version(Versions.DETEKT_PLUGIN).apply(false)
id("org.jlleitschuh.gradle.ktlint").version(Versions.KTLINT_PLUGIN).apply(false)
id("org.jetbrains.kotlinx.kover").version(Versions.KOVER_PLUGIN).apply(false)
Expand Down
9 changes: 6 additions & 3 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
object Versions {
const val GRADLE_PLUGIN = "7.3.0"
const val DOKKA_PLUGIN = "1.7.20"
const val SPM_PLUGIN = "2.0.3"
const val DETEKT_PLUGIN = "1.22.0"
const val KTLINT_PLUGIN = "11.0.0"
const val KOVER_PLUGIN = "0.6.1"
const val PUBLISH_PLUGIN = "0.24.0"
const val KOTLIN = "1.7.20"
const val COMPOSE = "1.3.3"
const val COMPOSE_FOUNDATION = "1.3.1"
Expand All @@ -14,7 +14,8 @@ object Versions {
const val KTOR = "2.2.2"
const val KOIN = "3.2.0"
const val MATERIAL_DESIGN = "1.6.1"
const val MOCKK = "1.12.3"
const val MOCKK = "1.13.4"
const val MOCKK_COMMON = "1.12.5"
}

object Dependencies {
Expand All @@ -26,6 +27,7 @@ object Dependencies {
const val KTOR_LOGGING = "io.ktor:ktor-client-logging:${Versions.KTOR}"
const val KTOR_ANDROID = "io.ktor:ktor-client-android:${Versions.KTOR}"
const val KTOR_IOS = "io.ktor:ktor-client-ios:${Versions.KTOR}"
const val KTOR_JAVA = "io.ktor:ktor-client-java:${Versions.KTOR}"
}

object DI {
Expand All @@ -47,8 +49,9 @@ object Dependencies {
}

object Test {
const val MOCKK_COMMON = "io.mockk:mockk-common:${Versions.MOCKK}"
const val MOCKK_COMMON = "io.mockk:mockk-common:${Versions.MOCKK_COMMON}"
const val MOCKK = "io.mockk:mockk:${Versions.MOCKK}"
const val MOCKK_JVM = "io.mockk:mockk-jvm:${Versions.MOCKK}"
const val KTOR = "io.ktor:ktor-client-mock:${Versions.KTOR}"
const val KOIN = "io.insert-koin:koin-test:${Versions.KOIN}"
}
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/spm-tasks.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ tasks.register("checkSwiftPackageVersion") {
group = "Multiplatform-swift-package"
description = "Checks if the Swift package has the updated version by comparing it with the current library version."
doLast {
val iosLibraryName = properties["library.ios.name"]
val libraryVersion = properties["library.version"]
val iosLibraryName = properties["IOS_NAME"]
val libraryVersion = properties["VERSION_NAME"]
val iosPackage = "$iosLibraryName-$libraryVersion.zip"
val filePath = File(rootProject.rootDir, iosPackage)
if (!filePath.exists()) {
Expand Down
30 changes: 25 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
#Kotlin
# Kotlin
kotlin.code.style=official

#Android
# Android
android.useAndroidX=true
android.nonTransitiveRClass=true

#MPP
# MPP
kotlin.mpp.enableCInteropCommonization=true

library.version=1.0.0
library.ios.name=YChat
# Lib
GROUP=co.yml
POM_ARTIFACT_ID=ychat
VERSION_NAME=1.0.0
IOS_NAME=YChat

# OSS
SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true

# POM
POM_NAME=YChat
POM_DESCRIPTION=YChat SDK is kotlin multiplatform library for chat gpt apis.
POM_URL=https://github.com/yml-org/ychat

POM_LICENCE_NAME=The Apache License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo

POM_SCM_URL=https://github.com/yml-org/ychat
POM_SCM_CONNECTION=scm:git:git://github.com/yml-org/ychat.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com:yml-org/ychat.git
110 changes: 29 additions & 81 deletions ychat/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization").version(Versions.KOTLIN)
id("org.jetbrains.dokka").version(Versions.DOKKA_PLUGIN)
id("com.chromaticnoise.multiplatform-swiftpackage").version(Versions.SPM_PLUGIN)
id("com.vanniktech.maven.publish")
id("com.android.library")
id("maven-publish")
id("signing")
id("io.gitlab.arturbosch.detekt")
id("org.jlleitschuh.gradle.ktlint")
id("org.jetbrains.kotlinx.kover")
Expand All @@ -24,8 +22,8 @@ kover {
}
}

val iosLibraryName = properties["library.ios.name"].toString()
version = properties["library.version"].toString()
val iosLibraryName = properties["IOS_NAME"].toString()
version = properties["VERSION_NAME"].toString()

multiplatformSwiftPackage {
packageName(iosLibraryName)
Expand All @@ -38,7 +36,7 @@ multiplatformSwiftPackage {

kotlin {
android()

jvm()
listOf(
iosX64(),
iosArm64(),
Expand Down Expand Up @@ -98,6 +96,16 @@ kotlin {
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
val jvmMain by getting {
dependencies {
implementation(Dependencies.Network.KTOR_JAVA)
}
}
val jvmTest by getting {
dependencies {
implementation(Dependencies.Test.MOCKK_JVM)
}
}
}
}

Expand All @@ -110,84 +118,24 @@ android {
}
}

val dokkaOutputDir = "$buildDir/dokka"

tasks.dokkaHtml {
outputDirectory.set(file(dokkaOutputDir))
}

val deleteDokkaOutputDir by tasks.register<Delete>("deleteDokkaOutputDirectory") {
delete(dokkaOutputDir)
}
val javadocJar = tasks.register<Jar>("javadocJar") {
dependsOn(deleteDokkaOutputDir, tasks.dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaOutputDir)
}

publishing {
repositories {
maven {
name = "YChat"
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
username = project.findProperty("mavenCentralUsername")?.toString() ?: System.getenv("MAVEN_USERNAME")
password = project.findProperty("mavenCentralPassword")?.toString() ?: System.getenv("MAVEN_PASSWORD")
mavenPublishing {
pom {
developers {
developer {
id.set("osugikoji")
name.set("Koji Osugi")
url.set("https://github.com/osugikoji")
}
}
}
publications {
register<MavenPublication>("release") {
groupId = "co.yml"
artifactId = "ychat"
version = properties["library.version"].toString()
afterEvaluate {
from(components["release"])
developer {
id.set("renatoarg")
name.set("Renato Goncalves")
url.set("https://github.com/renatoarg")
}
artifact(javadocJar)
pom {
name.set("YChat")
description.set("YChat SDK is kotlin multiplatform library for chat gpt apis.")
url.set("https://github.com/yml-org/ychat")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("osugikoji")
name.set("Koji Osugi")
url.set("https://github.com/osugikoji")
}
developer {
id.set("renatoarg")
name.set("Renato Goncalves")
url.set("https://github.com/renatoarg")
}
developer {
id.set("kikoso")
name.set("Enrique López Mañas")
url.set("https://github.com/kikoso")
}
}
scm {
url.set("https://github.com/yml-org/ychat")
connection.set("scm:git:git://github.com/yml-org/ychat.git")
developerConnection.set("scm:git:ssh://git@github.com:yml-org/ychat.git")
}
developer {
id.set("kikoso")
name.set("Enrique López Mañas")
url.set("https://github.com/kikoso")
}
}
}
}

signing {
useInMemoryPgpKeys(
project.findProperty("signing.keyId")?.toString() ?: System.getenv("SIGNINGKEY"),
project.findProperty("signing.InMemoryKey")?.toString() ?: System.getenv("MEMORY_KEY"),
project.findProperty("signing.password")?.toString() ?: System.getenv("SIGNINGPASSWORD")
)
sign(publishing.publications)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import co.yml.ychat.di.provider.NetworkProvider
import co.yml.ychat.domain.usecases.CompletionUseCase
import co.yml.ychat.entrypoint.features.Completion
import co.yml.ychat.entrypoint.impl.CompletionImpl
import kotlinx.coroutines.Dispatchers
import org.koin.core.module.Module
import org.koin.dsl.module

Expand All @@ -17,7 +18,7 @@ internal class LibraryModule(private val apiKey: String) {
entrypointModule + domainModule + dataModule + platformModule()

private val entrypointModule = module {
factory<Completion> { CompletionImpl(get()) }
factory<Completion> { CompletionImpl(Dispatchers.Default, get()) }
}

private val domainModule = module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import co.yml.ychat.YChat
import co.yml.ychat.domain.model.CompletionParams
import co.yml.ychat.domain.usecases.CompletionUseCase
import co.yml.ychat.entrypoint.features.Completion
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch

internal class CompletionImpl(private val completionUseCase: CompletionUseCase) : Completion {
internal class CompletionImpl(
private val dispatcher: CoroutineDispatcher,
private val completionUseCase: CompletionUseCase
) : Completion {

private val scope by lazy { CoroutineScope(SupervisorJob() + dispatcher) }

private var params: CompletionParams = CompletionParams()

Expand Down Expand Up @@ -50,7 +57,7 @@ internal class CompletionImpl(private val completionUseCase: CompletionUseCase)
}

override fun execute(callback: YChat.Callback<String>) {
MainScope().launch {
scope.launch {
runCatching { execute() }
.onSuccess { callback.onSuccess(it) }
.onFailure { callback.onError(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package co.yml.ychat.di.module

import io.ktor.client.engine.java.Java
import org.koin.dsl.module

internal actual fun platformModule() = module {
single { Java.create() }
}