deploy_gallery.sh 4.44 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 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

set -e

function script_location() {
  local script_location="${BASH_SOURCE[0]}"
  # Resolve symlinks
  while [[ -h "$script_location" ]]; do
    DIR="$(cd -P "$(dirname "$script_location")" >/dev/null && pwd)"
    script_location="$(readlink "$script_location")"
    [[ "$script_location" != /* ]] && script_location="$DIR/$script_location"
  done
  echo "$(cd -P "$(dirname "$script_location")" >/dev/null && pwd)"
}

# So that users can run this script locally from any directory and it will work as
# expected.
SCRIPT_LOCATION="$(script_location)"
FLUTTER_ROOT="$(dirname "$(dirname "$SCRIPT_LOCATION")")"
export PATH="$FLUTTER_ROOT/bin:$FLUTTER_ROOT/bin/cache/dart-sdk/bin:$PATH"

set -x

cd "$FLUTTER_ROOT"

29 30 31
version="$(<version)"
if [[ "$OS" == "linux" ]]; then
  echo "Building Flutter Gallery $version for Android..."
32
  export BUNDLE_GEMFILE="$FLUTTER_ROOT/dev/ci/docker_linux/Gemfile"
33 34
  # ANDROID_SDK_ROOT must be set in the env.
  (
35
    cd dev/integration_tests/flutter_gallery
36 37 38 39 40 41 42 43
    flutter build apk --release -t lib/main_publish.dart
  )
  echo "Android Flutter Gallery built"
  if [[ -z "$CIRRUS_PR" && "$CIRRUS_BRANCH" == "dev" && "$version" != *"pre"* ]]; then
    echo "Deploying Flutter Gallery $version to Play Store..."
    set +x # Don't echo back the below.
    if [ -n "$ANDROID_GALLERY_UPLOAD_KEY" ]; then
      echo "$ANDROID_GALLERY_UPLOAD_KEY" | base64 --decode > /root/.android/debug.keystore
44
    fi
45
    set -x
46
    (
47
      cd dev/integration_tests/flutter_gallery/android
48
      bundle exec fastlane deploy_play_store
49 50 51 52 53 54
    )
  else
    echo "(Not deploying; Flutter Gallery is only deployed to Play store for tagged dev branch commits.)"
  fi
elif [[ "$OS" == "darwin" ]]; then
  echo "Building Flutter Gallery $version for iOS..."
55
  export BUNDLE_GEMFILE="$FLUTTER_ROOT/dev/ci/mac/Gemfile"
56
  (
57
    cd dev/integration_tests/flutter_gallery
58
    flutter build ios --release --no-codesign -t lib/main_publish.dart
59

60 61 62 63 64
    # flutter build ios will run CocoaPods script. Check generated locations.
    if [[ ! -d "ios/Pods" ]]; then
      echo "Error: pod install failed to setup plugins"
      exit 1
    fi
65

66 67 68 69
    if [[ ! -d "ios/.symlinks/plugins" ]]; then
      echo "Error: pod install failed to setup plugin symlinks"
      exit 1
    fi
70

71 72 73 74
    if [[ -d "ios/.symlinks/flutter" ]]; then
      echo "Error: pod install created flutter symlink"
      exit 1
    fi
75

76
    if [[ ! -d "build/ios/iphoneos/Flutter Gallery.app/Frameworks/App.framework/flutter_assets" ]]; then
77 78 79
      echo "Error: flutter_assets not assembled"
      exit 1
    fi
80

81
    if [[
82 83 84
      -d "build/ios/iphoneos/Flutter Gallery.app/Frameworks/App.framework/flutter_assets/isolate_snapshot_data" ||
      -d "build/ios/iphoneos/Flutter Gallery.app/Frameworks/App.framework/flutter_assets/kernel_blob.bin" ||
      -d "build/ios/iphoneos/Flutter Gallery.app/Frameworks/App.framework/flutter_assets/vm_snapshot_data"
85 86 87 88 89 90 91 92 93 94
     ]]; then
      echo "Error: compiled debug version of app with --release flag"
      exit 1
    fi
  )
  echo "iOS Flutter Gallery built"
  if [[ -z "$CIRRUS_PR" ]]; then
    if [[ "$CIRRUS_BRANCH" == "dev" && "$version" != *"pre"* ]]; then
      echo "Archiving with distribution profile and deploying to TestFlight..."
      (
95
        cd dev/integration_tests/flutter_gallery/ios
96
        export DELIVER_ITMSTRANSPORTER_ADDITIONAL_UPLOAD_PARAMETERS="-t DAV"
97
        bundle exec fastlane build_and_deploy_testflight upload:true
98
      )
99
    else
100 101 102 103 104
      # On iOS the signing can break as well, so we verify this regularly (not just
      # on tagged dev branch commits). We can only do this post-merge, though, because
      # the secrets aren't available on PRs.
      echo "Testing archiving with distribution profile..."
      (
105
        cd dev/integration_tests/flutter_gallery/ios
106 107 108
        # Cirrus Mac VMs come with an old version of fastlane which was causing
        # dependency issues (https://github.com/flutter/flutter/issues/43435),
        # so explicitly use the version specified in $BUNDLE_GEMFILE.
109
        bundle exec fastlane build_and_deploy_testflight
110 111
      )
      echo "(Not deploying; Flutter Gallery is only deployed to TestFlight for tagged dev branch commits.)"
112
    fi
113 114
  else
    echo "(Not archiving or deploying; Flutter Gallery archiving is only tested post-commit.)"
115 116
  fi
else
117 118 119
  echo "Unknown OS: $OS"
  echo "Aborted."
  exit 1
120
fi