From 54ac469a3de71256836610ee78d3a14599f84fb9 Mon Sep 17 00:00:00 2001 From: David Chavez Date: Wed, 7 Feb 2024 00:09:36 +0100 Subject: [PATCH] chore(version): Bump to Java 11 / Enable KVM in CI (#103) --- .github/actions/get-avd-info/action.yml | 19 +++ .github/workflows/validate.yml | 136 ++++++------------ build.gradle | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- kotlin-audio-example/build.gradle.kts | 6 +- kotlin-audio/build.gradle | 14 +- .../src/androidTest/AndroidManifest.xml | 3 +- kotlin-audio/src/main/AndroidManifest.xml | 2 - 8 files changed, 74 insertions(+), 112 deletions(-) create mode 100644 .github/actions/get-avd-info/action.yml delete mode 100644 kotlin-audio/src/main/AndroidManifest.xml diff --git a/.github/actions/get-avd-info/action.yml b/.github/actions/get-avd-info/action.yml new file mode 100644 index 00000000..97a78632 --- /dev/null +++ b/.github/actions/get-avd-info/action.yml @@ -0,0 +1,19 @@ +name: "Get AVD Info" +description: "Get the AVD info based on its API level." +inputs: + api-level: + required: true +outputs: + arch: + value: ${{ steps.get-avd-arch.outputs.arch }} + target: + value: ${{ steps.get-avd-target.outputs.target }} +runs: + using: "composite" + steps: + - id: get-avd-arch + run: echo "arch=$(if [ ${{ inputs.api-level }} -ge 30 ]; then echo x86_64; else echo x86; fi)" >> $GITHUB_OUTPUT + shell: bash + - id: get-avd-target + run: echo "target=$(echo default)" >> $GITHUB_OUTPUT + shell: bash diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 2a73e54b..e62bcdea 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -1,37 +1,32 @@ name: validate on: push: - branches: [main] + branches: + - main pull_request: - branches: [main] + types: [opened, synchronize] concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + # Limit concurrency to 1 for PRs. 'main' concurrency isn't limited. + group: ${{ github.head_ref || github.run_id }} cancel-in-progress: true +env: + JAVA_VERSION: 11 jobs: - unit-tests: - runs-on: macos-latest - timeout-minutes: 75 + test: + runs-on: ubuntu-latest + timeout-minutes: 60 strategy: fail-fast: false matrix: - # Refactor to make these dynamic with a low/high bracket only on schedule, not push - # For now this is just the fastest combo (api/arch/target/snapshot-warm-time) based on testing - api-level: [29] - arch: [x86_64] - target: [google_apis] - first-boot-delay: [600] - # This is useful for benchmarking, do 0, 1, 2, etc (up to 256 max job-per-matrix limit) for averages - iteration: [0] - env: - JAVA_TOOL_OPTIONS: -Xmx4g -XX:+UseParallelGC + api-level: [26, 31] steps: - name: Checkout Repo uses: actions/checkout@v2 - name: Setup Java - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: '11' + distribution: "adopt" + java-version: ${{ env.JAVA_VERSION }} - name: Setup Gradle uses: gradle/gradle-build-action@v2 timeout-minutes: 5 @@ -40,96 +35,45 @@ jobs: # Builds on other branches will only read from main branch cache writes # Comment this and the with: above out for performance testing on a branch cache-read-only: ${{ github.ref != 'refs/heads/main' }} - - - name: Warm Gradle Cache - # This makes sure we fetch gradle network resources with a retry - uses: nick-invision/retry@v2 - with: - timeout_minutes: 15 - retry_wait_seconds: 60 - max_attempts: 3 - command: ./gradlew :kotlin-audio:packageDebugAndroidTest --daemon - # This appears to be 'Cache Size: ~1230 MB (1290026823 B)' based on watching action logs - # Repo limit is 10GB; branch caches are independent; branches may read default branch cache. - # We don't want branches to evict main branch snapshot, so save on main, read-only all else - - name: AVD cache - uses: actions/cache@v3 - id: avd-cache - with: - path: | - ~/.android/avd/* - ~/.android/adb* - key: avd-${{ matrix.api-level }}-${{ matrix.arch }}-${{matrix.target}}-v1-${{ hashFiles('~/.android/avd/**/snapshots/**') }} - restore-keys: | - avd-${{ matrix.api-level }}-${{ matrix.arch }}-${{matrix.target}}-v1 - - name: AVD Boot and Snapshot Creation - # Only generate a snapshot for saving if we are on main branch with a cache miss - # Comment the if out to generate snapshots on branch for performance testing - if: steps.avd-cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/main' - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ matrix.api-level }} - force-avd-creation: false - target: ${{ matrix.target }} - arch: ${{ matrix.arch }} - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - sdcard-path-or-size: 100M - disable-animations: true - # Give the emulator a little time to run and do first boot stuff before taking snapshot - script: echo "Generated AVD snapshot for caching." - - # This step is separate so pure install time may be calculated as a step - - name: Emulator Snapshot After Firstboot Warmup - # Only generate a snapshot for saving if we are on main branch with a cache miss - # Switch the if statements via comment if generating snapshots for performance testing - # if: matrix.first-boot-delay != '0' - if: steps.avd-cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/main' - env: - FIRST_BOOT_DELAY: ${{ matrix.first-boot-delay }} - uses: reactivecircus/android-emulator-runner@v2 + # API 30+ emulators only have x86_64 system images. + - name: Get AVD info + uses: ./.github/actions/get-avd-info + id: avd-info with: api-level: ${{ matrix.api-level }} - force-avd-creation: false - target: ${{ matrix.target }} - arch: ${{ matrix.arch }} - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - sdcard-path-or-size: 100M - disable-animations: true - # Give the emulator a little time to run and do first boot stuff before taking snapshot - script: | - sleep $FIRST_BOOT_DELAY - echo "First boot warmup completed." - - name: Run Emulator Tests + - 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: Run Instrumented Tests uses: reactivecircus/android-emulator-runner@v2 - timeout-minutes: 30 with: api-level: ${{ matrix.api-level }} - force-avd-creation: false - target: ${{ matrix.target }} - arch: ${{ matrix.arch }} - emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - sdcard-path-or-size: 100M - disable-animations: true - script: | - $ANDROID_HOME/platform-tools/adb logcat '*:D' > adb-log.txt & - sleep 5 - $ANDROID_HOME/platform-tools/adb shell su root "setprop ctl.restart zygote" - sleep 10 - ./gradlew :kotlin-audio:connectedCheck --daemon + arch: ${{ steps.avd-info.outputs.arch }} + target: ${{ steps.avd-info.outputs.target }} + script: ./gradlew :kotlin-audio:connectedCheck - name: Publish Test Report uses: mikepenz/action-junit-report@v3 if: always() # always run even if the previous step fails with: - report_paths: 'kotlin-audio/build/outputs/androidTest-results/**/TEST-*.xml' + report_paths: "kotlin-audio/build/outputs/androidTest-results/**/TEST-*.xml" build-sample: - runs-on: macos-latest + runs-on: blaze/macos-14 steps: - name: Checkout Repo uses: actions/checkout@v2 - - name: Setup Java - uses: actions/setup-java@v2 + - uses: actions/setup-java@v4 with: - distribution: 'adopt' - java-version: '11' + distribution: "adopt" + java-version: 11 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + timeout-minutes: 5 + with: + # Only write to the cache for builds on the 'main' branches, stops branches evicting main cache + # Builds on other branches will only read from main branch cache writes + # Comment this and the with: above out for performance testing on a branch + cache-read-only: ${{ github.ref != 'refs/heads/main' }} - name: Build Example App run: ./gradlew :kotlin-audio-example:assembleDebug diff --git a/build.gradle b/build.gradle index a49bff3d..e8f49610 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { maven { url 'https://jitpack.io' } } dependencies { - classpath 'com.android.tools.build:gradle:7.0.4' + classpath 'com.android.tools.build:gradle:7.3.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10" classpath "de.mannodermaus.gradle.plugins:android-junit5:1.8.2.0" @@ -27,4 +27,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} \ No newline at end of file +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 57bc0852..2ae5c0e2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Aug 16 18:14:46 CEST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/kotlin-audio-example/build.gradle.kts b/kotlin-audio-example/build.gradle.kts index 32c950c9..3ec3cc7b 100644 --- a/kotlin-audio-example/build.gradle.kts +++ b/kotlin-audio-example/build.gradle.kts @@ -5,12 +5,12 @@ plugins { android { namespace = "com.example.kotlin_audio_example" - compileSdk = 33 + compileSdk = 34 defaultConfig { applicationId = "com.example.kotlin_audio_example" minSdk = 21 - targetSdk = 33 + targetSdk = 34 versionCode = 1 versionName = "1.0" @@ -77,4 +77,4 @@ dependencies { androidTestImplementation("androidx.compose.ui:ui-test-junit4") debugImplementation("androidx.compose.ui:ui-tooling") debugImplementation("androidx.compose.ui:ui-test-manifest") -} \ No newline at end of file +} diff --git a/kotlin-audio/build.gradle b/kotlin-audio/build.gradle index 1edac783..463413be 100644 --- a/kotlin-audio/build.gradle +++ b/kotlin-audio/build.gradle @@ -11,11 +11,13 @@ group = 'com.github.doublesymmetry' version = versionNumber android { - compileSdk 31 + namespace = "com.doublesymmetry.kotlinaudio" + + compileSdk 34 defaultConfig { minSdk 21 - targetSdk 31 + targetSdk 34 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder" @@ -28,11 +30,11 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '11' } } @@ -97,4 +99,4 @@ afterEvaluate { task sourcesJar(type: Jar) { archiveClassifier.set('sources') from android.sourceSets.main.java.srcDirs -} \ No newline at end of file +} diff --git a/kotlin-audio/src/androidTest/AndroidManifest.xml b/kotlin-audio/src/androidTest/AndroidManifest.xml index a781eea8..19d2638e 100644 --- a/kotlin-audio/src/androidTest/AndroidManifest.xml +++ b/kotlin-audio/src/androidTest/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/kotlin-audio/src/main/AndroidManifest.xml b/kotlin-audio/src/main/AndroidManifest.xml deleted file mode 100644 index 601f259d..00000000 --- a/kotlin-audio/src/main/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file