From 3cda26d49face6ffe80f78f30dd6e7fb6bc683a0 Mon Sep 17 00:00:00 2001 From: Rajat Mittal Date: Thu, 8 Aug 2024 14:39:31 -0700 Subject: [PATCH 01/18] unit testing --- chat-sdk/build.gradle.kts | 31 +++-- .../chat/sdk/repository/ChatService.kt | 6 +- .../connect/chat/sdk/ChatSessionImpl.kt | 84 ++++++++++++ .../chat/sdk/network/AWSClientImplTest.kt | 111 ++++++++++++++++ .../sdk/repository/ChatServiceImplTest.kt | 121 ++++++++++++++++++ chat-sdk/test-summary.gradle.kts | 73 +++++++++++ gradle/libs.versions.toml | 9 ++ 7 files changed, 423 insertions(+), 12 deletions(-) create mode 100644 chat-sdk/src/test/java/com/amazon/connect/chat/sdk/ChatSessionImpl.kt create mode 100644 chat-sdk/src/test/java/com/amazon/connect/chat/sdk/network/AWSClientImplTest.kt create mode 100644 chat-sdk/src/test/java/com/amazon/connect/chat/sdk/repository/ChatServiceImplTest.kt create mode 100644 chat-sdk/test-summary.gradle.kts diff --git a/chat-sdk/build.gradle.kts b/chat-sdk/build.gradle.kts index 93c532c..3ea5a87 100644 --- a/chat-sdk/build.gradle.kts +++ b/chat-sdk/build.gradle.kts @@ -64,15 +64,7 @@ dependencies { implementation(libs.composeUiGraphics) implementation(libs.composeUiToolingPreview) implementation(libs.material3) - implementation("com.google.android.gms:play-services-basement:18.2.0") - implementation(libs.runtimeLivedata) // Add this dependency in libs.versions.toml if necessary - testImplementation(libs.junit) - androidTestImplementation(libs.androidxJunit) - androidTestImplementation(libs.espressoCore) - androidTestImplementation(platform(libs.composeBom)) - androidTestImplementation(libs.composeUiTestJunit4) - debugImplementation(libs.composeUiTooling) - debugImplementation(libs.composeUiTestManifest) + implementation(libs.runtimeLivedata) // Lifecycle livedata implementation(libs.lifecycleLivedataKtx) @@ -104,6 +96,24 @@ dependencies { // Image loading implementation(libs.coilCompose) + // Testing + // Mockito for mocking + testImplementation(libs.mockito.core) + testImplementation(libs.mockito.inline) + + // Kotlin extensions for Mockito + testImplementation(libs.mockito.kotlin) + + // Coroutines test library + testImplementation(libs.coroutines.test) + + testImplementation(libs.junit) + androidTestImplementation(libs.androidxJunit) + androidTestImplementation(platform(libs.composeBom)) + androidTestImplementation(libs.composeUiTestJunit4) + debugImplementation(libs.composeUiTooling) + debugImplementation(libs.composeUiTestManifest) + testImplementation(libs.robolectric) } publishing { @@ -128,3 +138,6 @@ publishing { tasks.withType().configureEach { dependsOn(tasks.named("assembleRelease")) } + +// Test summary gradle file +apply(from = "test-summary.gradle.kts") \ No newline at end of file diff --git a/chat-sdk/src/main/java/com/amazon/connect/chat/sdk/repository/ChatService.kt b/chat-sdk/src/main/java/com/amazon/connect/chat/sdk/repository/ChatService.kt index 643289e..e4d6240 100644 --- a/chat-sdk/src/main/java/com/amazon/connect/chat/sdk/repository/ChatService.kt +++ b/chat-sdk/src/main/java/com/amazon/connect/chat/sdk/repository/ChatService.kt @@ -20,7 +20,7 @@ interface ChatService { * Disconnects the current chat session. * @return A Result indicating whether the disconnection was successful. */ - suspend fun disconnectChatSession(): Result + suspend fun disconnectChatSession(): Result } class ChatServiceImpl @Inject constructor( @@ -44,13 +44,13 @@ class ChatServiceImpl @Inject constructor( } } - override suspend fun disconnectChatSession(): Result { + override suspend fun disconnectChatSession(): Result { return runCatching { val connectionDetails = connectionDetailsProvider.getConnectionDetails() ?: throw Exception("No connection details available") awsClient.disconnectParticipantConnection(connectionDetails.connectionToken).getOrThrow() Log.d("ChatServiceImpl", "Participant Disconnected") - Unit + true }.onFailure { exception -> Log.e("ChatServiceImpl", "Failed to disconnect participant: ${exception.message}", exception) } diff --git a/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/ChatSessionImpl.kt b/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/ChatSessionImpl.kt new file mode 100644 index 0000000..025da35 --- /dev/null +++ b/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/ChatSessionImpl.kt @@ -0,0 +1,84 @@ +package com.amazon.connect.chat.sdk + +import com.amazon.connect.chat.sdk.model.ChatDetails +import com.amazon.connect.chat.sdk.model.GlobalConfig +import com.amazon.connect.chat.sdk.repository.ChatService +import com.amazonaws.regions.Regions +import junit.framework.TestCase.assertTrue +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.* +import org.mockito.MockitoAnnotations +import org.mockito.kotlin.verify +import org.robolectric.RobolectricTestRunner + + +@ExperimentalCoroutinesApi +@RunWith(RobolectricTestRunner::class) +class ChatSessionImplTest { + + @Mock + private lateinit var chatService: ChatService + + private lateinit var chatSession: ChatSession + + @Before + fun setUp() { + MockitoAnnotations.openMocks(this) + chatSession = ChatSessionImpl(chatService) + } + + @Test + fun test_configure(){ + val config = GlobalConfig(region = Regions.US_WEST_2) + chatSession.configure(config) + verify(chatService).configure(config) + } + + @Test + fun test_connect_success() = runTest { + val chatDetails = ChatDetails(participantToken = "participant-token") + `when`(chatService.createChatSession(chatDetails)).thenReturn(Result.success(true)) + + val result = chatSession.connect(chatDetails) + + assertTrue(result.isSuccess) + verify(chatService).createChatSession(chatDetails) + } + + @Test + fun test_connect_failure() = runTest { + val chatDetails = ChatDetails(participantToken = "invalid token") + `when`(chatService.createChatSession(chatDetails)).thenThrow(RuntimeException("Network error")) + + val result = chatSession.connect(chatDetails) + + assertTrue(result.isFailure) + verify(chatService).createChatSession(chatDetails) + } + + @Test + fun test_disconnect_success() = runTest { + `when`(chatService.disconnectChatSession()).thenReturn(Result.success(true)) + + val result = chatSession.disconnect() + + assertTrue(result.isSuccess) + verify(chatService).disconnectChatSession() + } + + @Test + fun test_disconnect_failure() = runTest { + `when`(chatService.disconnectChatSession()).thenThrow(RuntimeException("Network error")) + + val result = chatSession.disconnect() + + assertTrue(result.isFailure) + verify(chatService).disconnectChatSession() + } + +} diff --git a/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/network/AWSClientImplTest.kt b/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/network/AWSClientImplTest.kt new file mode 100644 index 0000000..814b7f4 --- /dev/null +++ b/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/network/AWSClientImplTest.kt @@ -0,0 +1,111 @@ +import com.amazon.connect.chat.sdk.model.GlobalConfig +import com.amazon.connect.chat.sdk.network.AWSClientImpl +import com.amazonaws.regions.Region +import com.amazonaws.regions.Regions +import com.amazonaws.services.connectparticipant.AmazonConnectParticipantClient +import com.amazonaws.services.connectparticipant.model.ConnectionCredentials +import com.amazonaws.services.connectparticipant.model.CreateParticipantConnectionRequest +import com.amazonaws.services.connectparticipant.model.CreateParticipantConnectionResult +import com.amazonaws.services.connectparticipant.model.DisconnectParticipantRequest +import com.amazonaws.services.connectparticipant.model.DisconnectParticipantResult +import com.amazonaws.services.connectparticipant.model.Websocket +import junit.framework.TestCase.assertTrue +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.any +import org.mockito.Mockito.mock +import org.mockito.Mockito.verify +import org.mockito.Mockito.`when` +import org.mockito.MockitoAnnotations +import org.robolectric.RobolectricTestRunner + +@ExperimentalCoroutinesApi +@RunWith(RobolectricTestRunner::class) +class AWSClientImplTest { + + @Mock + private lateinit var mockClient: AmazonConnectParticipantClient + + private lateinit var awsClient: AWSClientImpl + + @Before + fun setUp() { + MockitoAnnotations.openMocks(this) + awsClient = AWSClientImpl(mockClient) + } + + @Test + fun test_configure() { + val config = GlobalConfig(region = Regions.US_WEST_2) + awsClient.configure(config) + verify(mockClient).setRegion(Region.getRegion(config.region)) + } + + @Test + fun test_createParticipantConnection_success() = runTest { + val participantToken = "token" + + val mockResponse = CreateParticipantConnectionResult().apply { + connectionCredentials = ConnectionCredentials().apply { + connectionToken = "mockedConnectionToken" + } + websocket = Websocket().apply { + url = "mockedWebsocketUrl" + connectionExpiry = "mockedExpiryTime" + } + } + + `when`(mockClient.createParticipantConnection(any(CreateParticipantConnectionRequest::class.java))) + .thenReturn(mockResponse) + + val result = awsClient.createParticipantConnection(participantToken) + + assertTrue("Expected successful connection creation", result.isSuccess) + verify(mockClient).createParticipantConnection(any(CreateParticipantConnectionRequest::class.java)) + } + + @Test + fun test_createParticipantConnection_failure() = runTest { + val participantToken = "invalid_token" + `when`(mockClient.createParticipantConnection(any(CreateParticipantConnectionRequest::class.java))) + .thenThrow(RuntimeException("Network error")) + + try { + awsClient.createParticipantConnection(participantToken) + } catch (e: Exception) { + assertTrue("Expected exception due to network error", e is RuntimeException) + assertTrue("Expected network error message", e.message == "Network error") + } + } + + @Test + fun test_disconnectParticipantConnection_success() = runTest { + val connectionToken = "token" + val mockResponse = mock(DisconnectParticipantResult::class.java) + `when`(mockClient.disconnectParticipant(any(DisconnectParticipantRequest::class.java))) + .thenReturn(mockResponse) + + val result = awsClient.disconnectParticipantConnection(connectionToken) + + assertTrue("Expected successful disconnection", result.isSuccess) + verify(mockClient).disconnectParticipant(any(DisconnectParticipantRequest::class.java)) + } + + @Test + fun test_disconnectParticipantConnection_failure() = runTest { + val connectionToken = "invalid_token" + `when`(mockClient.disconnectParticipant(any(DisconnectParticipantRequest::class.java))) + .thenThrow(RuntimeException("Network error")) + + try { + awsClient.disconnectParticipantConnection(connectionToken) + } catch (e: Exception) { + assertTrue("Expected exception due to network error", e is RuntimeException) + assertTrue("Expected network error message", e.message == "Network error") + } + } +} diff --git a/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/repository/ChatServiceImplTest.kt b/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/repository/ChatServiceImplTest.kt new file mode 100644 index 0000000..eee0906 --- /dev/null +++ b/chat-sdk/src/test/java/com/amazon/connect/chat/sdk/repository/ChatServiceImplTest.kt @@ -0,0 +1,121 @@ +package com.amazon.connect.chat.sdk.repository + +import com.amazon.connect.chat.sdk.model.ChatDetails +import com.amazon.connect.chat.sdk.model.ConnectionDetails +import com.amazon.connect.chat.sdk.model.GlobalConfig +import com.amazon.connect.chat.sdk.network.APIClient +import com.amazon.connect.chat.sdk.network.AWSClient +import com.amazonaws.regions.Regions +import com.amazonaws.services.connectparticipant.model.DisconnectParticipantResult +import junit.framework.TestCase.assertTrue +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.* +import org.mockito.MockitoAnnotations +import org.robolectric.RobolectricTestRunner + +@ExperimentalCoroutinesApi +@RunWith(RobolectricTestRunner::class) +class ChatServiceImplTest { + + @Mock + private lateinit var apiClient: APIClient + + @Mock + private lateinit var awsClient: AWSClient + + @Mock + private lateinit var connectionDetailsProvider: ConnectionDetailsProvider + + private lateinit var chatService: ChatService + + @Before + fun setUp() { + MockitoAnnotations.openMocks(this) + chatService = ChatServiceImpl(apiClient, awsClient, connectionDetailsProvider) + } + + @Test + fun test_configure(){ + val config = GlobalConfig(region = Regions.US_WEST_2) + chatService.configure(config) + verify(awsClient).configure(config) + } + + @Test + fun test_createParticipantConnection_success() = runTest { + val chatDetails = ChatDetails(participantToken = "token") + val mockConnectionDetails = createMockConnectionDetails("valid_token") + + `when`(awsClient.createParticipantConnection(chatDetails.participantToken)).thenReturn(Result.success(mockConnectionDetails)) + `when`(connectionDetailsProvider.updateChatDetails(chatDetails)).then { /**/ } + + val result = chatService.createChatSession(chatDetails) + + assertTrue(result.isSuccess) + verify(connectionDetailsProvider).updateChatDetails(chatDetails) + verify(connectionDetailsProvider).updateConnectionDetails(mockConnectionDetails) + verify(awsClient).createParticipantConnection(chatDetails.participantToken) + } + + @Test + fun test_createParticipantConnection_failure() = runTest { + val chatDetails = ChatDetails(participantToken = "invalid_token") + `when`(awsClient.createParticipantConnection(chatDetails.participantToken)).thenReturn( + Result.failure(Exception("Network error")) + ) + val result = chatService.createChatSession(chatDetails) + assertTrue(result.isFailure) + verify(connectionDetailsProvider).updateChatDetails(chatDetails) + verify(awsClient).createParticipantConnection(chatDetails.participantToken) + } + + @Test + fun test_disconnectParticipantConnection_success() = runTest { + val mockConnectionDetails = createMockConnectionDetails("valid_token") + `when`(connectionDetailsProvider.getConnectionDetails()).thenReturn(mockConnectionDetails) + `when`(awsClient.disconnectParticipantConnection(mockConnectionDetails.connectionToken)).thenReturn(Result.success( + DisconnectParticipantResult() + )) + + val result = chatService.disconnectChatSession() + + assertTrue(result.isSuccess) + verify(connectionDetailsProvider).getConnectionDetails() + verify(awsClient).disconnectParticipantConnection(mockConnectionDetails.connectionToken) + } + + @Test + fun test_disconnectParticipantConnection_failure() = runTest { + val mockConnectionDetails = createMockConnectionDetails("invalid_token") + `when`(connectionDetailsProvider.getConnectionDetails()).thenReturn(mockConnectionDetails) + `when`(awsClient.disconnectParticipantConnection(mockConnectionDetails.connectionToken)).thenThrow(RuntimeException("Network error")) + + val result = chatService.disconnectChatSession() + assertTrue(result.isFailure) + verify(connectionDetailsProvider).getConnectionDetails() + verify(awsClient).disconnectParticipantConnection(mockConnectionDetails.connectionToken) + } + + @Test + fun test_disconnectParticipantConnection_noConnectionDetails() = runTest { + `when`(connectionDetailsProvider.getConnectionDetails()).thenReturn(null) + val result = chatService.disconnectChatSession() + assertTrue(result.isFailure) + verify(connectionDetailsProvider).getConnectionDetails() + verify(awsClient, never()).disconnectParticipantConnection(anyString()) + } + + private fun createMockConnectionDetails(token : String): ConnectionDetails { + return ConnectionDetails( + connectionToken = token, + websocketUrl = "mockedWebsocketUrl", + expiry = "mockedExpiryTime" + ) + } + +} \ No newline at end of file diff --git a/chat-sdk/test-summary.gradle.kts b/chat-sdk/test-summary.gradle.kts new file mode 100644 index 0000000..d1f091b --- /dev/null +++ b/chat-sdk/test-summary.gradle.kts @@ -0,0 +1,73 @@ +import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.gradle.api.tasks.testing.logging.TestLogEvent +import org.gradle.api.tasks.testing.TestDescriptor +import org.gradle.api.tasks.testing.TestResult + + +tasks.withType { + testLogging { + events = setOf( + TestLogEvent.FAILED, + TestLogEvent.PASSED, + TestLogEvent.SKIPPED, + TestLogEvent.STANDARD_ERROR, + TestLogEvent.STANDARD_OUT + ) + exceptionFormat = TestExceptionFormat.FULL + } + + afterSuite(KotlinClosure2({ desc, result -> + if (desc.parent == null) { // Will match the outermost suite + val totalTests = result.testCount + val passedTests = result.successfulTestCount + val failedTests = result.failedTestCount + val skippedTests = result.skippedTestCount + val resultType = result.resultType + + val output = """ + + + ${Color.CYAN}─────────────────────────────────────────────────────────────────────────────────${Color.NONE} + ${Color.CYAN}| ${Color.WHITE}Test Summary${Color.CYAN} | + ${Color.CYAN}|───────────────────────────────────────────────────────────────────────────────|${Color.NONE} + ${Color.CYAN}| ${Color.WHITE}Total Tests : ${Color.GREEN}$totalTests${Color.CYAN} | + ${Color.CYAN}| ${Color.WHITE}Passed : ${Color.GREEN}$passedTests${Color.CYAN} | + ${Color.CYAN}| ${Color.WHITE}Failed : ${Color.RED}$failedTests${Color.CYAN} | + ${Color.CYAN}| ${Color.WHITE}Skipped : ${Color.YELLOW}$skippedTests${Color.CYAN} | + ${Color.CYAN}| ${Color.WHITE}Result : ${when (resultType) { + TestResult.ResultType.SUCCESS -> "${Color.GREEN}$resultType" + TestResult.ResultType.FAILURE -> "${Color.RED}$resultType" + TestResult.ResultType.SKIPPED -> "${Color.YELLOW}$resultType" + }}${Color.CYAN} | + ${Color.CYAN}─────────────────────────────────────────────────────────────────────────────────${Color.NONE} + """.trimIndent() + println(output) + } + }, this)) +} + +// Helper class to convert Groovy closure to Kotlin lambda +class KotlinClosure2( + private val function: (T1, T2) -> R, + private val owner: Any? = null, + private val thisObject: Any? = null +) : groovy.lang.Closure<@UnsafeVariance R>(owner, thisObject) { + @Suppress("unused") + fun doCall(var1: T1, var2: T2): R = function(var1, var2) +} + +internal enum class Color(val ansiCode: String) { + NONE("\u001B[0m"), + BLACK("\u001B[30m"), + RED("\u001B[31m"), + GREEN("\u001B[32m"), + YELLOW("\u001B[33m"), + BLUE("\u001B[34m"), + PURPLE("\u001B[35m"), + CYAN("\u001B[36m"), + WHITE("\u001B[37m"); + + override fun toString(): String { + return ansiCode + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 45f8bb8..44760c9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,6 +3,7 @@ androidGradlePlugin = "8.5.1" hiltAndroid = "2.49" kotlin = "1.9.20" hilt = "2.49" +robolectric = "4.13" serialization = "1.9.20" androidxCoreKtx = "1.13.1" androidxLifecycleRuntimeKtx = "2.8.4" @@ -35,6 +36,9 @@ chatSdk = "1.0.0" runtimeLivedata = "1.6.8" appcompat = "1.7.0" material = "1.12.0" +mockito = "4.0.0" +mockitoKotlin = "4.0.0" +coroutinesTest = "1.5.2" [libraries] androidGradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" } @@ -70,12 +74,17 @@ hiltNavigationCompose = { module = "androidx.hilt:hilt-navigation-compose", vers navigationCompose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" } awsSdkCore = { module = "com.amazonaws:aws-android-sdk-core", version.ref = "awsSdkCore" } awsSdkConnectParticipant = { module = "com.amazonaws:aws-android-sdk-connectparticipant", version.ref = "awsSdkConnectParticipant" } +robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" } serializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serializationJson" } coilCompose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" } chatSdk = { module = "com.amazon.connect.chat:library", version.ref = "chatSdk" } runtimeLivedata = { group = "androidx.compose.runtime", name = "runtime-livedata", version.ref = "runtimeLivedata" } appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } material = { group = "com.google.android.material", name = "material", version.ref = "material" } +mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" } +mockito-inline = { group = "org.mockito", name = "mockito-inline", version.ref = "mockito" } +mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version.ref = "mockitoKotlin" } +coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutinesTest" } [plugins] androidApplication = { id = "com.android.application", version.ref = "androidGradlePlugin" } From 07c6f22e1c12820927b9a7a80724a9492dac4502 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:42:07 -0700 Subject: [PATCH 02/18] Create ci.yml --- .github/workflows/ci.yml | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2b94f53 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,86 @@ +name: Android CI + +on: + # pull_request: + # branches: [ main ] + push: + branches: [ rajatttt/test ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Set up Android SDK + uses: android-actions/setup-android@v2 + with: + api-level: 30 + build-tools: 30.0.3 + + - name: Cache Gradle + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Build with Gradle + run: ./gradlew build + + test: + runs-on: ubuntu-latest + needs: build + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Set up Android SDK + uses: android-actions/setup-android@v2 + with: + api-level: 30 + build-tools: 30.0.3 + + - name: Cache Gradle + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Run Unit Tests + run: ./gradlew testDebugUnitTest + + - name: Parse Unit Test Results + id: parse_test_results + run: | + TEST_RESULTS=$(./gradlew testDebugUnitTest --console=plain | tee /dev/tty | grep -A 20 "Test Summary" | tail -n +2) + echo "::set-output name=test_results::${TEST_RESULTS}" + shell: bash + + - name: Comment on PR + uses: marocchino/sticky-pull-request-comment@v2 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + header: Test Results + message: ${{ steps.parse_test_results.outputs.test_results }} + recreate: true From b3e6347f98a91475c1a37fdc7a9d594aff08e196 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:45:27 -0700 Subject: [PATCH 03/18] Update ci.yml --- .github/workflows/ci.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b94f53..28b7db0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,10 +14,10 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Set up Android SDK uses: android-actions/setup-android@v2 @@ -45,11 +45,11 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - - - name: Set up JDK 11 + + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Set up Android SDK uses: android-actions/setup-android@v2 @@ -77,10 +77,10 @@ jobs: echo "::set-output name=test_results::${TEST_RESULTS}" shell: bash - - name: Comment on PR - uses: marocchino/sticky-pull-request-comment@v2 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - header: Test Results - message: ${{ steps.parse_test_results.outputs.test_results }} - recreate: true + # - name: Comment on PR + # uses: marocchino/sticky-pull-request-comment@v2 + # with: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # header: Test Results + # message: ${{ steps.parse_test_results.outputs.test_results }} + # recreate: true From 044941f4b05c97566b6496e4757815f413267e32 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:02:11 -0700 Subject: [PATCH 04/18] Update ci.yml --- .github/workflows/ci.yml | 52 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28b7db0..0bc0b8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,36 +7,36 @@ on: branches: [ rajatttt/test ] jobs: - build: - runs-on: ubuntu-latest + # build: + # runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 + # steps: + # - name: Checkout code + # uses: actions/checkout@v2 - - name: Set up JDK 17 - uses: actions/setup-java@v1 - with: - java-version: 17 + # - name: Set up JDK 17 + # uses: actions/setup-java@v1 + # with: + # java-version: 17 - - name: Set up Android SDK - uses: android-actions/setup-android@v2 - with: - api-level: 30 - build-tools: 30.0.3 + # - name: Set up Android SDK + # uses: android-actions/setup-android@v2 + # with: + # api-level: 30 + # build-tools: 30.0.3 - - name: Cache Gradle - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- + # - name: Cache Gradle + # uses: actions/cache@v2 + # with: + # path: | + # ~/.gradle/caches + # ~/.gradle/wrapper + # key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + # restore-keys: | + # ${{ runner.os }}-gradle- - - name: Build with Gradle - run: ./gradlew build + # - name: Build with Gradle + # run: ./gradlew build test: runs-on: ubuntu-latest @@ -73,7 +73,7 @@ jobs: - name: Parse Unit Test Results id: parse_test_results run: | - TEST_RESULTS=$(./gradlew testDebugUnitTest --console=plain | tee /dev/tty | grep -A 20 "Test Summary" | tail -n +2) + TEST_RESULTS=$(grep -A 20 "Test Summary" <<< "${{ steps.run_tests.outputs.test_results }}" | tail -n +2) echo "::set-output name=test_results::${TEST_RESULTS}" shell: bash From d46fdcc47b61754b1251d2ee792412922e47fb0f Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:02:40 -0700 Subject: [PATCH 05/18] Update ci.yml --- .github/workflows/ci.yml | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bc0b8e..58faf4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,36 +7,36 @@ on: branches: [ rajatttt/test ] jobs: - # build: - # runs-on: ubuntu-latest + build: + runs-on: ubuntu-latest - # steps: - # - name: Checkout code - # uses: actions/checkout@v2 + steps: + - name: Checkout code + uses: actions/checkout@v2 - # - name: Set up JDK 17 - # uses: actions/setup-java@v1 - # with: - # java-version: 17 + - name: Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: 17 - # - name: Set up Android SDK - # uses: android-actions/setup-android@v2 - # with: - # api-level: 30 - # build-tools: 30.0.3 + - name: Set up Android SDK + uses: android-actions/setup-android@v2 + with: + api-level: 30 + build-tools: 30.0.3 - # - name: Cache Gradle - # uses: actions/cache@v2 - # with: - # path: | - # ~/.gradle/caches - # ~/.gradle/wrapper - # key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - # restore-keys: | - # ${{ runner.os }}-gradle- + - name: Cache Gradle + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- - # - name: Build with Gradle - # run: ./gradlew build + - name: Build with Gradle + run: ./gradlew build test: runs-on: ubuntu-latest From 874e819b40e4275e6e56cd744b06330b3426103e Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:27:22 -0700 Subject: [PATCH 06/18] Update ci.yml --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58faf4d..2746543 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,12 +68,12 @@ jobs: ${{ runner.os }}-gradle- - name: Run Unit Tests - run: ./gradlew testDebugUnitTest + run: ./gradlew testDebugUnitTest | tee test-results.txt - name: Parse Unit Test Results id: parse_test_results run: | - TEST_RESULTS=$(grep -A 20 "Test Summary" <<< "${{ steps.run_tests.outputs.test_results }}" | tail -n +2) + TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +0) echo "::set-output name=test_results::${TEST_RESULTS}" shell: bash From df6478edb24b22adc8eaedb70ee18ec03b1b9b30 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:37:11 -0700 Subject: [PATCH 07/18] Update ci.yml --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2746543..377eb81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,10 +77,10 @@ jobs: echo "::set-output name=test_results::${TEST_RESULTS}" shell: bash - # - name: Comment on PR - # uses: marocchino/sticky-pull-request-comment@v2 - # with: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # header: Test Results - # message: ${{ steps.parse_test_results.outputs.test_results }} - # recreate: true + - name: Comment on PR + uses: marocchino/sticky-pull-request-comment@v2 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + header: Test Results + message: ${{ steps.parse_test_results.outputs.test_results }} + recreate: true From f191c83dd4794b49604746acc0ef213fef8aef9d Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:23:09 -0700 Subject: [PATCH 08/18] Update ci.yml --- .github/workflows/ci.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 377eb81..8b390e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,9 +35,15 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- - - name: Build with Gradle - run: ./gradlew build + - name: Build with Gradle (no tests) + run: ./gradlew assemble + - name: Save Build Artifacts + uses: actions/upload-artifact@v2 + with: + name: app-build + path: app/build/outputs/apk/ + test: runs-on: ubuntu-latest needs: build @@ -67,8 +73,14 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- + - name: Download Build Artifacts + uses: actions/download-artifact@v2 + with: + name: app-build + path: app/build/outputs/apk/ + - name: Run Unit Tests - run: ./gradlew testDebugUnitTest | tee test-results.txt + run: ./gradlew test | tee test-results.txt - name: Parse Unit Test Results id: parse_test_results @@ -84,3 +96,4 @@ jobs: header: Test Results message: ${{ steps.parse_test_results.outputs.test_results }} recreate: true + From 6c99c514d1b8b75b943b331533891b2abb193862 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:23:24 -0700 Subject: [PATCH 09/18] Update ci.yml --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ed1959..922f6f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: id: parse_test_results run: | TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +0) - echo "::set-output name=test_results::${TEST_RESULTS}" + echo "test_results=$TEST_RESULTS" >> $GITHUB_ENV shell: bash comment-in-pr: @@ -105,10 +105,10 @@ jobs: uses: actions/github-script@v6 with: script: | - const testResults = `{{ steps.parse_test_results.outputs.test_results }}`; + const testResults = process.env.test_results; github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `### Test Results\n${testResults}` - }); \ No newline at end of file + }); From 80c54aee1b6f2e75e27eeebd1d49bc8ecd9c1afe Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:38:07 -0700 Subject: [PATCH 10/18] Update ci.yml --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 922f6f2..75fa44a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,14 +78,15 @@ jobs: with: name: app-build path: app/build/outputs/apk/ - + - name: Run Unit Tests + id: run_tests run: ./gradlew test | tee test-results.txt - name: Parse Unit Test Results id: parse_test_results run: | - TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +0) + TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2 | sed 's/%/%25/g; s/$/%0A/g; s/\r/%0D/g') echo "test_results=$TEST_RESULTS" >> $GITHUB_ENV shell: bash From b9d7fb31e847a131316e064bc27b28836ead014c Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:57:16 -0700 Subject: [PATCH 11/18] Update ci.yml --- .github/workflows/ci.yml | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75fa44a..748c016 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,33 +83,19 @@ jobs: id: run_tests run: ./gradlew test | tee test-results.txt - - name: Parse Unit Test Results - id: parse_test_results + - name: Run Unit Tests and Capture Results + id: run_tests run: | - TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2 | sed 's/%/%25/g; s/$/%0A/g; s/\r/%0D/g') - echo "test_results=$TEST_RESULTS" >> $GITHUB_ENV - shell: bash - - comment-in-pr: - runs-on: ubuntu-latest - needs: test - permissions: - contents: write - pull-requests: write - repository-projects: write - id-token: write + ./gradlew test | tee test-results.txt + TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2) + echo "$TEST_RESULTS" > test-summary.txt - steps: - - name: Checkout - uses: actions/checkout@v2 - name: Comment on PR - uses: actions/github-script@v6 - with: - script: | - const testResults = process.env.test_results; - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `### Test Results\n${testResults}` - }); + if: github.event_name == 'pull_request' + run: | + COMMENT_BODY=$(cat test-summary.txt) + echo "### Test Results" > comment_body.txt + echo "$COMMENT_BODY" >> comment_body.txt + gh pr comment ${{ github.event.pull_request.number }} --body "$(cat comment_body.txt)" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 9915e5cad8d0f3e2cb1fce287d594fc18c89b844 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:07:35 -0700 Subject: [PATCH 12/18] Update ci.yml --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 748c016..269d5c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,10 +78,6 @@ jobs: with: name: app-build path: app/build/outputs/apk/ - - - name: Run Unit Tests - id: run_tests - run: ./gradlew test | tee test-results.txt - name: Run Unit Tests and Capture Results id: run_tests From 41a35d8f44e4e8b6f6fe774e0f9e5e78a9faeba8 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:00:01 -0700 Subject: [PATCH 13/18] Update ci.yml --- .github/workflows/ci.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 269d5c1..f0e28dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,15 +83,19 @@ jobs: id: run_tests run: | ./gradlew test | tee test-results.txt - TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2) + TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2 | sed 's/\x1b\[[0-9;]*m//g') echo "$TEST_RESULTS" > test-summary.txt - + - name: Comment on PR if: github.event_name == 'pull_request' - run: | - COMMENT_BODY=$(cat test-summary.txt) - echo "### Test Results" > comment_body.txt - echo "$COMMENT_BODY" >> comment_body.txt - gh pr comment ${{ github.event.pull_request.number }} --body "$(cat comment_body.txt)" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const testResults = fs.readFileSync('test-summary.txt', 'utf8'); + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `### Test Results\n${testResults}` + }); From fb551761983d2aab2cc86ce6985af7ee63946a75 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:01:49 -0700 Subject: [PATCH 14/18] Update ci.yml --- .github/workflows/ci.yml | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0e28dc..7ad93f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,19 +83,43 @@ jobs: id: run_tests run: | ./gradlew test | tee test-results.txt - TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2 | sed 's/\x1b\[[0-9;]*m//g') + TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2 | sed 's/\x1B\[[0-9;]*[JKmsu]//g' | tr -d '[:space:]') echo "$TEST_RESULTS" > test-summary.txt - + + - name: Format Test Results for Two-Row Markdown Table with Emojis + run: | + echo "### Test Results" > formatted-summary.txt + echo "" >> formatted-summary.txt + echo "| Total Tests | Passed | Failed | Skipped | Result |" >> formatted-summary.txt + echo "|-------------|--------|--------|---------|--------|" >> formatted-summary.txt + TOTAL=$(grep "Total Tests" test-summary.txt | awk '{print $5}') + PASSED=$(grep "Passed" test-summary.txt | awk '{print $4}') + FAILED=$(grep "Failed" test-summary.txt | awk '{print $4}') + SKIPPED=$(grep "Skipped" test-summary.txt | awk '{print $4}') + RESULT=$(grep "Result" test-summary.txt | awk '{print $4}' | sed 's/\x1B\[[0-9;]*[JKmsu]//g' | tr -d '[:space:]') + + echo "Cleaned RESULT: '$RESULT'" + + if [[ "$RESULT" == "SUCCESS" ]]; then + EMOJI="✅" + elif [[ "$RESULT" == "FAILURE" ]]; then + EMOJI="❌" + else + EMOJI="⚠️" + fi + + echo "| $TOTAL | $PASSED | $FAILED | $SKIPPED | $RESULT $EMOJI |" >> formatted-summary.txt + - name: Comment on PR if: github.event_name == 'pull_request' uses: actions/github-script@v6 with: script: | const fs = require('fs'); - const testResults = fs.readFileSync('test-summary.txt', 'utf8'); + const testResults = fs.readFileSync('formatted-summary.txt', 'utf8'); github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: `### Test Results\n${testResults}` + body: testResults }); From bcc9cbc5d6dd6cfd1b34994c609e834272403aed Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:17:24 -0700 Subject: [PATCH 15/18] Update ci.yml --- .github/workflows/ci.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ad93f3..1d2b285 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,14 +92,22 @@ jobs: echo "" >> formatted-summary.txt echo "| Total Tests | Passed | Failed | Skipped | Result |" >> formatted-summary.txt echo "|-------------|--------|--------|---------|--------|" >> formatted-summary.txt + + # Extracting values from the test summary TOTAL=$(grep "Total Tests" test-summary.txt | awk '{print $5}') PASSED=$(grep "Passed" test-summary.txt | awk '{print $4}') FAILED=$(grep "Failed" test-summary.txt | awk '{print $4}') SKIPPED=$(grep "Skipped" test-summary.txt | awk '{print $4}') - RESULT=$(grep "Result" test-summary.txt | awk '{print $4}' | sed 's/\x1B\[[0-9;]*[JKmsu]//g' | tr -d '[:space:]') - echo "Cleaned RESULT: '$RESULT'" + # Directly capture the line that contains "Result" for inspection + RESULT_LINE=$(grep "Result" test-summary.txt) + echo "Debug: Raw RESULT_LINE='$RESULT_LINE'" + + # Extract and clean up the RESULT variable + RESULT=$(echo "$RESULT_LINE" | awk '{print $4}' | sed 's/\x1B\[[0-9;]*[JKmsu]//g' | tr -d '[:space:]') + echo "Debug: Cleaned RESULT='$RESULT'" + # Use `if` or `case` to compare the result if [[ "$RESULT" == "SUCCESS" ]]; then EMOJI="✅" elif [[ "$RESULT" == "FAILURE" ]]; then @@ -109,7 +117,10 @@ jobs: fi echo "| $TOTAL | $PASSED | $FAILED | $SKIPPED | $RESULT $EMOJI |" >> formatted-summary.txt - + + # Show the final output for debugging + cat formatted-summary.txt + - name: Comment on PR if: github.event_name == 'pull_request' uses: actions/github-script@v6 From d9df904c3be867ede18bf4271982674096491670 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:45:55 -0700 Subject: [PATCH 16/18] Update ci.yml --- .github/workflows/ci.yml | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d2b285..368333c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,21 +93,24 @@ jobs: echo "| Total Tests | Passed | Failed | Skipped | Result |" >> formatted-summary.txt echo "|-------------|--------|--------|---------|--------|" >> formatted-summary.txt - # Extracting values from the test summary - TOTAL=$(grep "Total Tests" test-summary.txt | awk '{print $5}') - PASSED=$(grep "Passed" test-summary.txt | awk '{print $4}') - FAILED=$(grep "Failed" test-summary.txt | awk '{print $4}') - SKIPPED=$(grep "Skipped" test-summary.txt | awk '{print $4}') + echo "Raw Test Summary Content:" + cat test-summary.txt - # Directly capture the line that contains "Result" for inspection - RESULT_LINE=$(grep "Result" test-summary.txt) - echo "Debug: Raw RESULT_LINE='$RESULT_LINE'" + # Extracting values from the test summary + TOTAL=$(grep "Total Tests" test-summary.txt | awk -F"|" '{print $3}' | tr -d '[:space:]') + PASSED=$(grep "Passed" test-summary.txt | awk -F"|" '{print $4}' | tr -d '[:space:]') + FAILED=$(grep "Failed" test-summary.txt | awk -F"|" '{print $5}' | tr -d '[:space:]') + SKIPPED=$(grep "Skipped" test-summary.txt | awk -F"|" '{print $6}' | tr -d '[:space:]') + RESULT=$(grep "Result" test-summary.txt | awk -F"|" '{print $7}' | tr -d '[:space:]') - # Extract and clean up the RESULT variable - RESULT=$(echo "$RESULT_LINE" | awk '{print $4}' | sed 's/\x1B\[[0-9;]*[JKmsu]//g' | tr -d '[:space:]') - echo "Debug: Cleaned RESULT='$RESULT'" + # Detailed debugging + echo "Debug: Extracted Values:" + echo " TOTAL: '$TOTAL'" + echo " PASSED: '$PASSED'" + echo " FAILED: '$FAILED'" + echo " SKIPPED: '$SKIPPED'" + echo " RESULT (Raw): '$RESULT'" - # Use `if` or `case` to compare the result if [[ "$RESULT" == "SUCCESS" ]]; then EMOJI="✅" elif [[ "$RESULT" == "FAILURE" ]]; then @@ -115,12 +118,15 @@ jobs: else EMOJI="⚠️" fi + + echo "Debug: Final RESULT after processing: '$RESULT $EMOJI'" echo "| $TOTAL | $PASSED | $FAILED | $SKIPPED | $RESULT $EMOJI |" >> formatted-summary.txt # Show the final output for debugging + echo "Final formatted-summary.txt content:" cat formatted-summary.txt - + - name: Comment on PR if: github.event_name == 'pull_request' uses: actions/github-script@v6 From ee047e8f512ebd370d13a36a1c161eea5f4e9e80 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:59:29 -0700 Subject: [PATCH 17/18] Update ci.yml --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 368333c..0e9bcd3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,12 +96,12 @@ jobs: echo "Raw Test Summary Content:" cat test-summary.txt - # Extracting values from the test summary - TOTAL=$(grep "Total Tests" test-summary.txt | awk -F"|" '{print $3}' | tr -d '[:space:]') - PASSED=$(grep "Passed" test-summary.txt | awk -F"|" '{print $4}' | tr -d '[:space:]') - FAILED=$(grep "Failed" test-summary.txt | awk -F"|" '{print $5}' | tr -d '[:space:]') - SKIPPED=$(grep "Skipped" test-summary.txt | awk -F"|" '{print $6}' | tr -d '[:space:]') - RESULT=$(grep "Result" test-summary.txt | awk -F"|" '{print $7}' | tr -d '[:space:]') + # Extracting values using awk + TOTAL=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/TotalTests/ {print $2}') + PASSED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Passed/ {print $2}') + FAILED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Failed/ {print $2}') + SKIPPED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Skipped/ {print $2}') + RESULT=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Result/ {print $2}') # Detailed debugging echo "Debug: Extracted Values:" @@ -118,7 +118,7 @@ jobs: else EMOJI="⚠️" fi - + echo "Debug: Final RESULT after processing: '$RESULT $EMOJI'" echo "| $TOTAL | $PASSED | $FAILED | $SKIPPED | $RESULT $EMOJI |" >> formatted-summary.txt From 2c02563eb7440e7632d76d0b6e86f3251c26d163 Mon Sep 17 00:00:00 2001 From: Rajat <143978428+mrajatttt@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:07:42 -0700 Subject: [PATCH 18/18] Update ci.yml --- .github/workflows/ci.yml | 98 +++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e9bcd3..be75d2c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,12 +73,6 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- - - name: Download Build Artifacts - uses: actions/download-artifact@v2 - with: - name: app-build - path: app/build/outputs/apk/ - - name: Run Unit Tests and Capture Results id: run_tests run: | @@ -86,57 +80,57 @@ jobs: TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2 | sed 's/\x1B\[[0-9;]*[JKmsu]//g' | tr -d '[:space:]') echo "$TEST_RESULTS" > test-summary.txt - - name: Format Test Results for Two-Row Markdown Table with Emojis - run: | - echo "### Test Results" > formatted-summary.txt - echo "" >> formatted-summary.txt - echo "| Total Tests | Passed | Failed | Skipped | Result |" >> formatted-summary.txt - echo "|-------------|--------|--------|---------|--------|" >> formatted-summary.txt + # - name: Format Test Results for Two-Row Markdown Table with Emojis + # run: | + # echo "### Test Results" > formatted-summary.txt + # echo "" >> formatted-summary.txt + # echo "| Total Tests | Passed | Failed | Skipped | Result |" >> formatted-summary.txt + # echo "|-------------|--------|--------|---------|--------|" >> formatted-summary.txt - echo "Raw Test Summary Content:" - cat test-summary.txt + # echo "Raw Test Summary Content:" + # cat test-summary.txt - # Extracting values using awk - TOTAL=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/TotalTests/ {print $2}') - PASSED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Passed/ {print $2}') - FAILED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Failed/ {print $2}') - SKIPPED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Skipped/ {print $2}') - RESULT=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Result/ {print $2}') + # # Extracting values using awk + # TOTAL=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/TotalTests/ {print $2}') + # PASSED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Passed/ {print $2}') + # FAILED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Failed/ {print $2}') + # SKIPPED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Skipped/ {print $2}') + # RESULT=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Result/ {print $2}') - # Detailed debugging - echo "Debug: Extracted Values:" - echo " TOTAL: '$TOTAL'" - echo " PASSED: '$PASSED'" - echo " FAILED: '$FAILED'" - echo " SKIPPED: '$SKIPPED'" - echo " RESULT (Raw): '$RESULT'" + # # Detailed debugging + # echo "Debug: Extracted Values:" + # echo " TOTAL: '$TOTAL'" + # echo " PASSED: '$PASSED'" + # echo " FAILED: '$FAILED'" + # echo " SKIPPED: '$SKIPPED'" + # echo " RESULT (Raw): '$RESULT'" - if [[ "$RESULT" == "SUCCESS" ]]; then - EMOJI="✅" - elif [[ "$RESULT" == "FAILURE" ]]; then - EMOJI="❌" - else - EMOJI="⚠️" - fi + # if [[ "$RESULT" == "SUCCESS" ]]; then + # EMOJI="✅" + # elif [[ "$RESULT" == "FAILURE" ]]; then + # EMOJI="❌" + # else + # EMOJI="⚠️" + # fi - echo "Debug: Final RESULT after processing: '$RESULT $EMOJI'" + # echo "Debug: Final RESULT after processing: '$RESULT $EMOJI'" - echo "| $TOTAL | $PASSED | $FAILED | $SKIPPED | $RESULT $EMOJI |" >> formatted-summary.txt + # echo "| $TOTAL | $PASSED | $FAILED | $SKIPPED | $RESULT $EMOJI |" >> formatted-summary.txt - # Show the final output for debugging - echo "Final formatted-summary.txt content:" - cat formatted-summary.txt + # # Show the final output for debugging + # echo "Final formatted-summary.txt content:" + # cat formatted-summary.txt - - name: Comment on PR - if: github.event_name == 'pull_request' - uses: actions/github-script@v6 - with: - script: | - const fs = require('fs'); - const testResults = fs.readFileSync('formatted-summary.txt', 'utf8'); - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: testResults - }); + # - name: Comment on PR + # if: github.event_name == 'pull_request' + # uses: actions/github-script@v6 + # with: + # script: | + # const fs = require('fs'); + # const testResults = fs.readFileSync('formatted-summary.txt', 'utf8'); + # github.rest.issues.createComment({ + # issue_number: context.issue.number, + # owner: context.repo.owner, + # repo: context.repo.repo, + # body: testResults + # });