Fix shellcheck warnings (#778)

pull/779/head
Quentin Hibon 5 years ago committed by GitHub
parent 129c86a030
commit 7fb3489ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
cd "$(dirname "$0")" cd "$(dirname "$0")" || exit
ADB="${ANDROID_HOME}/platform-tools/adb" ADB="${ANDROID_HOME}/platform-tools/adb"
EMULATOR="${ANDROID_HOME}/tools/emulator" EMULATOR="${ANDROID_HOME}/tools/emulator"
@ -24,7 +24,7 @@ AVDNAME="uhabitsTest"
GRADLE="./gradlew --stacktrace --quiet" GRADLE="./gradlew --stacktrace --quiet"
PACKAGE_NAME=org.isoron.uhabits PACKAGE_NAME=org.isoron.uhabits
ANDROID_OUTPUTS_DIR="uhabits-android/build/outputs" ANDROID_OUTPUTS_DIR="uhabits-android/build/outputs"
VERSION=$(cat gradle.properties | grep VERSION_NAME | sed -e 's/.*=//g;s/ //g') VERSION=$(grep VERSION_NAME gradle.properties | sed -e 's/.*=//g;s/ //g')
if [ ! -f "${ANDROID_HOME}/platform-tools/adb" ]; then if [ ! -f "${ANDROID_HOME}/platform-tools/adb" ]; then
echo "Error: ANDROID_HOME is not set correctly" echo "Error: ANDROID_HOME is not set correctly"
@ -76,37 +76,38 @@ run_adb_as_root() {
} }
build_apk() { build_apk() {
if [ ! -z $RELEASE ]; then if [ -n "$RELEASE" ]; then
log_info "Reading secret..." log_info "Reading secret..."
# shellcheck disable=SC1091
source .secret/env || fail source .secret/env || fail
fi fi
log_info "Removing old APKs..." log_info "Removing old APKs..."
rm -vf uhabits-android/build/*.apk rm -vf uhabits-android/build/*.apk
if [ ! -z $RELEASE ]; then if [ -n "$RELEASE" ]; then
log_info "Building release APK..." log_info "Building release APK..."
$GRADLE :uhabits-android:assembleRelease $GRADLE :uhabits-android:assembleRelease
cp -v \ cp -v \
uhabits-android/build/outputs/apk/release/uhabits-android-release.apk \ uhabits-android/build/outputs/apk/release/uhabits-android-release.apk \
uhabits-android/build/loop-$VERSION-release.apk uhabits-android/build/loop-"$VERSION"-release.apk
fi fi
log_info "Building debug APK..." log_info "Building debug APK..."
$GRADLE :uhabits-android:assembleDebug --stacktrace || fail $GRADLE :uhabits-android:assembleDebug --stacktrace || fail
cp -v \ cp -v \
uhabits-android/build/outputs/apk/debug/uhabits-android-debug.apk \ uhabits-android/build/outputs/apk/debug/uhabits-android-debug.apk \
uhabits-android/build/loop-$VERSION-debug.apk uhabits-android/build/loop-"$VERSION"-debug.apk
} }
build_instrumentation_apk() { build_instrumentation_apk() {
log_info "Building instrumentation APK..." log_info "Building instrumentation APK..."
if [ ! -z $RELEASE ]; then if [ -n "$RELEASE" ]; then
$GRADLE :uhabits-android:assembleAndroidTest \ $GRADLE :uhabits-android:assembleAndroidTest \
-Pandroid.injected.signing.store.file=$LOOP_KEY_STORE \ -Pandroid.injected.signing.store.file="$LOOP_KEY_STORE" \
-Pandroid.injected.signing.store.password=$LOOP_STORE_PASSWORD \ -Pandroid.injected.signing.store.password="$LOOP_STORE_PASSWORD" \
-Pandroid.injected.signing.key.alias=$LOOP_KEY_ALIAS \ -Pandroid.injected.signing.key.alias="$LOOP_KEY_ALIAS" \
-Pandroid.injected.signing.key.password=$LOOP_KEY_PASSWORD || fail -Pandroid.injected.signing.key.password="$LOOP_KEY_PASSWORD" || fail
else else
$GRADLE assembleAndroidTest || fail $GRADLE assembleAndroidTest || fail
fi fi
@ -125,7 +126,7 @@ install_test_butler() {
install_apk() { install_apk() {
log_info "Installing APK..." log_info "Installing APK..."
if [ ! -z $RELEASE ]; then if [ -n "$RELEASE" ]; then
$ADB install -r ${ANDROID_OUTPUTS_DIR}/apk/release/uhabits-android-release.apk || fail $ADB install -r ${ANDROID_OUTPUTS_DIR}/apk/release/uhabits-android-release.apk || fail
else else
$ADB install -t -r ${ANDROID_OUTPUTS_DIR}/apk/debug/uhabits-android-debug.apk || fail $ADB install -t -r ${ANDROID_OUTPUTS_DIR}/apk/debug/uhabits-android-debug.apk || fail
@ -144,7 +145,7 @@ run_instrumented_tests() {
SIZE=$1 SIZE=$1
log_info "Running instrumented tests..." log_info "Running instrumented tests..."
$ADB shell am instrument \ $ADB shell am instrument \
-r -e coverage true -e size $SIZE \ -r -e coverage true -e size "$SIZE" \
-w ${PACKAGE_NAME}.test/androidx.test.runner.AndroidJUnitRunner \ -w ${PACKAGE_NAME}.test/androidx.test.runner.AndroidJUnitRunner \
| tee ${ANDROID_OUTPUTS_DIR}/instrument.txt | tee ${ANDROID_OUTPUTS_DIR}/instrument.txt
@ -181,7 +182,8 @@ create_avd() {
wait_for_device() { wait_for_device() {
log_info "Waiting for device..." log_info "Waiting for device..."
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82' # shellcheck disable=SC2016
adb wait-for-device shell 'while [[ -z "$(getprop sys.boot_completed)" ]]; do sleep 1; done; input keyevent 82'
sleep 15 sleep 15
} }
@ -194,10 +196,10 @@ run_avd() {
stop_avd() { stop_avd() {
log_info "Stopping emulator..." log_info "Stopping emulator..."
# https://stackoverflow.com/a/38652520 # https://stackoverflow.com/a/38652520
adb devices | grep emulator | cut -f1 | while read line; do adb devices | grep emulator | cut -f1 | while read -r line; do
adb -s $line emu kill adb -s "$line" emu kill
done done
while [[ ! -z $(pgrep emulator) ]]; do sleep 1; done while [[ -n $(pgrep emulator) ]]; do sleep 1; done
} }
run_tests() { run_tests() {
@ -207,7 +209,7 @@ run_tests() {
uninstall_apk uninstall_apk
install_apk install_apk
install_test_apk install_test_apk
run_instrumented_tests $SIZE run_instrumented_tests "$SIZE"
fetch_logcat fetch_logcat
uninstall_test_apk uninstall_test_apk
} }
@ -219,8 +221,9 @@ build_android() {
} }
parse_opts() { parse_opts() {
OPTS=`getopt -o r --long release -n 'build.sh' -- "$@"` if ! OPTS="$(getopt -o r --long release -n 'build.sh' -- "$@")" ; then
if [ $? != 0 ] ; then exit 1; fi exit 1;
fi
eval set -- "$OPTS" eval set -- "$OPTS"
while true; do while true; do
@ -252,26 +255,26 @@ remove_build_dirs() {
main() { main() {
case "$1" in case "$1" in
build) build)
shift; parse_opts $* shift; parse_opts "$@"
ktlint ktlint
build_core build_core
build_android build_android
;; ;;
medium-tests) medium-tests)
shift; parse_opts $* shift; parse_opts "$@"
for attempt in {1..3}; do for _ in {1..3}; do
(run_tests medium) && exit 0 (run_tests medium) && exit 0
done done
exit 1 exit 1
;; ;;
large-tests) large-tests)
shift; parse_opts $* shift; parse_opts "$@"
stop_avd stop_avd
remove_avd remove_avd
for api in 28; do for api in {28..28}; do
create_avd $api create_avd "$api"
run_avd run_avd
run_tests large run_tests large
stop_avd stop_avd
@ -302,5 +305,5 @@ END
esac esac
} }
main $* main "$@"

Loading…
Cancel
Save