Skip to content

Commit

Permalink
CI Workflow Dependency Upgrades + Optimization 👷 (#3369)
Browse files Browse the repository at this point in the history
* CI Workflow Dependency Upgrades + Optimization 👷

* Migrate CI workflow to use Ubuntu runner

* Update CI Workflow with KVM

* Troubleshooting: Force recreation of AVD for Quest

* Troubleshooting: Update CI Workflow configuration

* Update Quest module workflow configuration | AVD

* Troubleshooting configuration
- Add workflow dispatch event trigger
- Disable CI runs for working modules
- Reset Quest test run and reporting configuration

* Update CI workflow configuration
- Update path to emulator SDK
- Enable Engine and Geowidget jobs

* Update CI workflow configuration:Quest Tests 👷

* Add Target SDK build.gradle configuration 🔧

* Unit Test troubleshooting

* Unit Test troubleshooting

* Troubleshooting: Quest module Unit Tests

* Apply Spotless to Quest

* [DNM] Quest Module tests troubleshooting (#3387)

* Upgrade JUnit 5
* Update CI configuration for maintainability 👷
* Refactor Gradle Configs for maintainability 🔧
* Refactor unit tests to runTest
  • Loading branch information
ndegwamartin authored Jul 24, 2024
1 parent eda28fa commit 9b51114
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 52 deletions.
93 changes: 67 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
name: CI

on:
workflow_dispatch:
pull_request:
branches: [ main ]
merge_group:
Expand All @@ -17,7 +18,7 @@ env:

jobs:
engine-tests:
runs-on: macos-13
runs-on: ubuntu-latest
strategy:
matrix:
api-level: [30]
Expand All @@ -28,15 +29,20 @@ jobs:
access_token: ${{ github.token }}

- name: Checkout 🛎️
uses: actions/checkout@v2
with:
fetch-depth: 2
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
distribution: temurin
java-version: 17

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Add empty local.properties
run: touch local.properties
working-directory: android
Expand All @@ -52,15 +58,15 @@ jobs:
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties && cat ~/.gradle/gradle.properties

- name: Setup Gradle cache
uses: gradle/gradle-build-action@v2
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3

- name: Spotless check engine module
run: ./gradlew -PlocalPropertiesFile=local.properties :engine:spotlessCheck :engine:ktlintCheck --stacktrace
working-directory: android

- name: Load AVD cache
uses: actions/cache@v2
uses: actions/cache@v4
id: avd-cache
with:
path: |
Expand All @@ -86,7 +92,7 @@ jobs:
working-directory: android
api-level: ${{ matrix.api-level }}
arch: x86_64
force-avd-creation: true
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: ./gradlew -PlocalPropertiesFile=local.properties :engine:clean :engine:fhircoreJacocoReport --stacktrace
Expand All @@ -97,7 +103,7 @@ jobs:
run: bash <(curl -s https://codecov.io/bash) -F engine -f "engine/build/reports/jacoco/fhircoreJacocoReport/fhircoreJacocoReport.xml"

geowidget-tests:
runs-on: macos-13
runs-on: ubuntu-latest
strategy:
matrix:
api-level: [30]
Expand All @@ -108,15 +114,20 @@ jobs:
access_token: ${{ github.token }}

- name: Checkout 🛎️
uses: actions/checkout@v2
with:
fetch-depth: 2
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
distribution: temurin
java-version: 17

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Add empty local.properties
run: touch local.properties
working-directory: android
Expand All @@ -132,15 +143,15 @@ jobs:
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties && cat ~/.gradle/gradle.properties

- name: Setup Gradle cache
uses: gradle/gradle-build-action@v2
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3

- name: Spotless check geowidget module
run: ./gradlew -PlocalPropertiesFile=local.properties :geowidget:spotlessCheck --stacktrace
working-directory: android

- name: Load AVD cache
uses: actions/cache@v2
uses: actions/cache@v4
id: avd-cache
with:
path: |
Expand Down Expand Up @@ -177,7 +188,7 @@ jobs:
run: bash <(curl -s https://codecov.io/bash) -F geowidget -f "geowidget/build/reports/jacoco/fhircoreJacocoReport/fhircoreJacocoReport.xml"

quest-tests:
runs-on: macos-13
runs-on: ubuntu-latest
strategy:
matrix:
api-level: [30]
Expand All @@ -187,15 +198,20 @@ jobs:
with:
access_token: ${{ github.token }}
- name: Checkout 🛎️
uses: actions/checkout@v2
with:
fetch-depth: 2
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
distribution: temurin
java-version: 17

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Add empty local.properties
run: touch local.properties
working-directory: android
Expand All @@ -211,15 +227,15 @@ jobs:
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties && cat ~/.gradle/gradle.properties

- name: Setup Gradle cache
uses: gradle/gradle-build-action@v2
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3

- name: Spotless check quest application
run: ./gradlew -PlocalPropertiesFile=local.properties :quest:spotlessCheck --stacktrace :quest:ktlintCheck --stacktrace
working-directory: android

- name: Load AVD cache
uses: actions/cache@v2
uses: actions/cache@v4
id: avd-cache
with:
path: |
Expand All @@ -239,7 +255,7 @@ jobs:
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Run Quest module unit and instrumentation tests and generate coverage report
- name: Run Quest module unit and instrumentation tests and generate unit tests coverage report
uses: reactivecircus/android-emulator-runner@v2
with:
working-directory: android
Expand All @@ -249,9 +265,34 @@ jobs:
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: ./gradlew clean -PlocalPropertiesFile=local.properties :quest:fhircoreJacocoReport --stacktrace -Pandroid.testInstrumentationRunnerArguments.notPackage=org.smartregister.fhircore.quest.performance
# ./gradlew -PlocalPropertiesFile=local.properties :quest:clean && ./gradlew -PlocalPropertiesFile=local.properties :quest:assembleOpensrpDebugAndroidTest --stacktrace && /Users/runner/Library/Android/sdk/platform-tools/adb install quest/build/outputs/apk/androidTest/opensrp/debug/quest-opensrp-debug-androidTest.apk && ./gradlew -PlocalPropertiesFile=local.properties :quest:assembleOpensrpDebug --stacktrace && /Users/runner/Library/Android/sdk/platform-tools/adb install quest/build/outputs/apk/opensrp/debug/quest-opensrp-debug.apk && /Users/runner/Library/Android/sdk/platform-tools/adb shell am instrument -w -e package org.smartregister.fhircore.quest.ui.profile -e coverage "true" org.smartregister.opensrp.test/org.smartregister.fhircore.quest.QuestTestRunner && /Users/runner/Library/Android/sdk/platform-tools/adb shell run-as org.smartregister.opensrp cat "/data/user/0/org.smartregister.opensrp/files/coverage.ec" > quest/coverage.ec && ./gradlew -PlocalPropertiesFile=local.properties :quest:fhircoreJacocoReport --stacktrace


- name: Run Quest module unit and instrumentation tests and generate aggregated coverage report (Disabled)
if: false
uses: reactivecircus/android-emulator-runner@v2
with:
working-directory: android
api-level: ${{ matrix.api-level }}
arch: x86_64
force-avd-creation: true
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
run: |
set -e
./gradlew -PlocalPropertiesFile=local.properties :quest:clean
./gradlew -PlocalPropertiesFile=local.properties :quest:assembleOpensrpDebugAndroidTest --stacktrace
/Users/martin/Library/Android/sdk/platform-tools/adb install quest/build/outputs/apk/androidTest/opensrp/debug/quest-opensrp-debug-androidTest.apk
./gradlew -PlocalPropertiesFile=local.properties :quest:assembleOpensrpDebug --stacktrace
/Users/martin/Library/Android/sdk/platform-tools/adb install quest/build/outputs/apk/opensrp/debug/quest-opensrp-debug.apk
/Users/martin/Library/Android/sdk/platform-tools/adb shell am instrument -w \
--no-window-animation \
-e coverage "true" \
-e debug false \
org.smartregister.opensrp.test/org.smartregister.fhircore.quest.QuestTestRunner
/Users/martin/Library/Android/sdk/platform-tools/adb shell run-as org.smartregister.opensrp \
cat "/data/user/0/org.smartregister.opensrp/files/coverage.ec" > quest/coverage.ec
./gradlew -PlocalPropertiesFile=local.properties :quest:fhircoreJacocoReport --stacktrace
- name: Upload Quest module test coverage report to Codecov
if: matrix.api-level == 30 # Only upload coverage on API level 30
working-directory: android
run: bash <(curl -s https://codecov.io/bash) -F quest -f "quest/build/reports/jacoco/fhircoreJacocoReport/fhircoreJacocoReport.xml"
run: bash <(curl -s https://codecov.io/bash) -F quest -f "quest/build/reports/jacoco/fhircoreJacocoReport/fhircoreJacocoReport.xml"
2 changes: 2 additions & 0 deletions android/buildSrc/src/main/kotlin/BuildConfigs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ object BuildConfigs {
const val kotlinCompilerExtensionVersion = "1.5.8"
const val jacocoVersion ="0.8.11"
const val ktLintVersion = "0.49.0"
const val enableUnitTestCoverage = true
const val enableAndroidTestCoverage = false
}
5 changes: 4 additions & 1 deletion android/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ android {
}

buildTypes {
getByName("debug") { enableUnitTestCoverage = true }
getByName("debug") {
enableUnitTestCoverage = BuildConfigs.enableUnitTestCoverage
enableAndroidTestCoverage = BuildConfigs.enableAndroidTestCoverage
}

create("debugNonProxy") {
initWith(getByName("debug"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import javax.inject.Inject
import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.hl7.fhir.r4.model.ResourceType
import org.junit.Assert
import org.junit.Before
Expand Down Expand Up @@ -100,7 +101,7 @@ class CustomSyncWorkerTest : RobolectricTest() {
}

@Test
fun `should create sync worker with organization`() = runBlocking {
fun `should create sync worker with organization`() = runTest {
sharedPreferencesHelper =
SharedPreferencesHelper(ApplicationProvider.getApplicationContext(), Gson())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.hl7.fhir.r4.model.CanonicalType
import org.hl7.fhir.r4.model.Composition
import org.hl7.fhir.r4.model.Library
Expand Down Expand Up @@ -60,7 +61,7 @@ class FhirEngineExtensionTest : RobolectricTest() {
}

@Test
fun searchCompositionByIdentifier() = runBlocking {
fun searchCompositionByIdentifier() = runTest {
coEvery { fhirEngine.search<Composition>(any()) } returns
listOf(SearchResult(resource = Composition().apply { id = "123" }, null, null))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import kotlin.coroutines.cancellation.CancellationException
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Before
Expand Down Expand Up @@ -72,7 +72,7 @@ class LocationUtilsTest : RobolectricTest() {
}

@Test
fun `test getAccurateLocation`() = runBlocking {
fun `test getAccurateLocation`() = runTest {
val location =
Location("Test location").apply {
latitude = 36.0
Expand All @@ -88,7 +88,7 @@ class LocationUtilsTest : RobolectricTest() {
}

@Test
fun `test getApproximateLocation`() = runBlocking {
fun `test getApproximateLocation`() = runTest {
val location =
Location("").apply {
latitude = 36.0
Expand All @@ -102,7 +102,7 @@ class LocationUtilsTest : RobolectricTest() {
}

@Test
fun `test getAccurateLocation with cancellation`() = runBlocking {
fun `test getAccurateLocation with cancellation`() = runTest {
val job = launch {
delay(500)
coroutineContext.cancel()
Expand Down
6 changes: 5 additions & 1 deletion android/geowidget/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ android {
}

buildTypes {
getByName("debug") { enableUnitTestCoverage = true }
getByName("debug") {
enableUnitTestCoverage = BuildConfigs.enableUnitTestCoverage
enableAndroidTestCoverage = BuildConfigs.enableAndroidTestCoverage
}

create("debugNonProxy") { initWith(getByName("debug")) }

getByName("release") {
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ joda-time = "2.10.14"
json = "20230618"
jsonPath = "2.8.0"
junit = "1.2.1"
junit-jupiter = "5.9.3"
junit-jupiter = "5.10.3"
junit-ktx = "1.2.1"
kotlin = "1.9.22"
kotlin-serialization = "1.8.10"
Expand Down
14 changes: 10 additions & 4 deletions android/quest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ android {
defaultConfig {
applicationId = BuildConfigs.applicationId
minSdk = BuildConfigs.minSdk
targetSdk = BuildConfigs.targetSdk
versionCode = BuildConfigs.versionCode
versionName = BuildConfigs.versionName
multiDexEnabled = true
Expand Down Expand Up @@ -99,15 +100,19 @@ android {
}

buildTypes {
getByName("debug") { enableUnitTestCoverage = true }
getByName("debug") {
enableUnitTestCoverage = BuildConfigs.enableUnitTestCoverage
enableAndroidTestCoverage = BuildConfigs.enableAndroidTestCoverage
}

create("debugNonProxy") { initWith(getByName("debug")) }

create("benchmark") {
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks += listOf("debug")
isDebuggable = true
}

create("debugNonProxy") { initWith(getByName("debug")) }

getByName("release") {
isMinifyEnabled = false
proguardFiles(
Expand Down Expand Up @@ -406,7 +411,8 @@ tasks.withType<Test> {
testLogging { events = setOf(TestLogEvent.FAILED) }
minHeapSize = "4608m"
maxHeapSize = "4608m"
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
// maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
configure<JacocoTaskExtension> { isIncludeNoLocationClasses = true }
}

configurations { all { exclude(group = "xpp3") } }
Expand Down
Loading

0 comments on commit 9b51114

Please sign in to comment.