deploy_gallery.sh 2.66 KB
Newer Older
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
#!/bin/bash

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"

if [[ "$SHARD" = "deploy_gallery" ]]; then
  version="$(<version)"
  if [[ "$OS" == "linux" ]]; then
    echo "Building Flutter Gallery $version for Android..."
31

32
    # ANDROID_SDK_ROOT must be set in the env.
33 34 35 36 37 38
    (
      cd examples/flutter_gallery
      flutter build apk --release -t lib/main_publish.dart
    )
    echo "Android Flutter Gallery built"
    if [[ -z "$CIRRUS_PULL_REQUEST" && "$CIRRUS_BRANCH" == "dev" && "$version" != *"pre"* ]]; then
39
      echo "Deploying Flutter Gallery $version to Play Store..."
40 41 42 43 44
      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
      fi
      set -x
45 46
      (
        cd examples/flutter_gallery/android
47
        fastlane deploy_play_store
48 49 50 51
      )
    else
      echo "Not deployed: Flutter Gallery is only deployed to the Play Store on merged and tagged dev branch commits"
    fi
52
  elif [[ "$OS" == "darwin" ]]; then
53 54 55 56 57 58 59 60 61 62 63
    echo "Building Flutter Gallery $version for iOS..."
    (
      cd examples/flutter_gallery
      flutter build ios --release --no-codesign -t lib/main_publish.dart
    )
    echo "iOS Flutter Gallery built"
    if [[ -z "$CIRRUS_PULL_REQUEST" ]]; then
      if [[ "$CIRRUS_BRANCH" == "dev" && "$version" != *"pre"* ]]; then
        echo "Archiving with distribution profile and deploying to TestFlight..."
        (
          cd examples/flutter_gallery/ios
64
          fastlane build_and_deploy_testflight upload:true
65 66 67 68 69
        )
      else
        echo "Archiving with distribution profile..."
        (
          cd examples/flutter_gallery/ios
70
          fastlane build_and_deploy_testflight
71 72 73 74 75 76 77 78 79 80
        )
        echo "Archive is only deployed to TestFlight on tagged dev branch commits"
      fi
    else
      echo "Not deployed: Flutter Gallery is only deployed to TestFlight on merged and tagged dev branch commits"
    fi
  fi
else
  echo "Doing nothing: not on the 'deploy_gallery' SHARD."
fi