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