Use AGP to do some unit tests and add ccache (#25)

This commit is contained in:
LoveSy 2022-09-20 01:40:29 +08:00 committed by GitHub
parent 0864159fc4
commit cf9b95f6d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 123 additions and 56 deletions

View File

@ -32,10 +32,19 @@ jobs:
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ runner.os }}-${{ github.sha }}
restore-keys: ${{ runner.os }}
- name: Build with Gradle
run: |
ccache -o cache_dir=${{ github.workspace }}/.ccache
ccache -o hash_dir=false
ccache -o compiler_check='%compiler% -dumpmachine; %compiler% -dumpversion'
ccache -p
echo 'android.native.buildOutput=verbose' >> gradle.properties
./gradlew :lsplant:publishToMavenLocal
./gradlew :lsplant:publishToMavenLocal :lsplant:prefabDebugPackage
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.maven_pgp_signingKey }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.maven_pgp_signingPassword }}
@ -45,6 +54,51 @@ jobs:
name: ${{ matrix.os }}-library
path: ~/.m2
agp-test:
needs: build
name: Test using AGP
runs-on: macos-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}
restore-keys: gradle-${{ runner.os }}-
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ runner.os }}-${{ github.sha }}
restore-keys: ${{ runner.os }}
save: false
- name: Test with Gradle
run: |
ccache -o cache_dir=${{ github.workspace }}/.ccache
ccache -o hash_dir=false
ccache -o compiler_check='%compiler% -dumpmachine; %compiler% -dumpversion'
echo -e "84831b9409646a918e30573bab4c9c91346d8abd" > $ANDROID_SDK_ROOT/licenses/android-sdk-preview-license
echo 'android.testoptions.manageddevices.emulator.gpu=swiftshader_indirect' >> gradle.properties
echo 'android.native.buildOutput=verbose' >> gradle.properties
echo 'android.sdk.channel=3' >> gradle.properties
./gradlew :test:allDevicesDebugAndroidTest
rm -v test/build/outputs/androidTest-results/managedDevice/*/testlog/adb.additional_test_output*
- name: Upload outputs
if: always()
uses: actions/upload-artifact@v2
with:
name: test-outputs
path: test/build/outputs
test:
needs: build
name: Test on API ${{ matrix.api-level }} ${{ matrix.arch }}
@ -89,42 +143,9 @@ jobs:
- api-level: 26
target: default
arch: x86
- api-level: 27
target: default
arch: x86_64
- api-level: 27
target: default
arch: x86
- api-level: 28
target: default
arch: x86_64
- api-level: 28
target: default
arch: x86
- api-level: 29
target: default
arch: x86_64
- api-level: 29
target: default
arch: x86
- api-level: 30
target: default
arch: x86_64
- api-level: 30
target: google_apis
arch: x86
- api-level: 31
target: default
arch: x86_64
- api-level: 31
target: android-tv
arch: x86
- api-level: 32
target: google_apis
arch: x86_64
- api-level: 33
target: google_apis
arch: x86_64
steps:
- name: checkout
uses: actions/checkout@v2
@ -134,14 +155,6 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: '11'
- name: AVD cache
uses: actions/cache@v2
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}-${{ matrix.arch }}-${{ matrix.target }}
- name: Gradle cache
uses: actions/cache@v2
with:
@ -150,26 +163,24 @@ jobs:
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ matrix.api-level }}-${{ matrix.arch }}-${{ matrix.target }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}
restore-keys: gradle-${{ runner.os }}-
- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@release/v2
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
api-level: ${{ matrix.api-level }}
arch: ${{ matrix.arch }}
target: ${{ matrix.target }}
script: echo "Generated AVD snapshot for caching."
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
avd-name: ${{ matrix.api-level }}_${{ matrix.arch }}
key: ${{ runner.os }}-${{ github.sha }}
restore-keys: ${{ runner.os }}
save: false
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
arch: ${{ matrix.arch }}
target: ${{ matrix.target }}
script: ./gradlew :lsplant:prefabDebugConfigurePackage; ./gradlew :test:connectedCheck
force-avd-creation: false
script: |
ccache -o cache_dir=${{ github.workspace }}/.ccache
ccache -o hash_dir=false
ccache -o compiler_check='%compiler% -dumpmachine; %compiler% -dumpversion'
echo 'android.native.buildOutput=verbose' >> gradle.properties
./gradlew :test:connectedCheck
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
avd-name: ${{ matrix.api-level }}_${{ matrix.arch }}

View File

@ -1,3 +1,5 @@
import java.nio.file.Paths
plugins {
id("com.android.library")
id("maven-publish")
@ -11,6 +13,16 @@ val androidCompileSdkVersion: Int by rootProject.extra
val androidNdkVersion: String by rootProject.extra
val androidCmakeVersion: String by rootProject.extra
fun findInPath(executable: String): String? {
val pathEnv = System.getenv("PATH")
return pathEnv.split(File.pathSeparator).map { folder ->
Paths.get("${folder}${File.separator}${executable}${if (org.gradle.internal.os.OperatingSystem.current().isWindows) ".exe" else ""}")
.toFile()
}.firstOrNull { path ->
path.exists()
}?.absolutePath
}
android {
compileSdk = androidCompileSdkVersion
ndkVersion = androidNdkVersion
@ -74,6 +86,10 @@ android {
"-DCMAKE_C_FLAGS_RELEASE=$configFlags",
"-DDEBUG_SYMBOLS_PATH=${project.buildDir.absolutePath}/symbols/$name",
)
findInPath("ccache")?.let {
println("Using ccache $it")
arguments += "-DANDROID_CCACHE=$it"
}
}
}
}

View File

@ -1,3 +1,5 @@
import com.android.build.api.dsl.ManagedVirtualDevice
plugins {
id("com.android.application")
}
@ -10,6 +12,7 @@ val androidNdkVersion: String by rootProject.extra
val androidCmakeVersion: String by rootProject.extra
android {
namespace = "org.lsposed.lsplant.test"
compileSdk = androidCompileSdkVersion
ndkVersion = androidNdkVersion
buildToolsVersion = androidBuildToolsVersion
@ -44,7 +47,44 @@ android {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
namespace = "org.lsposed.lsplant"
testOptions {
managedDevices {
devices {
fun createDevice(api: Int, is64: Boolean, target: String = "default") = create<ManagedVirtualDevice>("""avd-$api-${if(is64) "x86_64" else "x86"}-$target""") {
device = "Pixel 2"
apiLevel = api
systemImageSource = target
require64Bit = is64
}
// createDevice(21, false)
// createDevice(21, true)
// createDevice(22, false)
// createDevice(22, true)
// createDevice(23, false)
// createDevice(23, true)
// createDevice(24, false)
// createDevice(24, true)
// createDevice(25, false)
// createDevice(25, true)
// createDevice(26, false)
// createDevice(26, true)
createDevice(27, false)
createDevice(27, true)
createDevice(28, false)
createDevice(28, true)
createDevice(29, false)
createDevice(29, true)
createDevice(30, false, "aosp_atd")
createDevice(30, true)
// createDevice(31, false, "android-tv")
createDevice(31, true, "aosp_atd")
createDevice(32, true, "google_apis")
createDevice(33, true, "google_apis")
}
}
}
}
dependencies {