|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2020 Antrea Authors |
| 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 | +# This script is inspired by the one maintained in |
| 18 | +# https://github.com/kubernetes/enhancements |
| 19 | + |
| 20 | +set -o errexit |
| 21 | +set -o nounset |
| 22 | +set -o pipefail |
| 23 | + |
| 24 | +TOOL_VERSION=$(head hack/mdtoc-version) |
| 25 | + |
| 26 | +GO_VERSION="$(${GO} version | awk '{print $3}')" |
| 27 | +function version_lt() { test "$(printf '%s\n' "$@" | sort -rV | head -n 1)" != "$1"; } |
| 28 | + |
| 29 | +if version_lt "${GO_VERSION}" "go1.16"; then |
| 30 | + # See https://golang.org/doc/go-get-install-deprecation |
| 31 | + echo "Running this script requires Go >= 1.16, please upgrade" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +# cd to the root path |
| 36 | +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" |
| 37 | +cd "${ROOT}" |
| 38 | + |
| 39 | +# create a temporary directory |
| 40 | +TMP_DIR=$(mktemp -d) |
| 41 | + |
| 42 | +# cleanup |
| 43 | +exitHandler() ( |
| 44 | + echo "Cleaning up temporary directory" |
| 45 | + rm -rf "${TMP_DIR}" |
| 46 | +) |
| 47 | +trap exitHandler EXIT |
| 48 | + |
| 49 | +GOBIN="${TMP_DIR}" ${GO} install "github.com/tallclair/mdtoc@${TOOL_VERSION}" |
| 50 | +export PATH="${TMP_DIR}:${PATH}" |
| 51 | + |
| 52 | +echo "Checking table of contents are up to date..." |
| 53 | +# Verify tables of contents are up-to-date |
| 54 | +find docs -name '*.md' | xargs mdtoc --inplace --dryrun |
0 commit comments