Skip to content

Commit 5d5abe9

Browse files
Update make docs procedure (#3321)
Co-authored-by: grafanabot <[email protected]>
1 parent a767e2c commit 5d5abe9

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

docs/make-docs

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
# [Semantic versioning](https://semver.org/) is used to help the reader identify the significance of changes.
77
# Changes are relevant to this script and the support docs.mk GNU Make interface.
88
#
9+
# ## 8.0.0 (2024-05-28)
10+
#
11+
# ### Changed
12+
#
13+
# - Add environment variable `OUTPUT_FORMAT` to control the output of commands.
14+
#
15+
# The default value is `human` and means the output format is human readable.
16+
# The value `json` is also supported and outputs JSON.
17+
#
18+
# Note that the `json` format isn't supported by `make docs`, only `make doc-validator` and `make vale`.
19+
#
920
# ## 7.0.0 (2024-05-03)
1021
#
1122
# ### Changed
@@ -255,6 +266,8 @@ readonly HUGO_REFLINKSERRORLEVEL="${HUGO_REFLINKSERRORLEVEL:-WARNING}"
255266
readonly VALE_MINALERTLEVEL="${VALE_MINALERTLEVEL:-error}"
256267
readonly WEBSITE_EXEC="${WEBSITE_EXEC:-make server-docs}"
257268

269+
readonly OUTPUT_FORMAT="${OUTPUT_FORMAT:-human}"
270+
258271
PODMAN="$(if command -v podman >/dev/null 2>&1; then echo podman; else echo docker; fi)"
259272

260273
if ! command -v curl >/dev/null 2>&1; then
@@ -748,45 +761,74 @@ POSIX_HERESTRING
748761

749762
case "${image}" in
750763
'grafana/doc-validator')
751-
if ! command -v jq >/dev/null 2>&1; then
752-
errr '`jq` must be installed for the `doc-validator` target to work.'
753-
note 'To install `jq`, refer to https://jqlang.github.io/jq/download/,'
754-
755-
exit 1
756-
fi
757-
758764
proj="$(new_proj "$1")"
759765
printf '\r\n'
760-
"${PODMAN}" run \
766+
767+
IFS='' read -r cmd <<EOF
768+
${PODMAN} run \
761769
--init \
762770
--interactive \
763771
--platform linux/amd64 \
764772
--rm \
765773
--tty \
766774
${volumes} \
767-
"${DOCS_IMAGE}" \
768-
"--include=${DOC_VALIDATOR_INCLUDE}" \
769-
"--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS}" \
770-
"/hugo/content$(proj_canonical "${proj}")" \
771-
"$(proj_canonical "${proj}")" \
772-
| sed "s#$(proj_dst "${proj}")#sources#" \
773-
| 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'
775+
${DOCS_IMAGE} \
776+
--include=${DOC_VALIDATOR_INCLUDE} \
777+
--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS} \
778+
/hugo/content$(proj_canonical "${proj}") \
779+
"$(proj_canonical "${proj}") \
780+
| sed "s#$(proj_dst "${proj}")#sources#"
781+
EOF
782+
783+
case "${OUTPUT_FORMAT}" in
784+
human)
785+
if ! command -v jq >/dev/null 2>&1; then
786+
errr '`jq` must be installed for the `doc-validator` target to work.'
787+
note 'To install `jq`, refer to https://jqlang.github.io/jq/download/,'
788+
789+
exit 1
790+
fi
791+
792+
${cmd} \
793+
| 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'
794+
;;
795+
json)
796+
${cmd}
797+
;;
798+
*) # default
799+
errr "Invalid output format '${OUTPUT_FORMAT}'"
800+
esac
774801
;;
775802
'grafana/vale')
776803
proj="$(new_proj "$1")"
777804
printf '\r\n'
778-
"${PODMAN}" run \
805+
IFS='' read -r cmd <<EOF
806+
${PODMAN} run \
779807
--init \
780808
--interactive \
781809
--rm \
782810
--workdir /etc/vale \
783811
--tty \
784812
${volumes} \
785-
"${DOCS_IMAGE}" \
786-
"--minAlertLevel=${VALE_MINALERTLEVEL}" \
787-
'--glob=*.md' \
788-
--output=/etc/vale/rdjsonl.tmpl \
789-
/hugo/content/docs | sed "s#$(proj_dst "${proj}")#sources#"
813+
${DOCS_IMAGE} \
814+
--minAlertLevel=${VALE_MINALERTLEVEL} \
815+
--glob=*.md \
816+
/hugo/content/docs
817+
EOF
818+
819+
case "${OUTPUT_FORMAT}" in
820+
human)
821+
${cmd} --output=line \
822+
| sed "s#$(proj_dst "${proj}")#sources#"
823+
;;
824+
json)
825+
${cmd} --output=/etc/vale/rdjsonl.tmpl \
826+
| sed "s#$(proj_dst "${proj}")#sources#"
827+
;;
828+
*)
829+
errr "Invalid output format '${OUTPUT_FORMAT}'"
830+
esac
831+
790832
;;
791833
*)
792834
tempfile="$(mktemp -t make-docs.XXX)"

0 commit comments

Comments
 (0)