-
Notifications
You must be signed in to change notification settings - Fork 341
/
update_docs.sh
executable file
·135 lines (118 loc) · 3.96 KB
/
update_docs.sh
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env bash
set -x
# Getting the scripts directory can be hard when dealing with sourcing bash files.
# Github actions has this env var set already and locally you can just source the
# build_func.sh yourself. This is just a best effort for local dev.
GITHUB_WORKSPACE=${GITHUB_WORKSPACE:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
DIR="$(cd "$GITHUB_WORKSPACE" || exit; cd ..; pwd)"
while getopts "bv:" opt; do
case $opt in
v)
VERSION="$OPTARG"
TOC_NAME="$(echo "${VERSION}"toc|sed s/\\./-/g)"
;;
b)
BUMP=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Using local build for this portion rather than docer to avoid having to use a go build image, long build with go modules, etc.
# Refresh CLI docs to ensure the docs are up to date when copied for the next version.
echo "Refreshing CLI docs in main docs..."
source "${DIR}/scripts/build_funcs.sh"; update_cli_docs
echo "Done. Beginning to generate docs for specified version..."
if [ -z "${VERSION}" ]
then
echo "-v requires argument to proceed making docs for the given version"
exit 1
fi
read -r -d '' CONFIG_VERSION_BLOCK << EOM
docs_latest: v.*
docs_versions:
- main
EOM
read -r -d '' NEW_VERSION_BLOCK << EOM
docs_latest: ${VERSION}
docs_versions:
- main
- ${VERSION}
EOM
read -r -d '' OLD_SCOPE_BLOCK << EOM
- scope:
path: docs\/main
values:
version: main
gh: https:\/\/github.com\/vmware-tanzu\/sonobuoy\/tree\/main
layout: \"docs\"
EOM
read -r -d '' NEW_SCOPE_BLOCK << EOM
- scope:
path: docs\/main
values:
version: main
gh: https:\/\/github.com\/vmware-tanzu\/sonobuoy\/tree\/main
layout: \"docs\"
- scope:
path: docs\/${VERSION}
values:
version: ${VERSION}
gh: https:\/\/github.com\/vmware-tanzu\/sonobuoy\/tree\/${VERSION}
layout: \"docs\"
EOM
read -r -d '' MAIN_FRONTMATTER << EOM
---
version: main
cascade:
layout: docs
gh: https:\/\/github.com\/vmware-tanzu\/sonobuoy\/tree\/.*
---
EOM
read -r -d '' RELEASE_FRONTMATTER << EOM
---
version: ${VERSION}
cascade:
layout: docs
gh: https:\/\/github.com\/vmware-tanzu\/sonobuoy\/tree\/${VERSION}
---
EOM
OLD_TOC_BLOCK="main: main-toc"
read -r -d '' NEW_TOC_BLOCK << EOM
main: main-toc
${VERSION}: ${TOC_NAME}
EOM
OLD_FOOTER_BLOCK="cta_url: \/docs\/v.*"
NEW_FOOTER_BLOCK="cta_url: \/docs\/${VERSION}"
if [ $BUMP ]
then
echo "-bump was triggered, modifying buildinfo.Version: $OPTARG" >&2
docker run --rm \
-v "${DIR}":/root \
debian:stretch-slim \
/bin/sh -c \
"sed -i 's/var Version.*/var Version = \"${VERSION}\"/' /root/pkg/buildinfo/version.go"
fi
docker run --rm \
-v "${DIR}":/root \
debian:bookworm-slim \
/bin/sh -c \
"rm -rf /root/site/content/docs/${VERSION} && \
cp -r /root/site/content/docs/main /root/site/content/docs/${VERSION} && \
sed -i 's/site\/docs\/main\///g' /root/site/content/docs/${VERSION}/_index.md && \
sed -i 's/docs\/img/img/g' /root/site/content/docs/${VERSION}/_index.md && \
sed -i 's/sonobuoy\/tree\/main/sonobuoy\/tree\/${VERSION}/g' /root/site/content/docs/${VERSION}/_index.md && \
sed -i 's/sonobuoy.io\/docs\/main/sonobuoy.io\/docs\/${VERSION}/g' /root/site/content/docs/${VERSION}/_index.md && \
cp /root/site/data/docs/main-toc.yml /root/site/data/docs/${TOC_NAME}.yml && \
perl -i -0pe 's/${CONFIG_VERSION_BLOCK}/${NEW_VERSION_BLOCK}/' /root/site/config.yaml && \
perl -i -0pe 's/${OLD_SCOPE_BLOCK}/${NEW_SCOPE_BLOCK}/' /root/site/config.yaml && \
perl -i -0pe 's/${OLD_TOC_BLOCK}/${NEW_TOC_BLOCK}/' /root/site/data/docs/toc-mapping.yml && \
perl -i -0pe 's/${MAIN_FRONTMATTER}/${RELEASE_FRONTMATTER}/' /root/site/content/docs/${VERSION}/index-frontmatter.yaml && \
perl -i -0pe 's/${MAIN_FRONTMATTER}/${RELEASE_FRONTMATTER}/' /root/site/content/docs/${VERSION}/_index.md && \
sed -i 's/${OLD_FOOTER_BLOCK}/${NEW_FOOTER_BLOCK}/' /root/site/config.yaml"