Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update make docs procedure #6930

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 63 additions & 21 deletions docs/make-docs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
# [Semantic versioning](https://semver.org/) is used to help the reader identify the significance of changes.
# Changes are relevant to this script and the support docs.mk GNU Make interface.
#
# ## 8.0.0 (2024-05-28)
#
# ### Changed
#
# - Add environment variable `OUTPUT_FORMAT` to control the output of commands.
#
# The default value is `human` and means the output format is human readable.
# The value `json` is also supported and outputs JSON.
#
# Note that the `json` format isn't supported by `make docs`, only `make doc-validator` and `make vale`.
#
# ## 7.0.0 (2024-05-03)
#
# ### Changed
Expand Down Expand Up @@ -255,6 +266,8 @@ readonly HUGO_REFLINKSERRORLEVEL="${HUGO_REFLINKSERRORLEVEL:-WARNING}"
readonly VALE_MINALERTLEVEL="${VALE_MINALERTLEVEL:-error}"
readonly WEBSITE_EXEC="${WEBSITE_EXEC:-make server-docs}"

readonly OUTPUT_FORMAT="${OUTPUT_FORMAT:-human}"

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
Expand Down Expand Up @@ -748,45 +761,74 @@ POSIX_HERESTRING

case "${image}" in
'grafana/doc-validator')
if ! command -v jq >/dev/null 2>&1; then
errr '`jq` must be installed for the `doc-validator` target to work.'
note 'To install `jq`, refer to https://jqlang.github.io/jq/download/,'

exit 1
fi

proj="$(new_proj "$1")"
printf '\r\n'
"${PODMAN}" run \

IFS='' read -r cmd <<EOF
${PODMAN} run \
--init \
--interactive \
--platform linux/amd64 \
--rm \
--tty \
${volumes} \
"${DOCS_IMAGE}" \
"--include=${DOC_VALIDATOR_INCLUDE}" \
"--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS}" \
"/hugo/content$(proj_canonical "${proj}")" \
"$(proj_canonical "${proj}")" \
| sed "s#$(proj_dst "${proj}")#sources#" \
| jq -r '"ERROR: \(.location.path):\(.location.range.start.line // 1):\(.location.range.start.column // 1): \(.message)" + if .suggestions[0].text then "\nSuggestion: \(.suggestions[0].text)" else "" end'
${DOCS_IMAGE} \
--include=${DOC_VALIDATOR_INCLUDE} \
--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS} \
/hugo/content$(proj_canonical "${proj}") \
"$(proj_canonical "${proj}") \
| sed "s#$(proj_dst "${proj}")#sources#"
EOF

case "${OUTPUT_FORMAT}" in
human)
if ! command -v jq >/dev/null 2>&1; then
errr '`jq` must be installed for the `doc-validator` target to work.'
note 'To install `jq`, refer to https://jqlang.github.io/jq/download/,'

exit 1
fi

${cmd} \
| jq -r '"ERROR: \(.location.path):\(.location.range.start.line // 1):\(.location.range.start.column // 1): \(.message)" + if .suggestions[0].text then "\nSuggestion: \(.suggestions[0].text)" else "" end'
;;
json)
${cmd}
;;
*) # default
errr "Invalid output format '${OUTPUT_FORMAT}'"
esac
;;
'grafana/vale')
proj="$(new_proj "$1")"
printf '\r\n'
"${PODMAN}" run \
IFS='' read -r cmd <<EOF
${PODMAN} run \
--init \
--interactive \
--rm \
--workdir /etc/vale \
--tty \
${volumes} \
"${DOCS_IMAGE}" \
"--minAlertLevel=${VALE_MINALERTLEVEL}" \
'--glob=*.md' \
--output=/etc/vale/rdjsonl.tmpl \
/hugo/content/docs | sed "s#$(proj_dst "${proj}")#sources#"
${DOCS_IMAGE} \
--minAlertLevel=${VALE_MINALERTLEVEL} \
--glob=*.md \
/hugo/content/docs
EOF

case "${OUTPUT_FORMAT}" in
human)
${cmd} --output=line \
| sed "s#$(proj_dst "${proj}")#sources#"
;;
json)
${cmd} --output=/etc/vale/rdjsonl.tmpl \
| sed "s#$(proj_dst "${proj}")#sources#"
;;
*)
errr "Invalid output format '${OUTPUT_FORMAT}'"
esac

;;
*)
tempfile="$(mktemp -t make-docs.XXX)"
Expand Down
Loading