Skip to content

Commit 0c81904

Browse files
authored
Migrate toc updating and verification scripts (antrea-io#21)
Signed-off-by: Yanjun Zhou <[email protected]>
1 parent e216981 commit 0c81904

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,16 @@ manifest:
120120
verify:
121121
@echo "===> Verifying spellings <==="
122122
GO=$(GO) $(CURDIR)/hack/verify-spelling.sh
123+
@echo "===> Verifying Table of Contents <==="
124+
GO=$(GO) $(CURDIR)/hack/verify-toc.sh
123125
@echo "===> Verifying documentation formatting for website <==="
124126
$(CURDIR)/hack/verify-docs-for-website.sh
125127

128+
.PHONY: toc
129+
toc:
130+
@echo "===> Generating Table of Contents for Theia docs <==="
131+
GO=$(GO) $(CURDIR)/hack/update-toc.sh
132+
126133
.PHONE: markdownlint
127134
markdownlint:
128135
@echo "===> Running markdownlint <==="

hack/mdtoc-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ee652eb78c047a7b6c7417d9324a97bb05689563

hack/update-toc.sh

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 a copy of script 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..."
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+
# Update tables of contents if necessary.
53+
find docs -name '*.md' | xargs mdtoc --inplace

hack/verify-toc.sh

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)