Setup CI for app-ng

This commit is contained in:
topjohnwu
2026-03-17 20:04:47 -07:00
parent e4f4239f5c
commit 5cb025e7cc
5 changed files with 103 additions and 55 deletions
+69 -33
View File
@@ -32,7 +32,7 @@ case $(uname -m) in
esac
cleanup() {
rm -f magisk_*.img
rm -f magisk-*.img
"$avd" delete avd -n test
}
@@ -72,17 +72,45 @@ wait_emu() {
dump_vars() {
local val
for name in $@ emu_args; do
for name in $@; do
eval val=\$$name
echo $name=\"$val\"\;
echo local $name=\"$val\"\;
done
}
resolve_vars() {
parse_args() {
set +x
local arg_list="$1"
local ver=$2
local type=$3
local return_vals="$1"
shift
local ver=
local type=
while getopts ":v:t:l" opt; do
case $opt in
v )
ver="$OPTARG"
;;
t )
type="$OPTARG"
;;
l )
export AVD_TEST_LOG=1
;;
\? )
echo "Error: Invalid option: -$OPTARG" 1>&2
exit 1
;;
: )
# Missing a required argument is fine as we perform validations later
;;
esac
done
if [ -z $ver ]; then
print_error "! No system image version specified"
exit 1
fi
# Determine API level
local api
@@ -128,8 +156,12 @@ resolve_vars() {
local sys_img_dir="$ANDROID_HOME/system-images/android-$ver/$type/$arch"
local ramdisk="$sys_img_dir/ramdisk.img"
# Dump variables to output
dump_vars $arg_list
# Dump global variables
echo emu_args=\"$emu_args\"
echo OPTIND=$OPTIND
# Dump local variables
dump_vars $return_vals
}
dl_emu() {
@@ -151,9 +183,10 @@ setup_emu() {
}
test_emu() {
local variant=$1
local apk=$1
local image=$2
local magisk_args="-ramdisk magisk_${variant}.img -feature -SystemAsRoot"
local magisk_args="-ramdisk $image -feature -SystemAsRoot"
if [ -n "$AVD_TEST_LOG" ]; then
rm -f logcat.log
@@ -165,7 +198,7 @@ test_emu() {
emu_pid=$!
wait_emu
run_setup $variant
run_setup $apk
adb reboot
wait_emu
@@ -177,8 +210,13 @@ test_emu() {
}
test_main() {
local ver avd_pkg ramdisk
eval $(resolve_vars "ver avd_pkg ramdisk" $1 $2)
local vars
vars=$(parse_args "ver avd_pkg ramdisk" "$@")
eval "$vars"
# Shift off the options we just parsed so that "$@" only contains the remaining positional arguments
shift $((OPTIND - 1))
local apks=($(print_apks "$@"))
# Specify an explicit port so that tests can run with other emulators running at the same time
local emu_port=5682
@@ -198,32 +236,28 @@ test_main() {
wait_emu
# Patch images
if [ -z "$AVD_TEST_SKIP_DEBUG" ]; then
./build.py -v avd_patch "$ramdisk" magisk_debug.img
fi
if [ -z "$AVD_TEST_SKIP_RELEASE" ]; then
./build.py -vr avd_patch "$ramdisk" magisk_release.img
fi
local images=()
for apk in "${apks[@]}"; do
images+=("magisk-$(basename $apk .apk).img")
./build.py -v avd_patch --apk "$apk" "$ramdisk" "${images[-1]}"
done
kill -INT $emu_pid
wait $emu_pid
if [ -z "$AVD_TEST_SKIP_DEBUG" ]; then
print_title "* Testing $avd_pkg (debug)"
test_emu debug
fi
if [ -z "$AVD_TEST_SKIP_RELEASE" ]; then
print_title "* Testing $avd_pkg (release)"
test_emu release
fi
for i in "${!apks[@]}"; do
print_title "* Testing $avd_pkg ($(basename ${apks[i]}))"
test_emu ${apks[i]} ${images[i]}
done
cleanup
}
run_main() {
local ver avd_pkg
eval $(resolve_vars "ver avd_pkg" $1 $2)
local vars
vars=$(parse_args "ver avd_pkg" "$@")
eval "$vars"
setup_emu "$avd_pkg" $ver
print_title "* Launching $avd_pkg"
"$emu" @test $emu_args 2>/dev/null
@@ -231,8 +265,10 @@ run_main() {
}
dl_main() {
local avd_pkg
eval $(resolve_vars "avd_pkg" $1 $2)
local vars
vars=$(parse_args "avd_pkg" "$@")
eval "$vars"
print_title "* Downloading $avd_pkg"
dl_emu "$avd_pkg"
}