-
Notifications
You must be signed in to change notification settings - Fork 11
/
validate_plugin
executable file
·92 lines (73 loc) · 3.38 KB
/
validate_plugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
# Validate that the plugin works correctly.
set -e
TARGET="$1"
# Checks if the target passed in matches the first argument. If no argument is given, then all targets should run
function should_run_target() {
name="$1"
if [[ "${TARGET}" -eq "${name}" || -z "${TARGET}" ]]; then
return 0
else
return 1
fi
}
function kill_emulator() {
pkill emulator || true
pkill emulator64-arm || true
pkill emulator64-x86 || true
rm -f ./example-android-project/build/android-avd-root/*/*.lock
}
# Clean up possibly existing files to ensure a fresh start
rm -f 'example-android-project/local.properties'
rm -rf 'example-android-project/build'
rm -rf 'android-emulator-plugin/build'
# Plugin locally to be consumed by example project
./gradlew -p android-emulator-plugin publishToMavenLocal
# ADB install may take longer than normal in CI due to potentially low-power machines
export ADB_INSTALL_TIMEOUT=10
# Add additional gradle options for testing
export GRADLE_OPTS="${GRADLE_OPTS} -Dorg.gradle.logging.level=info"
# Run the test on the default (for the project) emulator as well as using an older SDK version
# Run one after the other to ensure the plugin handles changing of configuration.
if should_run_target 1; then
./gradlew -p example-android-project connectedCheck
kill_emulator
ANDROID_EMULATOR_SDK_VERSION=21 ./gradlew -p example-android-project connectedCheck
fi
# Use a google_apis flavor
if should_run_target 2; then
ANDROID_EMULATOR_SDK_VERSION=24 ANDROID_EMULATOR_GOOGLE_APIS=true ./gradlew -p example-android-project connectedCheck
fi
# Validate that the emulator is needed or the tests would fail due to a lack of devices
if should_run_target 3; then
ENABLE_FOR_ANDROID_TESTS=false ./gradlew -p example-android-project connectedCheck &&
echo 'Build should not have succeeded' && exit 1 ||
echo 'Build failure expected due to "No connected devices!"'
fi
# Use a newer version of Gradle plugin
if should_run_target 4; then
ANDROID_GRADLE_VERSION=7.1.0 ANDROID_EMULATOR_GOOGLE_APIS=true ANDROID_EMULATOR_SDK_VERSION=24 ./gradlew -p example-android-project connectedCheck
fi
# Use the logEmulatorOutput flag
if should_run_target 5; then
LOG_ANDROID_EMULATOR=true ANDROID_EMULATOR_SDK_VERSION=24 ANDROID_EMULATOR_GOOGLE_APIS=true ./gradlew -p example-android-project connectedCheck
fi
# Use the failed emulator starts don't hang forever
if should_run_target 6; then
FAIL_EMULATOR_STARTUP=true ./gradlew -p example-android-project assemble # Prove the flag doesn't fail the build
FAIL_EMULATOR_STARTUP=true ./gradlew -p example-android-project connectedCheck &&
echo 'Build should not have succeeded' && exit 1 ||
echo 'Build failure expected due to invalid emulator arguments'
fi
# Use the emulator's device field by specifying the device type
if should_run_target 7; then
ANDROID_EMULATOR_SDK_VERSION=24 ANDROID_EMULATOR_DEVICE=pixel_xl ./gradlew -p example-android-project connectedCheck
fi
# Use the device field by specifying the device code
if should_run_target 8; then
ANDROID_EMULATOR_SDK_VERSION=24 ANDROID_EMULATOR_DEVICE=19 ./gradlew -p example-android-project connectedCheck
fi
# Use the latest Gradle plugin
if should_run_target 9; then
ANDROID_GRADLE_VERSION=7.3.0 ANDROID_EMULATOR_GOOGLE_APIS=true ANDROID_EMULATOR_SDK_VERSION=24 ./gradlew -p example-android-project connectedCheck
fi