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

ci: formatting, unit tests #14

Merged
merged 10 commits into from
Dec 19, 2023
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
36 changes: 33 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,6 +20,15 @@ jobs:
- name: Read asdf versions
id: asdf
run: cat .tool-versions | sed 's/ /=/' | tee -a "$GITHUB_OUTPUT"
- name: Parse java version
id: java-spec
run: |
DISTRIBUTION=(`echo ${{steps.asdf.outputs.java}} | cut -d - -f1`)
VERSION=(`echo ${{steps.asdf.outputs.java}} | cut -d - -f2`)
echo "java-distribution=$DISTRIBUTION" >> "$GITHUB_OUTPUT"
echo "java-version=$VERSION" >> "$GITHUB_OUTPUT"


- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -34,9 +43,30 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
distribution: ${{steps.java-spec.outputs.java-distribution}}
java-version: ${{steps.java-spec.outputs.java-version}}
cache: gradle
- uses: actions/cache@v3
with:
path: ~/.konan
key: konan-${{ runner.os }}-${{ hashFiles('build.gradle.kts') }}
restore-keys: konan-${{ runner.os }}
- run: ./gradlew spotlessCheck
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved spotless check up above running tests

- 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:
Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ repos:
types: [text]
files: \.(json|arb)$
args: ["--autofix"]
- repo: https://github.com/realm/SwiftLint
rev: 0.54.0
hooks:
- id: swiftlint
- repo: https://github.com/jguttman94/pre-commit-gradle
rev: v0.3.0
hooks:
- id: gradle-spotless
entry: gradle-spotless -w
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ruby 3.2.2
java temurin-17.0.9+9
26 changes: 6 additions & 20 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -45,4 +31,4 @@ dependencies {
implementation(libs.compose.material3)
implementation(libs.androidx.activity.compose)
debugImplementation(libs.compose.ui.tooling)
}
}
2 changes: 1 addition & 1 deletion androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
</intent-filter>
</activity>
</application>
</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,5 @@ fun GreetingView(text: String) {
@Preview
@Composable
fun DefaultPreview() {
MyApplicationTheme {
GreetingView("Hello, Android!")
}
MyApplicationTheme { GreetingView("Hello, Android!") }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion androidApp/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<style name="AppTheme" parent="android:Theme.Material.NoActionBar"/>
</resources>
</resources>
46 changes: 45 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

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.withType<org.gradle.api.tasks.testing.Test> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taken from this SO post about logging test output. There is a plugin linked from a different answer that does this and more, though customizing test logging seems to me like something that should be reasonably done out of the box.

Also planning to add a ticket to the backlog for reporting code coverage on the PR, potentially with JaCoCo

testLogging {
// set options for log level LIFECYCLE
events = setOf(
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
)

exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
showExceptions = true
showCauses = true
showStackTraces = true
}
}
}

tasks.getByName("clean", Delete::class) {
delete(rootProject.buildDir)
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ android.useAndroidX=true
android.nonTransitiveRClass=true

#MPP
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.enableCInteropCommonization=true
Loading