diff --git a/.github/workflows/release_test.yml b/.github/workflows/release_test.yml new file mode 100644 index 0000000..2163ffe --- /dev/null +++ b/.github/workflows/release_test.yml @@ -0,0 +1,46 @@ +# This is a basic workflow to help you get started with Actions + +name: Release MVI Test + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + tags: + - 'test/[0-9]+.[0-9]+.[0-9]+' + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: macos-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 + uses: actions/setup-java@v2 + with: + java-version: '21' + distribution: 'temurin' + + - name: Grant Permission to Execute Gradle + run: chmod +x gradlew + + - name: Build with Gradle + uses: gradle/gradle-build-action@v2 + with: + arguments: build + + - name: Publish Library + run: | + echo "Publishing library🚀" + ./gradlew :mvi-test:publishAndReleaseToMavenCentral --no-configuration-cache + echo "Published✅" + env: + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSWORD }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} diff --git a/docs/README.md b/docs/README.md index 42b2729..f61b0a5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -22,6 +22,7 @@ Here are the current available mvi modules versions: | mvi | [![Maven Central](https://img.shields.io/maven-central/v/com.adidas.mvi/mvi)](https://mvnrepository.com/artifact/com.adidas.mvi/mvi) | | mvi-compose | [![Maven Central](https://img.shields.io/maven-central/v/com.adidas.mvi/mvi-compose)](https://mvnrepository.com/artifact/com.adidas.mvi/mvi-compose) | | mvi-kotest | [![Maven Central](https://img.shields.io/maven-central/v/com.adidas.mvi/mvi-kotest)](https://mvnrepository.com/artifact/com.adidas.mvi/mvi-kotest) | +| mvi-test | [![Maven Central](https://img.shields.io/maven-central/v/com.adidas.mvi/mvi-test)](https://mvnrepository.com/artifact/com.adidas.mvi/mvi-test) | ## Features diff --git a/mvi-kotest/src/main/kotlin/com/adidas/mvi/kotest/TestMviLogger.kt b/mvi-kotest/src/main/kotlin/com/adidas/mvi/kotest/TestMviLogger.kt index 8437a6d..2056209 100644 --- a/mvi-kotest/src/main/kotlin/com/adidas/mvi/kotest/TestMviLogger.kt +++ b/mvi-kotest/src/main/kotlin/com/adidas/mvi/kotest/TestMviLogger.kt @@ -8,6 +8,14 @@ import com.adidas.mvi.Logger * * You can access list of all logged entries from [loggedTranformations] and [loggedIntents]. */ +@Deprecated( + message = "Use the one from mvi-test package", + replaceWith = + ReplaceWith( + expression = "com.adidas.mvi.test.TestMviLogger", + "com.adidas.mvi.test.TestMviLogger", + ), +) public class TestMviLogger : Logger { public val loggedTranformations: MutableList = ArrayList() public val loggedIntents: MutableList = ArrayList() diff --git a/mvi-sample/build.gradle.kts b/mvi-sample/build.gradle.kts index 431ea85..39d308e 100644 --- a/mvi-sample/build.gradle.kts +++ b/mvi-sample/build.gradle.kts @@ -56,6 +56,7 @@ dependencies { implementation(libs.mvi) implementation(project(":mvi-compose")) + implementation(project(":mvi-test")) implementation(libs.koinCore) implementation(libs.koinAndroid) diff --git a/mvi-sample/src/test/kotlin/com/adidas/mvi/sample/login/viewmodel/LoginViewModelTest.kt b/mvi-sample/src/test/kotlin/com/adidas/mvi/sample/login/viewmodel/LoginViewModelTest.kt index f6d69e2..3e67d0a 100644 --- a/mvi-sample/src/test/kotlin/com/adidas/mvi/sample/login/viewmodel/LoginViewModelTest.kt +++ b/mvi-sample/src/test/kotlin/com/adidas/mvi/sample/login/viewmodel/LoginViewModelTest.kt @@ -1,7 +1,7 @@ package com.adidas.mvi.sample.login.viewmodel import com.adidas.mvi.kotest.GivenViewModel -import com.adidas.mvi.kotest.TestMviLogger +import com.adidas.mvi.test.TestMviLogger import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/mvi-test/.gitignore b/mvi-test/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/mvi-test/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/mvi-test/build.gradle.kts b/mvi-test/build.gradle.kts new file mode 100644 index 0000000..b4a5e06 --- /dev/null +++ b/mvi-test/build.gradle.kts @@ -0,0 +1,19 @@ +import org.jlleitschuh.gradle.ktlint.KtlintExtension + +plugins { + kotlin("jvm") version libs.versions.kotlin.get() + alias(libs.plugins.ktlint) + alias(libs.plugins.mavenPublish) +} + +kotlin { + explicitApi() +} + +configure { + version.set(libs.versions.ktlint.lib.get()) +} + +dependencies { + implementation(libs.mvi) +} diff --git a/mvi-test/src/main/kotlin/com/adidas/mvi/test/TestMviLogger.kt b/mvi-test/src/main/kotlin/com/adidas/mvi/test/TestMviLogger.kt new file mode 100644 index 0000000..cdfbb30 --- /dev/null +++ b/mvi-test/src/main/kotlin/com/adidas/mvi/test/TestMviLogger.kt @@ -0,0 +1,58 @@ +package com.adidas.mvi.test + +import com.adidas.mvi.Loggable +import com.adidas.mvi.Logger + +/** + * A fake implementation of [Logger] that remembers all logged entries, for use in tests. + * + * You can access list of all logged entries from [loggedTranformations] and [loggedIntents]. + */ +public class TestMviLogger : Logger { + public val loggedTranformations: MutableList = ArrayList() + public val loggedIntents: MutableList = ArrayList() + + override fun logFailedIntent( + intent: Loggable, + throwable: Throwable, + ) { + loggedIntents += LoggedIntent.Failure(intent, throwable) + } + + override fun logIntent(intent: Loggable) { + loggedIntents += LoggedIntent.Success(intent) + } + + override fun logFailedTransformNewState( + transform: Loggable, + state: Loggable, + throwable: Throwable, + ) { + loggedTranformations += LoggedTranformation.Failure(transform, state, throwable) + } + + override fun logTransformedNewState( + transform: Loggable, + previousState: Loggable, + newState: Loggable, + ) { + loggedTranformations += LoggedTranformation.Success(transform, previousState, newState) + } + + public sealed class LoggedIntent() { + public abstract val intent: Loggable + + public data class Success(override val intent: Loggable) : LoggedIntent() + + public data class Failure(override val intent: Loggable, val throwable: Throwable) : LoggedIntent() + } + + public sealed class LoggedTranformation() { + public abstract val transform: Loggable + public abstract val previousState: Loggable + + public data class Success(override val transform: Loggable, override val previousState: Loggable, val newState: Loggable) : LoggedTranformation() + + public data class Failure(override val transform: Loggable, override val previousState: Loggable, val throwable: Throwable) : LoggedTranformation() + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 8595f08..3b1a04b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,3 +18,4 @@ include(":mvi") include(":mvi-compose") include(":mvi-kotest") include(":mvi-sample") +include(":mvi-test")