• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (C) 2021 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# This script builds the perfetto.dev docs website (via ./build) and pushes the
17# contents to the gs://perfetto.dev GCS bucket. It doesn't re-deploy the
18# AppEngine instance, as that doesn't depend on the contents (use
19# ./appengine/deploy for that).
20# This is ran by the Cloud Build infrastructure (./cloudbuild.yaml) whenever a
21# docs/ change is detected. See go/perfetto-ui-autopush for more details.
22
23set -eux
24
25# The directory that contains this script (//infra/perfetto.dev)
26readonly CUR_DIR="$(cd -P ${BASH_SOURCE[0]%/*}; pwd)"
27
28# The repo root.
29readonly ROOT_DIR=$(dirname $(dirname "$CUR_DIR"))
30
31# The directory that will contain the static website artifacts.
32readonly OUT_DIR="$ROOT_DIR/out/perfetto.dev"
33
34# Build first.
35"$CUR_DIR/build"
36
37# The markdown docs are rendered into extension-less HTML files to make the URLs
38# look nice (e.g., /docs/tracing rather than /docs/tracing.html). By default
39# gsutil infers the mime-type from the extension, falling back to octet/stream
40# for extension-less fiels. octect/stream causes the browser to download the
41# file rather than parsing it as a web page.
42# We set use_magicfile = True here, which causes gsutil to infer the MIME type
43# by invoking `file -b --mime /path/to/file`.
44# Unfortunately, that solves the HTML MIME problem but adds another one: the
45# standard `file` util doesn't deal with .css files and marks them as text/plain
46# causing the browser to ignore the CSS.
47# Here what we do is replacing the standard `file` util with a custom made one
48# (mime_util/file) which sets the right MIME types we want. We do this by
49# prepending our script to the PATH.
50export PATH="$CUR_DIR/mime_util:$PATH"
51export BOTO_CONFIG=/tmp/boto
52cat << EOF > $BOTO_CONFIG
53[GSUtil]
54use_magicfile = True
55
56EOF
57
58# Basic checks before uploading. Test both the existence and the mime type.
59[ "$(file $OUT_DIR/index.html)" == "text/html" ]
60[ "$(file $OUT_DIR/assets/style.css)" == "text/css" ]
61[ "$(file $OUT_DIR/assets/home.png)" == "image/png" ]
62[ "$(file $OUT_DIR/docs/images/perfetto-stack.svg)" == "image/svg+xml" ]
63[ "$(file $OUT_DIR/docs/images/perfetto-stack.svg)" == "image/svg+xml" ]
64[ "$(file $OUT_DIR/docs/analysis/sql-tables)" == "text/html" ]
65
66# -j: apply 'Content-Encoding: gzip' compression to passed extensions.
67# -d: mirror also deletetions.
68# -c: compare checksums, not mtimes.
69# -r: recursive.
70# The trailing slash appended to $OUT_DIR is to prevent that gsutil creates a
71# nested sub-directory inside gs://perfetto.dev/.
72gsutil -m rsync -j html,js,css,svg -d -c -r \
73  "$OUT_DIR/" gs://perfetto.dev/
74