Skip to content

Commit

Permalink
Collect logs from iOS simulator on Test Failures
Browse files Browse the repository at this point in the history
  • Loading branch information
aaalaniz committed Jun 22, 2024
1 parent b79042b commit 660958f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/lightsaber-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
- uses: ./.github/actions/setup-lightsaber-ci

- name: Build Shared
# TODO Understand why compileIosMainKotlinMetadata fails every time
run: ./gradlew shared:assemble -x compileIosMainKotlinMetadata
run: ./gradlew shared:assemble

build-androidApp:
runs-on: macos-14
Expand Down Expand Up @@ -188,4 +187,15 @@ jobs:
- name: Run Maestro tests
run: |
export MAESTRO_DRIVER_STARTUP_TIMEOUT=60000
maestro test .maestro
maestro test .maestro
- name: Collect logs
if: failure()
run: xcrun simctl spawn "${{ steps.ios-simulator.outputs.udid }}" log collect --output ${{ github.workspace }}/${{ steps.ios-simulator.outputs.udid }}.logarchive

- name: Archive the device logs
if: always()
uses: actions/upload-artifact@v4
with:
name: device-logs
path: ${{ github.workspace }}/*.logarchive
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ androidx-appcompat = "1.7.0"
androidx-core-ktx = "1.13.1"
datastore-version = "1.1.1"
compose-ui-test = "1.6.7"
kermit = "2.0.4"

[libraries]
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "core-splashscreen" }
Expand All @@ -26,6 +27,7 @@ androidx-datastore-core-okio = { group = "androidx.datastore", name = "datastore
androidx-datastore-preferences-core = { group = "androidx.datastore", name = "datastore-preferences-core", version.ref = "datastore-version" }
androidx-compose-ui-test-junit4-android = { group = "androidx.compose.ui" , name = "ui-test-junit4-android", version.ref = "compose-ui-test" }
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui" , name = "ui-test-manifest", version.ref = "compose-ui-test" }
kermit = { group = "co.touchlab" , name = "kermit", version.ref = "kermit" }

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Expand Down
3 changes: 0 additions & 3 deletions iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@ struct ContentView: View {
.ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler
}
}



1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ kotlin {
implementation(libs.circuitx.gesture.navigation)
implementation(libs.androidx.datastore.preferences.core)
implementation(libs.androidx.datastore.core.okio)
api(libs.kermit)
}
}
commonTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package xyz.alaniz.aaron.lightsaber
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.ui.platform.AccessibilitySyncOptions
import androidx.compose.ui.window.ComposeUIViewController
import co.touchlab.kermit.DefaultFormatter
import co.touchlab.kermit.Logger
import co.touchlab.kermit.NSLogWriter
import co.touchlab.kermit.OSLogWriter
import kotlinx.cinterop.ExperimentalForeignApi
import platform.Foundation.NSDocumentDirectory
import platform.Foundation.NSFileManager
Expand All @@ -12,8 +16,9 @@ import xyz.alaniz.aaron.lightsaber.di.IosApplicationComponent
import xyz.alaniz.aaron.lightsaber.di.create
import xyz.alaniz.aaron.lightsaber.di.dataStoreFileName
import xyz.alaniz.aaron.lightsaber.ui.lightsaber.IosLightsaberScreen
import kotlin.experimental.ExperimentalNativeApi

@OptIn(ExperimentalForeignApi::class, ExperimentalComposeApi::class)
@OptIn(ExperimentalForeignApi::class, ExperimentalComposeApi::class, ExperimentalNativeApi::class)
fun MainViewController() = ComposeUIViewController(configure = {
/**
* TODO Update this to only sync the accessibility tree for debug builds
Expand All @@ -36,6 +41,20 @@ fun MainViewController() = ComposeUIViewController(configure = {
error = null,
)
val dataStorePath = requireNotNull(documentDirectory).path + "/$dataStoreFileName"

/**
* Use NSLogWriter so that logs are available to pull off the simulator in CI.
*
* TODO Inject log writers based on debug or release builds.
*/
Logger.setLogWriters(listOf(NSLogWriter(messageStringFormatter = DefaultFormatter)))

/**
* Log unhandled exceptions.
*/
setUnhandledExceptionHook {
Logger.e(throwable = it) { "Unhandled exception: cause = ${it.cause} message = ${it.message}" }
}
App(initialScreen = IosLightsaberScreen) { scope, navigator ->
IosApplicationComponent.create(
navigator = navigator,
Expand Down

0 comments on commit 660958f

Please sign in to comment.