Jingwen Chen | 186bdcd | 2018-12-14 10:27:23 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2018 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Generate a versioned documentation tree. |
| 18 | # |
| 19 | # Run this script from a git checkout of a release tag. This script will infer |
| 20 | # the tag and create the documentation tree with the correct tag injected into |
| 21 | # the static pages, archive the tree, and copy it to Google Cloud Storage. |
| 22 | # |
| 23 | # This only needs to be done once per release. This script is non-destructive. |
| 24 | # |
| 25 | # TODO(jingwen): Automate this into the release pipeline. |
| 26 | |
| 27 | set -eu |
| 28 | |
| 29 | function log_info() { |
| 30 | echo "[Info]" $@ |
| 31 | } |
| 32 | |
| 33 | readonly SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 34 | # Unless we're in a tag (e.g. 0.20.0), set DOC_VERSION to master. |
| 35 | readonly DOC_VERSION=$(git describe --tags --exact-match 2>/dev/null || echo "NOT_A_RELEASE") |
| 36 | |
| 37 | if [[ $DOC_VERSION == "NOT_A_RELEASE" ]] |
| 38 | then |
| 39 | log_info "You are currently in the branch: `git rev-parse --abbrev-ref HEAD`" |
| 40 | log_info "Please run this script from a git checkout of a release tag, e.g. git checkout 0.20.0" |
| 41 | log_info "See the valid list of tags with 'git tag'" |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | function cleanup() { |
| 46 | mv $SCRIPT_DIR/../../site/_config.yml{.bak,} |
| 47 | } |
| 48 | |
| 49 | read -p "You're going to generate the docs for $DOC_VERSION. Continue? <y/n> " prompt |
| 50 | if [[ $prompt =~ [yY](es)* ]] |
| 51 | then |
| 52 | # Modify the "version" Jekyll variable so all links in anchor tags are generated |
| 53 | # with the injected version. |
| 54 | sed -i.bak "s/master/$DOC_VERSION/" $SCRIPT_DIR/../../site/_config.yml |
| 55 | trap cleanup EXIT |
| 56 | |
| 57 | bazel build //site:jekyll-tree --action_env=DOC_VERSION=$DOC_VERSION |
| 58 | |
| 59 | # -n: no-clobber; prevent overwriting existing archives to be non-destructive. |
| 60 | # There should be no need to delete existing archives once it's uploaded. But |
| 61 | # should there be such a need, please file an issue. |
| 62 | # |
| 63 | # -a public-read: set the default ACL for uploaded archives to public-read for Bazel to download it. |
philwo | 3bbf9b9d | 2019-04-17 07:05:01 -0700 | [diff] [blame] | 64 | gsutil cp -n $(cd $SCRIPT_DIR && bazel info bazel-genfiles)/site/jekyll-tree.tar gs://bazel-mirror/bazel_versioned_docs/jekyll-tree-$DOC_VERSION.tar |
Jingwen Chen | 186bdcd | 2018-12-14 10:27:23 -0800 | [diff] [blame] | 65 | |
| 66 | log_info "Done." |
| 67 | log_info "Now, please add \"$DOC_VERSION\" to the doc_versions list in <workspace>/site/_config.yml." |
| 68 | log_info "Please also add \"$DOC_VERSION\" to <workspace>/scripts/docs/doc_versions.bzl." |
| 69 | fi |