Update make docs procedure (#73540)

Co-authored-by: grafanabot <bot@grafana.com>
This commit is contained in:
github-actions[bot] 2023-08-21 08:56:54 +01:00 committed by GitHub
parent 220ea869be
commit 88d3f27b6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 124 additions and 58 deletions

View File

@ -76,7 +76,7 @@ docs-rm: ## Remove the docs container.
.PHONY: docs-pull .PHONY: docs-pull
docs-pull: ## Pull documentation base image. docs-pull: ## Pull documentation base image.
$(PODMAN) pull $(DOCS_IMAGE) $(PODMAN) pull -q $(DOCS_IMAGE)
make-docs: ## Fetch the latest make-docs script. make-docs: ## Fetch the latest make-docs script.
make-docs: make-docs:

View File

@ -133,6 +133,21 @@ readonly WEBSITE_MOUNTS="${WEBSITE_MOUNTS:-}"
PODMAN="$(if command -v podman >/dev/null 2>&1; then echo podman; else echo docker; fi)" PODMAN="$(if command -v podman >/dev/null 2>&1; then echo podman; else echo docker; fi)"
if ! command -v curl >/dev/null 2>&1; then
if ! command -v wget >/dev/null 2>&1; then
errr 'either `curl` or `wget` must be installed for this script to work.'
exit 1
fi
fi
if ! command -v "${PODMAN}" >/dev/null 2>&1; then
errr 'either `podman` or `docker` must be installed for this script to work.'
exit 1
fi
about() { about() {
cat <<EOF cat <<EOF
Test documentation locally with multiple source repositories. Test documentation locally with multiple source repositories.
@ -332,9 +347,10 @@ repo_path() {
done done
unset IFS unset IFS
echo "ERRR: could not find project '${_repo}' in any of the paths in REPOS_PATH '${REPOS_PATH}'." >&2 errr "could not find project '${_repo}' in any of the paths in REPOS_PATH '${REPOS_PATH}'."
echo "NOTE: you must have a checkout of the project '${_repo}' at '${REPOS_PATH##:*}/${_repo}'." >&2 note "you must have a checkout of the project '${_repo}' at '${REPOS_PATH##:*}/${_repo}'."
echo "NOTE: if you have cloned the repository into a directory with a different name, consider changing it to ${_repo}." >&2 note "if you have cloned the repository into a directory with a different name, consider changing it to ${_repo}."
unset _repo unset _repo
exit 1 exit 1
} }
@ -420,6 +436,50 @@ POSIX_HERESTRING
unset _project _version _repo _path unset _project _version _repo _path
} }
await_build() {
url="$1"
req="$(if command -v curl >/dev/null 2>&1; then echo 'curl -s -o /dev/null'; else echo 'wget -q'; fi)"
sleep 2
if ${req} "${url}"; then
echo
echo "View documentation locally:"
for x in ${url_src_dst_vers}; do
IFS='^' read -r url _ _ <<POSIX_HERESTRING
$x
POSIX_HERESTRING
if [ -n "${url}" ]; then
if [ "${_url}" != "arbitrary" ]; then
echo " ${url}"
fi
fi
done
echo
echo 'Press Ctrl+C to stop the server'
else
echo
errr 'The build was interrupted or a build error occurred, check the previous logs for possible causes.'
fi
unset url req
}
debg() {
if [ -n "${DEBUG}" ]; then
echo "DEBG: $1" >&2
fi
}
errr() {
echo "ERRR: $1" >&2
}
note() {
echo "NOTE: $1" >&2
}
url_src_dst_vers="$(url_src_dst_vers "$@")" url_src_dst_vers="$(url_src_dst_vers "$@")"
volumes="" volumes=""
@ -445,13 +505,14 @@ POSIX_HERESTRING
if [ "${_url}" != "arbitrary" ]; then if [ "${_url}" != "arbitrary" ]; then
if [ ! -f "${_src}/_index.md" ]; then if [ ! -f "${_src}/_index.md" ]; then
echo "ERRR: Index file '${_src}/_index.md' does not exist." >&2 errr "Index file '${_src}/_index.md' does not exist."
echo "Is '${_src}' the correct source directory?" >&2 note "Is '${_src}' the correct source directory?"
exit 1 exit 1
fi fi
fi fi
echo "DEBG: Mounting '${_src}' at container path '${_dst}'" >&2 debg "DEBG: Mounting '${_src}' at container path '${_dst}'"
if [ -z "${volumes}" ]; then if [ -z "${volumes}" ]; then
volumes="--volume=${_src}:${_dst}" volumes="--volume=${_src}:${_dst}"
else else
@ -477,35 +538,35 @@ case "${image}" in
proj="$(new_proj "$1")" proj="$(new_proj "$1")"
echo echo
"${PODMAN}" run \ "${PODMAN}" run \
--init \ --init \
--interactive \ --interactive \
--name "${DOCS_CONTAINER}" \ --name "${DOCS_CONTAINER}" \
--platform linux/amd64 \ --platform linux/amd64 \
--rm \ --rm \
--tty \ --tty \
${volumes} \ ${volumes} \
"${DOCS_IMAGE}" \ "${DOCS_IMAGE}" \
"--include=${DOC_VALIDATOR_INCLUDE}" \ "--include=${DOC_VALIDATOR_INCLUDE}" \
"--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS}" \ "--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS}" \
/hugo/content/docs \ /hugo/content/docs \
"$(proj_canonical "${proj}")" | sed "s#$(proj_dst "${proj}")#sources#" "$(proj_canonical "${proj}")" | sed "s#$(proj_dst "${proj}")#sources#"
;; ;;
'grafana/vale') 'grafana/vale')
proj="$(new_proj "$1")" proj="$(new_proj "$1")"
echo echo
"${PODMAN}" run \ "${PODMAN}" run \
--init \ --init \
--interactive \ --interactive \
--name "${DOCS_CONTAINER}" \ --name "${DOCS_CONTAINER}" \
--platform linux/amd64 \ --platform linux/amd64 \
--rm \ --rm \
--tty \ --tty \
${volumes} \ ${volumes} \
"${DOCS_IMAGE}" \ "${DOCS_IMAGE}" \
"--minAlertLevel=${VALE_MINALERTLEVEL}" \ "--minAlertLevel=${VALE_MINALERTLEVEL}" \
--config=/etc/vale/.vale.ini \ --config=/etc/vale/.vale.ini \
--output=line \ --output=line \
/hugo/content/docs | sed "s#$(proj_dst "${proj}")#sources#" /hugo/content/docs | sed "s#$(proj_dst "${proj}")#sources#"
;; ;;
*) *)
tempfile="$(mktemp -t make-docs.XXX)" tempfile="$(mktemp -t make-docs.XXX)"
@ -535,33 +596,38 @@ EOF
volumes="${volumes} --volume=${tempfile}:/entrypoint" volumes="${volumes} --volume=${tempfile}:/entrypoint"
readonly volumes readonly volumes
echo IFS='' read -r cmd <<EOF
echo "Documentation will be served at the following URLs:" ${PODMAN} run \
for x in ${url_src_dst_vers}; do --env=HUGO_REFLINKSERRORLEVEL=${HUGO_REFLINKSERRORLEVEL} \
IFS='^' read -r url _ _ <<POSIX_HERESTRING --init \
$x --interactive \
POSIX_HERESTRING --name=${DOCS_CONTAINER} \
--platform=linux/amd64 \
--publish=${DOCS_HOST_PORT}:3002 \
--publish=3003:3003 \
--rm \
--tty \
${volumes} \
${DOCS_IMAGE} \
/entrypoint
EOF
await_build http://localhost:3002 &
if [ -n "${url}" ]; then if [ -n "${DEBUG}" ]; then
if [ "${_url}" != "arbitrary" ]; then ${cmd}
echo " ${url}" else
fi ${cmd} 2>&1| sed \
fi -e '/Web Server is available at http:\/\/localhost:3003\/ (bind address 0.0.0.0)/ d' \
done -e '/^hugo server/ d' \
-e '/fatal: not a git repository (or any parent up to mount point \/)/ d' \
echo -e '/Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)./ d' \
"${PODMAN}" run \ -e "/Makefile:[0-9]*: warning: overriding recipe for target 'docs'/ d" \
--env "HUGO_REFLINKSERRORLEVEL=${HUGO_REFLINKSERRORLEVEL}" \ -e "/docs.mk:[0-9]*: warning: ignoring old recipe for target 'docs'/ d" \
--init \ -e '/\/usr\/bin\/make -j 2 proxy hserver-docs HUGO_PORT=3003/ d' \
--interactive \ -e '/website-proxy/ d' \
--name "${DOCS_CONTAINER}" \ -e '/rm -rf dist*/ d' \
--platform linux/amd64 \ -e '/Press Ctrl+C to stop/ d' \
--publish "${DOCS_HOST_PORT}:3002" \ -e '/make/ d' || echo
--publish "3003:3003" \ fi
--rm \
--tty \
${volumes} \
"${DOCS_IMAGE}" \
/entrypoint
;; ;;
esac esac