Versioned documentation

![ss](https://user-images.githubusercontent.com/347918/49976566-87573880-ff10-11e8-805f-33d8393a3c45.png)

Demo:
- https://bazel-docs-staging.netlify.com/versions/master/bazel-overview.html
- https://bazel-docs-staging.netlify.com/versions/0.19.1/bazel-overview.html

This PR introduces a pure-HTML version selection mechanism for pages
on docs.bazel.build.

It also introduces a non-destructive script that generates a
documentation tree from a git checkout of a release tag. The script is
currently manually run after every release, but it only needs to be run
once per release.

There are also additional manual modifications required to add the new
values into a couple of config files, which I will take on as an
important follow up.

Another useful follow up is to integrate versioned documentation generation
into Bazel's release pipeline.

For more details, read the design document:
https://docs.google.com/document/d/1MNe8IWz7td4_Yr3r43YL-hrFSmQvFutum-av-Sny56s/edit

Fixes #579
Also see #1788
Also see #3336
Also see #3537

RELNOTES[NEW]: https://docs.bazel.build now supports versioned
documentation. Use the selector at the top of the navigation bar to
switch between documentation for different Bazel releases.

Closes #6923.

Change-Id: I4641a2556985ec085a156430d8c4fbc40e3aae0a
PiperOrigin-RevId: 225563710
diff --git a/scripts/docs/generate_versioned_docs.sh b/scripts/docs/generate_versioned_docs.sh
new file mode 100755
index 0000000..4d1bec1
--- /dev/null
+++ b/scripts/docs/generate_versioned_docs.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+#
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Generate a versioned documentation tree.
+#
+# Run this script from a git checkout of a release tag. This script will infer
+# the tag and create the documentation tree with the correct tag injected into
+# the static pages, archive the tree, and copy it to Google Cloud Storage.
+#
+# This only needs to be done once per release. This script is non-destructive.
+#
+# TODO(jingwen): Automate this into the release pipeline.
+
+set -eu
+
+function log_info() {
+  echo "[Info]" $@
+}
+
+readonly SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+# Unless we're in a tag (e.g. 0.20.0), set DOC_VERSION to master.
+readonly DOC_VERSION=$(git describe --tags --exact-match 2>/dev/null || echo "NOT_A_RELEASE")
+
+if [[ $DOC_VERSION == "NOT_A_RELEASE" ]]
+then
+  log_info "You are currently in the branch: `git rev-parse --abbrev-ref HEAD`"
+  log_info "Please run this script from a git checkout of a release tag, e.g. git checkout 0.20.0"
+  log_info "See the valid list of tags with 'git tag'"
+  exit 1
+fi
+
+function cleanup() {
+  mv $SCRIPT_DIR/../../site/_config.yml{.bak,}
+}
+
+read -p "You're going to generate the docs for $DOC_VERSION. Continue? <y/n> " prompt
+if [[ $prompt =~ [yY](es)* ]]
+then
+  # Modify the "version" Jekyll variable so all links in anchor tags are generated
+  # with the injected version.
+  sed -i.bak "s/master/$DOC_VERSION/" $SCRIPT_DIR/../../site/_config.yml
+  trap cleanup EXIT
+
+  bazel build //site:jekyll-tree --action_env=DOC_VERSION=$DOC_VERSION
+
+  # -n: no-clobber; prevent overwriting existing archives to be non-destructive.
+  # There should be no need to delete existing archives once it's uploaded. But
+  # should there be such a need, please file an issue.
+  #
+  # -a public-read: set the default ACL for uploaded archives to public-read for Bazel to download it.
+  gsutil cp -n -a public-read $SCRIPT_DIR/../../bazel-genfiles/site/jekyll-tree.tar gs://bazel-mirror/bazel_versioned_docs/jekyll-tree-$DOC_VERSION.tar
+
+  log_info "Done."
+  log_info "Now, please add \"$DOC_VERSION\" to the doc_versions list in <workspace>/site/_config.yml."
+  log_info "Please also add \"$DOC_VERSION\" to <workspace>/scripts/docs/doc_versions.bzl."
+fi