From ea092d479f8513abd03455f437ff9bc2a1f623ad Mon Sep 17 00:00:00 2001 From: KaylaBrady <31781298+KaylaBrady@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:01:02 -0500 Subject: [PATCH 01/10] ci: Add android checks and unit tests --- .github/workflows/ci.yaml | 23 +++++++++++++++++ .tool-versions | 1 + androidApp/build.gradle.kts | 2 +- build.gradle.kts | 25 ++++++++++++++++++- settings.gradle.kts | 2 +- shared/build.gradle.kts | 2 +- .../com/mbta/tid/mbta_app/Test.android.kt | 7 +++--- 7 files changed, 55 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8106a9b58..debd7f170 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,12 +31,35 @@ jobs: create_credentials_file: true workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} + # TODO: Get java version from .tool-versions? - name: Set up Java uses: actions/setup-java@v3 with: distribution: temurin java-version: 17 cache: gradle + - uses: actions/cache@v3 + with: + path: ~/.konan + key: konan-${{ runner.os }}-${{ hashFiles('build.gradle.kts') }} + restore-keys: konan-${{ runner.os }} + # TODO: pre-commit run spotless + - run: ./gradlew spotlessCheck + - name: shared checks & unit tests + run: ./gradlew shared:check + - uses: actions/upload-artifact@v3 + if: failure() + with: + name: android-shared-reports + path: shared/build/reports + - name: android checks & unit tests + run: ./gradlew androidApp:check + - uses: actions/upload-artifact@v3 + if: failure() + with: + name: android-android-reports + path: androidApp/build/reports + - name: Fetch AWS secrets uses: aws-actions/aws-secretsmanager-get-secrets@v1 with: diff --git a/.tool-versions b/.tool-versions index f2a971aa7..6d5bf7890 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1,2 @@ ruby 3.2.2 +java temurin-17.0.9+9 diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 5fe0ab1a7..e2a8cf23f 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -45,4 +45,4 @@ dependencies { implementation(libs.compose.material3) implementation(libs.androidx.activity.compose) debugImplementation(libs.compose.ui.tooling) -} \ No newline at end of file +} diff --git a/build.gradle.kts b/build.gradle.kts index cae7afe11..ef7a10a61 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,30 @@ plugins { - //trick: for the same plugin versions in all sub-modules + // trick: for the same plugin versions in all sub-modules alias(libs.plugins.androidApplication).apply(false) alias(libs.plugins.androidLibrary).apply(false) alias(libs.plugins.kotlinAndroid).apply(false) alias(libs.plugins.kotlinMultiplatform).apply(false) + id("com.diffplug.spotless").version("6.21.0") +} + +spotless { + kotlinGradle { + ktlint() + } +} + +subprojects { + apply(plugin = "com.diffplug.spotless") + + spotless { + kotlin { + target("src/**/*.kt") + ktfmt().kotlinlangStyle() + } + kotlinGradle { ktfmt().kotlinlangStyle() } + } +} + +tasks.getByName("clean", Delete::class) { + delete(rootProject.buildDir) } diff --git a/settings.gradle.kts b/settings.gradle.kts index bc622c5bd..b634e7d90 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,4 +16,4 @@ dependencyResolutionManagement { rootProject.name = "MBTA_App" include(":androidApp") -include(":shared") \ No newline at end of file +include(":shared") diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 338306979..b5d37475b 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -14,7 +14,7 @@ kotlin { } } } - + listOf( iosX64(), iosArm64(), diff --git a/shared/src/androidUnitTest/kotlin/com/mbta/tid/mbta_app/Test.android.kt b/shared/src/androidUnitTest/kotlin/com/mbta/tid/mbta_app/Test.android.kt index 0f1ddc666..ea21fc9f5 100644 --- a/shared/src/androidUnitTest/kotlin/com/mbta/tid/mbta_app/Test.android.kt +++ b/shared/src/androidUnitTest/kotlin/com/mbta/tid/mbta_app/Test.android.kt @@ -1,12 +1,13 @@ package com.mbta.tid.mbta_app -import org.junit.Assert.assertTrue +import org.junit.Assert.assertFalse import org.junit.Test class AndroidGreetingTest { @Test fun testExample() { - assertTrue("Check Android is mentioned", Greeting().greet().contains("Android")) + // TODO: Switch back to assertTrue. See how test failure is represented in CI + assertFalse("Check Android is mentioned", Greeting().greet().contains("Android")) } -} \ No newline at end of file +} From b02941b4db5abb8d33aa394d1421f601fe026ac1 Mon Sep 17 00:00:00 2001 From: KaylaBrady <31781298+KaylaBrady@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:33:46 -0500 Subject: [PATCH 02/10] ci: Add swiftlint --- .github/workflows/ci.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index debd7f170..9d6fc2dc6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,7 +8,7 @@ on: workflow_dispatch: jobs: - test: + android: name: Analyze, test, build, and ${{ github.event_name == 'pull_request' && 'validate on' || 'upload to' }} Google Play runs-on: ubuntu-latest permissions: @@ -73,3 +73,9 @@ jobs: echo "keyPassword=$MOBILE_APP_ANDROID_UPLOAD_KEY_PASSPHRASE" >> key.properties echo "keyAlias=upload" >> key.properties echo "storeFile=$(pwd)/upload-keystore.jks" >> key.properties + ios: + name: static checks for ios app + runs-on: ubuntu-latest + steps: + - run: brew install swiftlint + - run: swiftlint From f2aeca998893af6b9a0cbace07e75841bf795526 Mon Sep 17 00:00:00 2001 From: KaylaBrady <31781298+KaylaBrady@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:07:26 -0500 Subject: [PATCH 03/10] style: run spotlessApply --- androidApp/build.gradle.kts | 24 ++------ .../mbta/tid/mbta_app/android/MainActivity.kt | 4 +- .../mbta_app/android/MyApplicationTheme.kt | 57 +++++++++---------- 3 files changed, 34 insertions(+), 51 deletions(-) diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index e2a8cf23f..683b17e79 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -13,29 +13,15 @@ android { versionCode = 1 versionName = "1.0" } - buildFeatures { - compose = true - } - composeOptions { - kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() - } - packaging { - resources { - excludes += "/META-INF/{AL2.0,LGPL2.1}" - } - } - buildTypes { - getByName("release") { - isMinifyEnabled = false - } - } + buildFeatures { compose = true } + composeOptions { kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() } + packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } + buildTypes { getByName("release") { isMinifyEnabled = false } } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } - kotlinOptions { - jvmTarget = "1.8" - } + kotlinOptions { jvmTarget = "1.8" } } dependencies { diff --git a/androidApp/src/main/java/com/mbta/tid/mbta_app/android/MainActivity.kt b/androidApp/src/main/java/com/mbta/tid/mbta_app/android/MainActivity.kt index 8ea948a3a..457b3587f 100644 --- a/androidApp/src/main/java/com/mbta/tid/mbta_app/android/MainActivity.kt +++ b/androidApp/src/main/java/com/mbta/tid/mbta_app/android/MainActivity.kt @@ -34,7 +34,5 @@ fun GreetingView(text: String) { @Preview @Composable fun DefaultPreview() { - MyApplicationTheme { - GreetingView("Hello, Android!") - } + MyApplicationTheme { GreetingView("Hello, Android!") } } diff --git a/androidApp/src/main/java/com/mbta/tid/mbta_app/android/MyApplicationTheme.kt b/androidApp/src/main/java/com/mbta/tid/mbta_app/android/MyApplicationTheme.kt index 70f4921e0..e6aa07646 100644 --- a/androidApp/src/main/java/com/mbta/tid/mbta_app/android/MyApplicationTheme.kt +++ b/androidApp/src/main/java/com/mbta/tid/mbta_app/android/MyApplicationTheme.kt @@ -20,36 +20,35 @@ fun MyApplicationTheme( darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit ) { - val colors = if (darkTheme) { - darkColorScheme( - primary = Color(0xFFBB86FC), - secondary = Color(0xFF03DAC5), - tertiary = Color(0xFF3700B3) + val colors = + if (darkTheme) { + darkColorScheme( + primary = Color(0xFFBB86FC), + secondary = Color(0xFF03DAC5), + tertiary = Color(0xFF3700B3) + ) + } else { + lightColorScheme( + primary = Color(0xFF6200EE), + secondary = Color(0xFF03DAC5), + tertiary = Color(0xFF3700B3) + ) + } + val typography = + Typography( + bodyMedium = + TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp + ) ) - } else { - lightColorScheme( - primary = Color(0xFF6200EE), - secondary = Color(0xFF03DAC5), - tertiary = Color(0xFF3700B3) + val shapes = + Shapes( + small = RoundedCornerShape(4.dp), + medium = RoundedCornerShape(4.dp), + large = RoundedCornerShape(0.dp) ) - } - val typography = Typography( - bodyMedium = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 16.sp - ) - ) - val shapes = Shapes( - small = RoundedCornerShape(4.dp), - medium = RoundedCornerShape(4.dp), - large = RoundedCornerShape(0.dp) - ) - MaterialTheme( - colorScheme = colors, - typography = typography, - shapes = shapes, - content = content - ) + MaterialTheme(colorScheme = colors, typography = typography, shapes = shapes, content = content) } From af37f5f66b832d20b1686538a885f1a62817c541 Mon Sep 17 00:00:00 2001 From: KaylaBrady <31781298+KaylaBrady@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:12:46 -0500 Subject: [PATCH 04/10] style: spotlessApply on shared dir --- shared/build.gradle.kts | 30 ++++--------------- .../com/mbta/tid/mbta_app/Platform.android.kt | 2 +- .../kotlin/com/mbta/tid/mbta_app/Greeting.kt | 2 +- .../kotlin/com/mbta/tid/mbta_app/Platform.kt | 2 +- .../kotlin/com/mbta/tid/mbta_app/Test.kt | 2 +- .../com/mbta/tid/mbta_app/Platform.ios.kt | 7 +++-- .../kotlin/com/mbta/tid/mbta_app/Test.ios.kt | 2 +- 7 files changed, 15 insertions(+), 32 deletions(-) diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index b5d37475b..41e7b025c 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -7,42 +7,24 @@ plugins { kotlin { targetHierarchy.default() - androidTarget { - compilations.all { - kotlinOptions { - jvmTarget = "1.8" - } - } - } + androidTarget { compilations.all { kotlinOptions { jvmTarget = "1.8" } } } - listOf( - iosX64(), - iosArm64(), - iosSimulatorArm64() - ).forEach { - it.binaries.framework { - baseName = "shared" - } + listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach { + it.binaries.framework { baseName = "shared" } } sourceSets { val commonMain by getting { dependencies { - //put your multiplatform dependencies here - } - } - val commonTest by getting { - dependencies { - implementation(libs.kotlin.test) + // put your multiplatform dependencies here } } + val commonTest by getting { dependencies { implementation(libs.kotlin.test) } } } } android { namespace = "com.mbta.tid.mbta_app" compileSdk = 34 - defaultConfig { - minSdk = 28 - } + defaultConfig { minSdk = 28 } } diff --git a/shared/src/androidMain/kotlin/com/mbta/tid/mbta_app/Platform.android.kt b/shared/src/androidMain/kotlin/com/mbta/tid/mbta_app/Platform.android.kt index 6e000f575..24a8a1ff2 100644 --- a/shared/src/androidMain/kotlin/com/mbta/tid/mbta_app/Platform.android.kt +++ b/shared/src/androidMain/kotlin/com/mbta/tid/mbta_app/Platform.android.kt @@ -4,4 +4,4 @@ class AndroidPlatform : Platform { override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}" } -actual fun getPlatform(): Platform = AndroidPlatform() \ No newline at end of file +actual fun getPlatform(): Platform = AndroidPlatform() diff --git a/shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/Greeting.kt b/shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/Greeting.kt index 6bf0c07b6..0eb407553 100644 --- a/shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/Greeting.kt +++ b/shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/Greeting.kt @@ -6,4 +6,4 @@ class Greeting { fun greet(): String { return "Hello, ${platform.name}!" } -} \ No newline at end of file +} diff --git a/shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/Platform.kt b/shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/Platform.kt index 1652b90ec..72feae8d2 100644 --- a/shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/Platform.kt +++ b/shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/Platform.kt @@ -4,4 +4,4 @@ interface Platform { val name: String } -expect fun getPlatform(): Platform \ No newline at end of file +expect fun getPlatform(): Platform diff --git a/shared/src/commonTest/kotlin/com/mbta/tid/mbta_app/Test.kt b/shared/src/commonTest/kotlin/com/mbta/tid/mbta_app/Test.kt index 459feb0e5..4b0f38cfc 100644 --- a/shared/src/commonTest/kotlin/com/mbta/tid/mbta_app/Test.kt +++ b/shared/src/commonTest/kotlin/com/mbta/tid/mbta_app/Test.kt @@ -9,4 +9,4 @@ class CommonGreetingTest { fun testExample() { assertTrue(Greeting().greet().contains("Hello"), "Check 'Hello' is mentioned") } -} \ No newline at end of file +} diff --git a/shared/src/iosMain/kotlin/com/mbta/tid/mbta_app/Platform.ios.kt b/shared/src/iosMain/kotlin/com/mbta/tid/mbta_app/Platform.ios.kt index 39929f312..216984440 100644 --- a/shared/src/iosMain/kotlin/com/mbta/tid/mbta_app/Platform.ios.kt +++ b/shared/src/iosMain/kotlin/com/mbta/tid/mbta_app/Platform.ios.kt @@ -2,8 +2,9 @@ package com.mbta.tid.mbta_app import platform.UIKit.UIDevice -class IOSPlatform: Platform { - override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion +class IOSPlatform : Platform { + override val name: String = + UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion } -actual fun getPlatform(): Platform = IOSPlatform() \ No newline at end of file +actual fun getPlatform(): Platform = IOSPlatform() diff --git a/shared/src/iosTest/kotlin/com/mbta/tid/mbta_app/Test.ios.kt b/shared/src/iosTest/kotlin/com/mbta/tid/mbta_app/Test.ios.kt index 51d98c8a6..a0004a89e 100644 --- a/shared/src/iosTest/kotlin/com/mbta/tid/mbta_app/Test.ios.kt +++ b/shared/src/iosTest/kotlin/com/mbta/tid/mbta_app/Test.ios.kt @@ -9,4 +9,4 @@ class IosGreetingTest { fun testExample() { assertTrue(Greeting().greet().contains("iOS"), "Check iOS is mentioned") } -} \ No newline at end of file +} From 393af9bd26c65106a4a6f7466582f743118d6526 Mon Sep 17 00:00:00 2001 From: KaylaBrady <31781298+KaylaBrady@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:35:44 -0500 Subject: [PATCH 05/10] style: add swiftlint pre-commit hooks, apply pre-commit hooks to all files --- .pre-commit-config.yaml | 4 + androidApp/src/main/AndroidManifest.xml | 2 +- androidApp/src/main/res/values/styles.xml | 2 +- gradle.properties | 2 +- iosApp/iosApp.xcodeproj/project.pbxproj | 752 +++++++++--------- .../AccentColor.colorset/Contents.json | 12 +- .../AppIcon.appiconset/Contents.json | 118 +-- iosApp/iosApp/Assets.xcassets/Contents.json | 8 +- iosApp/iosApp/ContentView.swift | 2 +- iosApp/iosApp/{iOSApp.swift => IOSApp.swift} | 4 +- iosApp/iosApp/Info.plist | 2 +- .../Preview Assets.xcassets/Contents.json | 8 +- 12 files changed, 460 insertions(+), 456 deletions(-) rename iosApp/iosApp/{iOSApp.swift => IOSApp.swift} (78%) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9380b13f2..daa94ff13 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,3 +9,7 @@ repos: types: [text] files: \.(json|arb)$ args: ["--autofix"] + - repo: https://github.com/realm/SwiftLint + rev: 0.54.0 + hooks: + - id: swiftlint diff --git a/androidApp/src/main/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml index 22d1facc8..f62ac2fbe 100644 --- a/androidApp/src/main/AndroidManifest.xml +++ b/androidApp/src/main/AndroidManifest.xml @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/androidApp/src/main/res/values/styles.xml b/androidApp/src/main/res/values/styles.xml index 6b4fa3d08..676b4ddaf 100644 --- a/androidApp/src/main/res/values/styles.xml +++ b/androidApp/src/main/res/values/styles.xml @@ -1,3 +1,3 @@