-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbuild
executable file
·108 lines (107 loc) · 4.11 KB
/
build
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
#!/bin/bash
set -eu
echo "Running website build script"
getGitHubToken() {
# Check if gardener-ci is available (in local setup)
command -v gardener-ci >/dev/null && gardenci="true" || gardenci=""
if [[ $gardenci == "true" ]]; then
# Get a (round-robin) random technical GitHub user credentials
technicalUser=$(gardener-ci config model_element --cfg-type github --cfg-name "${1}" --key credentials | sed -e "s/^GithubCredentials //" -e "s/'/\"/g")
if [[ -n "${technicalUser}" ]]; then
# get auth token and strip lead/trail quotes
authToken=$(jq -r '.authToken' <<<"$technicalUser")
echo "${authToken}"
fi
fi
}
# Compute nessesary variables
if [[ $(uname) == 'Darwin' ]]; then
READLINK_BIN="greadlink"
else
READLINK_BIN="readlink"
fi
if [[ -z "${GARDENER_WEBSITE_GENERATOR_PATH:-}" ]]; then
generatorRepoPath="$(${READLINK_BIN} -f "$(dirname "${0}")/..")"
else
generatorRepoPath="$(${READLINK_BIN} -f "${GARDENER_WEBSITE_GENERATOR_PATH}")"
fi
if [[ ! -d "${generatorRepoPath}" ]]; then
echo "website-generator directory path is invalid ['$generatorRepoPath']. Set GARDENER_WEBSITE_GENERATOR_PATH to a correct path or run from website-generator cloned repo."
exit 1
fi
if [[ -z "${GARDENER_WEBSITE_PATH:-}" ]]; then
# Fallback to "website" repo cloned as peer directory to "website-generator"
websiteRepoPath="$(${READLINK_BIN} -f "$(dirname "${0}")/../../website")"
else
websiteRepoPath="$(${READLINK_BIN} -f "${GARDENER_WEBSITE_PATH}")"
fi
website="${websiteRepoPath}/docs"
echo "Generated site directory: $website"
# Variables
GITHUB_OAUTH_TOKEN=${GITHUB_OAUTH_TOKEN:-$(getGitHubToken github_com)}
# Navigating to website generator
cd "${generatorRepoPath}"
# Clear from previous runs
rm -rf "hugo/content"
rm -rf "hugo/assets/data"
# Docforge prep and run
if [[ -d "${HOME}/.docforge" ]]; then
docforgeCacheDir="${HOME}/.docforge"
else
docforgeCacheDir="$(${READLINK_BIN} -f ./../.docforge)"
fi
if [[ ! -d "${docforgeCacheDir}" ]]; then
echo "creating cache dir: ${docforgeCacheDir}"
mkdir -p "${docforgeCacheDir}"
fi
# Print docforge version
docforge version
echo "cache dir is set to: ${docforgeCacheDir}"
docforge \
-f https://github.com/gardener/documentation/blob/master/.docforge/website.yaml \
-d "hugo/content" \
--hugo \
--github-oauth-token-map "github.com=$GITHUB_OAUTH_TOKEN" \
--github-info-destination "../assets/data" \
--cache-dir "$docforgeCacheDir" \
--skip-link-validation="${SKIP_VALIDATION:-false}"
# Building 404.js
./.ci/404.sh
# Navigating to hugo
cd hugo
if [[ -f content/html/hardened_shoots_report.md ]]; then
mkdir -p static/html
mv content/html/hardened_shoots_report.md static/html/hardened_shoots_report.html
# remove docforge added frontmatters
sed -i '/---/,/---/d' static/html/hardened_shoots_report.html
sed -i 's@/docs/security-and-compliance/report/@/html/hardened_shoots_report.html@' content/docs/security-and-compliance/report.md
sed -i '/<!doctype html>/d' content/docs/security-and-compliance/report.md
sed -i 's/audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}//' content/docs/security-and-compliance/report.md
sed -i 's/a{color:inherit;text-decoration:inherit}//' content/docs/security-and-compliance/report.md
sed -i 's/<div class="tw-content tw-px-6">/<div class="tw-content">/' content/docs/security-and-compliance/report.md
# workaround for a docforge multisource gitinfo build bug
sed -i -n '1,/^}{$/p' assets/data/docs/security-and-compliance/report.md.json
sed -i 's/^}{$/}/' assets/data/docs/security-and-compliance/report.md.json
fi
# Hugo prep and run
if [ "${LOCAL_BUILD:-true}" = false ]; then
echo "Installing npm dependencies"
npm install
pushd themes/docsy
npm install
popd
fi
# Clear website from previous run
rm -rf "$website"
# Commiting to github pages repo
if [ "${PUBLISH:-false}" = true ]; then
hugo --minify --destination "$website"
echo gardener.cloud >"$website/CNAME"
# Bypass Jekyll processing
echo '' >"$website/.nojekyll"
cd "$websiteRepoPath"
echo
echo "Committing website changes"
git add . -A
git commit -m 'Automatic build triggered by last commit' || true
fi