Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/add nix targets #12

Merged
merged 6 commits into from
Feb 17, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build-and-publish:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/tests.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ jobs:
reporter: java-junit

- name: "Run Coverage"
run: ./gradlew codeCoverageReport
if: ${{ github.event_name == 'pull_request' }}
run: ./gradlew koverXmlReport
shell: bash

- name: "Coverage Report"
uses: madrapps/[email protected]
uses: mi-kas/kover-report@v1
if: ${{ github.event_name == 'pull_request' }}
with:
paths: ./build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml
path: |
./ktor-simple-cache/build/reports/kover/report.xml
./ktor-simple-memory-cache/build/reports/kover/report.xml
./ktor-simple-redis-cache/build/reports/kover/report.xml
token: ${{ secrets.GITHUB_TOKEN }}
title: "Coverage Report"
update-comment: true
29 changes: 1 addition & 28 deletions build.gradle.kts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
plugins {
id("jacoco-report-aggregation")
}

tasks.wrapper {
gradleVersion = "8.6"
}
Expand All @@ -10,38 +6,15 @@ allprojects {

group = "com.ucasoft.ktor"

version = "0.2.0"

apply {
plugin("jacoco")
}
version = "0.2.3"

repositories {
mavenCentral()
}

tasks.withType<Test> {
useJUnitPlatform()
reports {
junitXml.required.set(true)
}
}

jacoco {
toolVersion = "0.8.11"
}
}

dependencies {
jacocoAggregation(project(":ktor-simple-cache"))
jacocoAggregation(project(":ktor-simple-memory-cache"))
jacocoAggregation(project(":ktor-simple-redis-cache"))
}

reporting {
reports {
val codeCoverageReport by creating(JacocoCoverageReport::class) {
testType.set(TestSuiteType.UNIT_TEST)
}
}
}
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ publishing {

signing {
sign(publishing.publications)
}

tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}
4 changes: 2 additions & 2 deletions ktor-simple-cache/README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Ktor Simple Cache
Base solution which provides the plugin implementation and abstract class for cache providers.

[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-cache/0.2.0?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-cache/0.2.0/jar)
[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-cache/0.2.3?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-cache/0.2.3/jar)
## Setup
### Gradle
```kotlin
repositories {
mavenCentral()
}

implementation("com.ucasoft.ktor:ktor-simple-cache:0.2.0")
implementation("com.ucasoft.ktor:ktor-simple-cache:0.2.3")
```
## Usage
```kotlin
Expand Down
8 changes: 7 additions & 1 deletion ktor-simple-cache/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization") apply false
id("org.jetbrains.kotlinx.kover")
id("publish")
}

kotlin {
jvm {
jvmToolchain(11)
tasks.withType<Test> {
useJUnitPlatform()
}
}
linuxX64()
macosX64()
sourceSets {
val jvmMain by getting {
val commonMain by getting {
dependencies {
implementation(ktorServer("core"))
}
Expand Down
4 changes: 2 additions & 2 deletions ktor-simple-memory-cache/README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Ktor Simple Memory Cache
Memory cache provider for Ktor Simple Cache plugin

[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-memory-cache/0.2.0?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-memory-cache/0.2.0/jar)
[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-memory-cache/0.2.3?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-memory-cache/0.2.3/jar)
## Setup
### Gradle
```kotlin
repositories {
mavenCentral()
}

implementation("com.ucasoft.ktor:ktor-simple-memory-cache:0.2.0")
implementation("com.ucasoft.ktor:ktor-simple-memory-cache:0.2.3")
```
## Usage
```kotlin
Expand Down
8 changes: 6 additions & 2 deletions ktor-simple-memory-cache/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("org.jetbrains.kotlinx.kover")
id("publish")
}

kotlin {
jvm {
jvmToolchain(11)
}
linuxX64()
macosX64()
sourceSets {
val jvmMain by getting {
val commonMain by getting {
dependencies {
implementation(project(":ktor-simple-cache"))
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")
}
kotlin.srcDir("src/main/kotlin")
}
val jvmTest by getting {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(ktorServer("test-host"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.ucasoft.ktor.simpleMemoryCache

import com.ucasoft.ktor.simpleCache.SimpleCacheConfig
import com.ucasoft.ktor.simpleCache.SimpleCacheProvider
import java.time.LocalDateTime
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlin.time.Duration

class SimpleMemoryCacheProvider(config: Config) : SimpleCacheProvider(config) {
Expand All @@ -18,17 +19,18 @@ class SimpleMemoryCacheProvider(config: Config) : SimpleCacheProvider(config) {
}
}


override suspend fun setCache(key: String, content: Any, invalidateAt: Duration?) {
cache[key] = SimpleMemoryCacheObject(content, invalidateAt ?: this.invalidateAt)
}

class Config internal constructor() : SimpleCacheProvider.Config()
}

private data class SimpleMemoryCacheObject(val content: Any, val duration: Duration, val start: LocalDateTime = LocalDateTime.now()) {
private data class SimpleMemoryCacheObject(val content: Any, val duration: Duration, val start: Instant = Clock.System.now()) {

val isExpired: Boolean
get() = LocalDateTime.now().isAfter(start.plusSeconds(duration.inWholeSeconds))
get() = Clock.System.now() - start > duration
}

fun SimpleCacheConfig.memoryCache(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.server.testing.*
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import kotlin.test.Test

internal class MemoryCacheTests {

Expand Down Expand Up @@ -67,7 +68,9 @@ internal class MemoryCacheTests {

val secondResponse = jsonClient.get("short")
secondResponse.body<TestResponse>().id.shouldBe(firstBody.id)
Thread.sleep(3000)
runBlocking {
delay(3000)
}
val thirdResponse = jsonClient.get("short")
thirdResponse.body<TestResponse>().id.shouldNotBe(firstBody.id)

Expand Down
4 changes: 2 additions & 2 deletions ktor-simple-redis-cache/README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Ktor Simple Redis Cache
Redis cache provider for Ktor Simple Cache plugin

[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-redis-cache/0.2.0?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-redis-cache/0.2.0/jar)
[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-redis-cache/0.2.3?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-redis-cache/0.2.3/jar)
## Setup
### Gradle
```kotlin
repositories {
mavenCentral()
}

implementation("com.ucasoft.ktor:ktor-simple-redis-cache:0.2.0")
implementation("com.ucasoft.ktor:ktor-simple-redis-cache:0.2.3")
```
## Usage
```kotlin
Expand Down
4 changes: 4 additions & 0 deletions ktor-simple-redis-cache/build.gradle.kts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("org.jetbrains.kotlinx.kover")
id("publish")
}

kotlin {
jvm {
jvmToolchain(11)
tasks.withType<Test> {
useJUnitPlatform()
}
}
sourceSets {
val jvmMain by getting {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pluginManagement {
val kotlinVersion = "1.9.22"
kotlin("multiplatform") version kotlinVersion apply false
kotlin("plugin.serialization") version kotlinVersion apply false
id("org.jetbrains.kotlinx.kover") version "0.7.5" apply false
}
}
}
Expand Down
Loading