sigs.k8s.io/kueue@v0.6.2/hack/update-toc.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2022 The Kubernetes 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  set -o errexit
    18  set -o nounset
    19  set -o pipefail
    20  
    21  # keep in sync with hack/verify-toc.sh
    22  TOOL_VERSION=b8c54a57d69f29386d055584e595f38d65ce2a1f
    23  
    24  # cd to the root path
    25  ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
    26  cd "${ROOT}"
    27  
    28  # create a temporary directory
    29  TMP_DIR=$(mktemp -d)
    30  
    31  # cleanup
    32  exitHandler() (
    33    echo "Cleaning up..."
    34    rm -rf "${TMP_DIR}"
    35  )
    36  trap exitHandler EXIT
    37  
    38  # Perform go install in a temp dir as we are not tracking this version in a go
    39  # module.
    40  # If we do the go install in the repo, it will create/update go.mod and go.sum.
    41  cd "${TMP_DIR}"
    42  GO111MODULE=on GOBIN="${TMP_DIR}" go install "sigs.k8s.io/mdtoc@${TOOL_VERSION}"
    43  export PATH="${TMP_DIR}:${PATH}"
    44  cd "${ROOT}"
    45  
    46  # Update tables of contents if necessary.
    47  find keps -name '*.md' \
    48      | grep -Fxvf hack/.notableofcontents \
    49      | xargs mdtoc --inplace --max-depth=5  || (
    50        echo "Failed generating TOC. If this failed silently and you are on mac, try 'brew install grep'"
    51        exit 1
    52      )