|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2020 Google LLC |
| 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 | +set -o errexit |
| 17 | +set -o nounset |
| 18 | +set -o xtrace |
| 19 | +set -o pipefail |
| 20 | + |
| 21 | +# Update the gh-pages branch. Note that `cargo doc` is **not deterministic** so |
| 22 | +# this should only be done when there is a real change. |
| 23 | +readonly RUST_BRANCH=${1:-main} |
| 24 | +readonly RUST_GH_BRANCH=gh-pages |
| 25 | + |
| 26 | +if [ -z "${FORCE+x}" ]; then |
| 27 | + readonly PREV_COMMIT=$(git log --oneline -n 1 ${RUST_GH_BRANCH} | sed 's/.*branch at \([0-9a-f]*\)/\1/') |
| 28 | + readonly CHANGES=$(git diff "${PREV_COMMIT}..${RUST_BRANCH}" | grep -e '[+-]//[/!]') |
| 29 | + |
| 30 | + if [ -z "${CHANGES}" ]; then |
| 31 | + echo "No doc comment changes found in ${PREV_COMMIT}..${RUST_BRANCH} subdir rust/" |
| 32 | + exit 0 |
| 33 | + fi |
| 34 | +fi |
| 35 | + |
| 36 | +git switch "${RUST_BRANCH}" |
| 37 | +readonly RUST_BRANCH_SHA1=$(git rev-parse --short HEAD) |
| 38 | +readonly RUST_BRANCH_SUBJECT=$(git log -n 1 --format=format:%s) |
| 39 | +readonly COMMIT_MESSAGE=$(cat <<-END |
| 40 | +Update Rust docs to ${RUST_BRANCH} branch at ${RUST_BRANCH_SHA1} |
| 41 | +
|
| 42 | +Auto-generated from commit ${RUST_BRANCH_SHA1} ("${RUST_BRANCH_SUBJECT}"). |
| 43 | +END |
| 44 | +) |
| 45 | + |
| 46 | +readonly TGZ_FILE="/tmp/coset-doc-${RUST_BRANCH_SHA1}.tgz" |
| 47 | +# Build Cargo docs and save them off outside the repo |
| 48 | +( |
| 49 | + rm -rf target/doc |
| 50 | + cargo doc --no-deps |
| 51 | + cargo deadlinks |
| 52 | + cd target/doc || exit |
| 53 | + tar czf "${TGZ_FILE}" ./* |
| 54 | +) |
| 55 | + |
| 56 | +# Shift to ${RUST_GH_BRANCH} branch and replace contents of (just) ./rust/ |
| 57 | +git switch ${RUST_GH_BRANCH} |
| 58 | + |
| 59 | +readonly DOC_DIR=rust |
| 60 | +rm -rf ${DOC_DIR} |
| 61 | +mkdir ${DOC_DIR} |
| 62 | +( |
| 63 | + cd "${DOC_DIR}" || exit |
| 64 | + tar xzf "${TGZ_FILE}" |
| 65 | +) |
| 66 | + |
| 67 | +# Commit any differences |
| 68 | +git add "${DOC_DIR}" |
| 69 | +git commit --message="${COMMIT_MESSAGE}" |
| 70 | +git switch "${RUST_BRANCH}" |
0 commit comments