• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2set -e
3
4function deploy {
5  local total_tries="$1"
6  local remaining_tries=$(($total_tries - 1))
7  shift
8  while [[ "$remaining_tries" > 0 ]]; do
9    (cd "$FLUTTER_ROOT/dev/docs" && firebase deploy --token "$FIREBASE_TOKEN" --project "$@") && break
10    remaining_tries=$(($remaining_tries - 1))
11    echo "Error: Unable to deploy documentation to Firebase. Retrying in five seconds... ($remaining_tries tries left)"
12    sleep 5
13  done
14
15  [[ "$remaining_tries" == 0 ]] && {
16    echo "Command still failed after $total_tries tries: '$@'"
17    return 1
18  }
19  return 0
20}
21
22function script_location() {
23  local script_location="${BASH_SOURCE[0]}"
24  # Resolve symlinks
25  while [[ -h "$script_location" ]]; do
26    DIR="$(cd -P "$( dirname "$script_location")" >/dev/null && pwd)"
27    script_location="$(readlink "$script_location")"
28    [[ "$script_location" != /* ]] && script_location="$DIR/$script_location"
29  done
30  echo "$(cd -P "$(dirname "$script_location")" >/dev/null && pwd)"
31}
32
33# Zip up the docs so people can download them for offline usage.
34function create_offline_zip() {
35  # Must be run from "$FLUTTER_ROOT/dev/docs"
36  echo "Zipping Flutter offline docs archive."
37  rm -rf flutter.docs.zip doc/offline
38  (cd ./doc; zip -r -9 -q ../flutter.docs.zip .)
39}
40
41# Generate the docset for Flutter docs for use with Dash, Zeal, and Velocity.
42function create_docset() {
43  # Must be run from "$FLUTTER_ROOT/dev/docs"
44  # Must have dashing installed: go get -u github.com/technosophos/dashing
45  # Dashing produces a LOT of log output (~30MB), so we redirect it, and just
46  # show the end of it if there was a problem.
47  echo "Building Flutter docset."
48  rm -rf flutter.docset
49  (dashing build --source ./doc --config ./dashing.json > /tmp/dashing.log 2>&1 || (tail -100 /tmp/dashing.log; false)) && \
50  cp ./doc/flutter/static-assets/favicon.png ./flutter.docset/icon.png && \
51  "$DART" ./dashing_postprocess.dart && \
52  tar cf flutter.docset.tar.gz --use-compress-program="gzip --best" flutter.docset
53}
54
55# Move the offline archives into place, after all the processing of the doc
56# directory is done. This avoids the tools recursively processing the archives
57# as part of their process.
58function move_offline_into_place() {
59  # Must be run from "$FLUTTER_ROOT/dev/docs"
60  echo "Moving offline data into place."
61  mkdir -p doc/offline
62  mv flutter.docs.zip doc/offline/flutter.docs.zip
63  du -sh doc/offline/flutter.docs.zip
64  if [[ "$CIRRUS_BRANCH" == "stable" ]]; then
65    echo -e "<entry>\n  <version>${FLUTTER_VERSION}</version>\n  <url>https://api.flutter.dev/offline/flutter.docset.tar.gz</url>\n</entry>" > doc/offline/flutter.xml
66  else
67    echo -e "<entry>\n  <version>${FLUTTER_VERSION}</version>\n  <url>https://master-api.flutter.dev/offline/flutter.docset.tar.gz</url>\n</entry>" > doc/offline/flutter.xml
68  fi
69  mv flutter.docset.tar.gz doc/offline/flutter.docset.tar.gz
70  du -sh doc/offline/flutter.docset.tar.gz
71}
72
73# So that users can run this script from anywhere and it will work as expected.
74SCRIPT_LOCATION="$(script_location)"
75# Sets the Flutter root to be "$(script_location)/../..": This script assumes
76# that it resides two directory levels down from the root, so if that changes,
77# then this line will need to as well.
78FLUTTER_ROOT="$(dirname "$(dirname "$SCRIPT_LOCATION")")"
79
80echo "Running docs.sh"
81
82if [[ ! -d "$FLUTTER_ROOT" || ! -f "$FLUTTER_ROOT/bin/flutter" ]]; then
83  echo "Unable to locate the Flutter installation (using FLUTTER_ROOT: $FLUTTER_ROOT)"
84  exit 1
85fi
86
87FLUTTER_BIN="$FLUTTER_ROOT/bin"
88DART_BIN="$FLUTTER_ROOT/bin/cache/dart-sdk/bin"
89FLUTTER="$FLUTTER_BIN/flutter"
90DART="$DART_BIN/dart"
91PUB="$DART_BIN/pub"
92export PATH="$FLUTTER_BIN:$DART_BIN:$PATH"
93
94# Make sure dart is installed by invoking flutter to download it.
95"$FLUTTER" --version
96FLUTTER_VERSION=$(cat "$FLUTTER_ROOT/version")
97
98# If the pub cache directory exists in the root, then use that.
99FLUTTER_PUB_CACHE="$FLUTTER_ROOT/.pub-cache"
100if [[ -d "$FLUTTER_PUB_CACHE" ]]; then
101  # This has to be exported, because pub interprets setting it to the empty
102  # string in the same way as setting it to ".".
103  export PUB_CACHE="${PUB_CACHE:-"$FLUTTER_PUB_CACHE"}"
104fi
105
106# Install and activate dartdoc.
107"$PUB" global activate dartdoc 0.28.4
108
109# This script generates a unified doc set, and creates
110# a custom index.html, placing everything into dev/docs/doc.
111(cd "$FLUTTER_ROOT/dev/tools" && "$FLUTTER" pub get)
112(cd "$FLUTTER_ROOT/dev/tools" && "$PUB" get)
113(cd "$FLUTTER_ROOT" && "$DART" "$FLUTTER_ROOT/dev/tools/dartdoc.dart")
114(cd "$FLUTTER_ROOT" && "$DART" "$FLUTTER_ROOT/dev/tools/java_and_objc_doc.dart")
115
116# Create offline doc archives.
117(cd "$FLUTTER_ROOT/dev/docs"; create_offline_zip)
118(cd "$FLUTTER_ROOT/dev/docs"; create_docset)
119(cd "$FLUTTER_ROOT/dev/docs"; move_offline_into_place)
120
121# Ensure google webmaster tools can verify our site.
122cp "$FLUTTER_ROOT/dev/docs/google2ed1af765c529f57.html" "$FLUTTER_ROOT/dev/docs/doc"
123
124# Upload new API docs when running on Cirrus
125if [[ -n "$CIRRUS_CI" && -z "$CIRRUS_PR" ]]; then
126  echo "This is not a pull request; considering whether to upload docs... (branch=$CIRRUS_BRANCH)"
127  if [[ "$CIRRUS_BRANCH" == "master" ]]; then
128    echo "Updating $CIRRUS_BRANCH docs: https://master-api.flutter.dev/"
129    # Disable search indexing on the master staging site so searches get only
130    # the stable site.
131    echo -e "User-agent: *\nDisallow: /" > "$FLUTTER_ROOT/dev/docs/doc/robots.txt"
132    export FIREBASE_TOKEN="$FIREBASE_MASTER_TOKEN"
133    deploy 5 master-docs-flutter-dev
134  fi
135
136  if [[ "$CIRRUS_BRANCH" == "stable" ]]; then
137    # Enable search indexing on the master staging site so searches get only
138    # the stable site.
139    echo "Updating $CIRRUS_BRANCH docs: https://api.flutter.dev/"
140    echo -e "# All robots welcome!" > "$FLUTTER_ROOT/dev/docs/doc/robots.txt"
141    export FIREBASE_TOKEN="$FIREBASE_PUBLIC_TOKEN"
142    deploy 5 docs-flutter-dev
143  fi
144fi
145
146