File: generate_versioned_docs.sh

package info (click to toggle)
bazel-bootstrap 4.2.3%2Bds-11
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,704 kB
  • sloc: java: 721,717; sh: 55,859; cpp: 35,360; python: 12,139; xml: 295; objc: 269; makefile: 113; ansic: 106; ruby: 3
file content (69 lines) | stat: -rwxr-xr-x 2,775 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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 $(cd $SCRIPT_DIR && bazel info 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