firebase_testlab.sh 2.56 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4
#!/usr/bin/env bash
# Copyright 2014 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
5

6 7 8
# The tests to run on Firebase Test Lab.
# Currently, the test consists on building an Android App Bundle and ensuring
# that the app doesn't crash upon startup.
9 10
#
# When adding a test, ensure that there's at least a `print()` statement under lib/*.dart.
11 12 13
tests=(
  "dev/integration_tests/release_smoke_test"
  "dev/integration_tests/abstract_method_smoke_test"
14
  "dev/integration_tests/android_embedding_v2_smoke_test"
15 16
)

17 18 19 20 21 22 23
# The devices where the tests are run.
#
# To get the full list of devices available, run:
#     gcloud firebase test android models list
devices=(
  # Pixel 3
  "model=blueline,version=28"
24
  "model=blueline,version=29"
25 26 27 28 29

  # Moto Z XT1650
  "model=griffin,version=24"
)

30 31 32 33
set -e

GIT_REVISION=$(git rev-parse HEAD)

34 35 36 37 38
DEVICE_FLAG=""
for device in ${devices[*]}; do
  DEVICE_FLAG+="--device $device "
done

39 40 41 42 43 44 45 46 47 48
# New contributors will not have permissions to run this test - they won't be
# able to access the service account information. We should just mark the test
# as passed - it will run fine on post submit, where it will still catch
# failures.
# We can also still make sure that building a release app bundle still works.
if [[ $GCLOUD_FIREBASE_TESTLAB_KEY == ENCRYPTED* ]]; then
  echo "This user does not have permission to run this test."
  exit 0
fi

49 50 51 52
echo $GCLOUD_FIREBASE_TESTLAB_KEY > ${HOME}/gcloud-service-key.json
gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json
gcloud --quiet config set project flutter-infra

53 54 55 56
function test_app_bundle() {
  pushd "$@"
  ../../../bin/flutter build appbundle --target-platform android-arm,android-arm64

57 58 59 60 61 62
  aab="build/app/outputs/bundle/release/app-release.aab"

  # If the app bundle doesn't exist, then exit with code 1.
  if [ ! -f "$aab" ]; then
    exit 1
  fi
63 64

  # Run the test.
65 66 67
  gcloud firebase test android run \
    --type robo \
    --app "$aab" \
68 69
    --timeout 2m \
    --results-bucket=gs://flutter_firebase_testlab \
70 71
    --results-dir="$@"/"$GIT_REVISION"/"$CIRRUS_BUILD_ID" \
    $DEVICE_FLAG
72

73 74 75 76 77 78 79
  rm -f /tmp/logcat
  gsutil cat gs://flutter_firebase_testlab/"$@"/"$GIT_REVISION"/"$CIRRUS_BUILD_ID"/*/logcat > /tmp/logcat
  # Check logcat for "E/flutter" - if it's there, something's wrong.
  ! grep "E/flutter" /tmp/logcat || false
  # Check logcat for "I/flutter" - This is in the log if there's a print statement under lib/*.dart.
  grep "I/flutter" /tmp/logcat
  popd
80 81 82 83 84
}

for test in ${tests[*]}; do
  test_app_bundle $test
done