docs.sh 3.57 KB
Newer Older
1
#!/bin/bash
2
set -e
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 31 32 33 34 35 36 37 38 39
function deploy {
  local total_tries="$1"
  local remaining_tries=$(($total_tries - 1))
  shift
  while [[ "$remaining_tries" > 0 ]]; do
    (cd "$FLUTTER_ROOT/dev/docs" && firebase deploy --token "$FIREBASE_TOKEN" --project "$@") && break
    remaining_tries=$(($remaining_tries - 1))
    echo "Error: Unable to deploy documentation to Firebase. Retrying in five seconds... ($remaining_tries tries left)"
    sleep 5
  done

  [[ "$remaining_tries" == 0 ]] && {
    echo "Command still failed after $total_tries tries: '$@'"
    return 1
  }
  return 0
}

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 from anywhere and it will work as expected.
SCRIPT_LOCATION="$(script_location)"
# Sets the Flutter root to be "$(script_location)/../..": This script assumes
# that it resides two directory levels down from the root, so if that changes,
# then this line will need to as well.
FLUTTER_ROOT="$(dirname "$(dirname "$SCRIPT_LOCATION")")"

40
echo "Running docs.sh"
41

42 43 44 45
if [[ ! -d "$FLUTTER_ROOT" || ! -f "$FLUTTER_ROOT/bin/flutter" ]]; then
  echo "Unable to locate the Flutter installation (using FLUTTER_ROOT: $FLUTTER_ROOT)"
  exit 1
fi
Ian Hickson's avatar
Ian Hickson committed
46

47 48 49 50 51 52
FLUTTER_BIN="$FLUTTER_ROOT/bin"
DART_BIN="$FLUTTER_ROOT/bin/cache/dart-sdk/bin"
FLUTTER="$FLUTTER_BIN/flutter"
DART="$DART_BIN/dart"
PUB="$DART_BIN/pub"
export PATH="$FLUTTER_BIN:$DART_BIN:$PATH"
53

54 55
# Make sure dart is installed by invoking flutter to download it.
"$FLUTTER" --version
56

57 58
# If the pub cache directory exists in the root, then use that.
FLUTTER_PUB_CACHE="$FLUTTER_ROOT/.pub-cache"
59
if [[ -d "$FLUTTER_PUB_CACHE" ]]; then
60 61 62 63 64
  # This has to be exported, because pub interprets setting it
  # to the empty string in the same way as setting it to ".".
  export PUB_CACHE="${PUB_CACHE:-"$FLUTTER_PUB_CACHE"}"
fi

65
# Install and activate dartdoc.
66
"$PUB" global activate dartdoc 0.24.1
Seth Ladd's avatar
Seth Ladd committed
67 68

# This script generates a unified doc set, and creates
Ian Hickson's avatar
Ian Hickson committed
69
# a custom index.html, placing everything into dev/docs/doc.
70 71 72 73
(cd "$FLUTTER_ROOT/dev/tools" && "$FLUTTER" packages get)
(cd "$FLUTTER_ROOT/dev/tools" && "$PUB" get)
(cd "$FLUTTER_ROOT" && "$DART" "$FLUTTER_ROOT/dev/tools/dartdoc.dart")
(cd "$FLUTTER_ROOT" && "$DART" "$FLUTTER_ROOT/dev/tools/java_and_objc_doc.dart")
74

Seth Ladd's avatar
Seth Ladd committed
75
# Ensure google webmaster tools can verify our site.
76
cp "$FLUTTER_ROOT/dev/docs/google2ed1af765c529f57.html" "$FLUTTER_ROOT/dev/docs/doc"
77

78
# Upload new API docs when running on Cirrus
79 80 81 82
if [[ -n "$CIRRUS_CI" && -z "$CIRRUS_PR" ]]; then
  echo "This is not a pull request; considering whether to upload docs... (branch=$CIRRUS_BRANCH)"
  if [[ "$CIRRUS_BRANCH" == "master" || "$CIRRUS_BRANCH" == "beta" ]]; then
    if [[ "$CIRRUS_BRANCH" == "master" ]]; then
83
      echo "Updating master docs: https://master-docs-flutter-io.firebaseapp.com/"
84 85 86 87 88
      # Disable search indexing on the master staging site so searches get only
      # the beta site.
      echo -e "User-agent: *\nDisallow: /" > "$FLUTTER_ROOT/dev/docs/doc/robots.txt"
      export FIREBASE_TOKEN="$FIREBASE_MASTER_TOKEN"
      deploy 5 master-docs-flutter-io
89 90
    fi

91
    if [[ "$CIRRUS_BRANCH" == "beta" ]]; then
92
      echo "Updating beta docs: https://docs.flutter.io/"
93 94
      export FIREBASE_TOKEN="$FIREBASE_PUBLIC_TOKEN"
      deploy 5 docs-flutter-io
95
    fi
96
  fi
97
fi
98