|
6 | 6 | # [Semantic versioning](https://semver.org/) is used to help the reader identify the significance of changes.
|
7 | 7 | # Changes are relevant to this script and the support docs.mk GNU Make interface.
|
8 | 8 | #
|
| 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 | +# |
9 | 20 | # ## 7.0.0 (2024-05-03)
|
10 | 21 | #
|
11 | 22 | # ### Changed
|
@@ -255,6 +266,8 @@ readonly HUGO_REFLINKSERRORLEVEL="${HUGO_REFLINKSERRORLEVEL:-WARNING}"
|
255 | 266 | readonly VALE_MINALERTLEVEL="${VALE_MINALERTLEVEL:-error}"
|
256 | 267 | readonly WEBSITE_EXEC="${WEBSITE_EXEC:-make server-docs}"
|
257 | 268 |
|
| 269 | +readonly OUTPUT_FORMAT="${OUTPUT_FORMAT:-human}" |
| 270 | + |
258 | 271 | PODMAN="$(if command -v podman >/dev/null 2>&1; then echo podman; else echo docker; fi)"
|
259 | 272 |
|
260 | 273 | if ! command -v curl >/dev/null 2>&1; then
|
@@ -748,45 +761,74 @@ POSIX_HERESTRING
|
748 | 761 |
|
749 | 762 | case "${image}" in
|
750 | 763 | '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 |
| - |
758 | 764 | proj="$(new_proj "$1")"
|
759 | 765 | printf '\r\n'
|
760 |
| - "${PODMAN}" run \ |
| 766 | + |
| 767 | + IFS='' read -r cmd <<EOF |
| 768 | + ${PODMAN} run \ |
761 | 769 | --init \
|
762 | 770 | --interactive \
|
763 | 771 | --platform linux/amd64 \
|
764 | 772 | --rm \
|
765 | 773 | --tty \
|
766 | 774 | ${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 |
774 | 801 | ;;
|
775 | 802 | 'grafana/vale')
|
776 | 803 | proj="$(new_proj "$1")"
|
777 | 804 | printf '\r\n'
|
778 |
| - "${PODMAN}" run \ |
| 805 | + IFS='' read -r cmd <<EOF |
| 806 | + ${PODMAN} run \ |
779 | 807 | --init \
|
780 | 808 | --interactive \
|
781 | 809 | --rm \
|
782 | 810 | --workdir /etc/vale \
|
783 | 811 | --tty \
|
784 | 812 | ${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 | + |
790 | 832 | ;;
|
791 | 833 | *)
|
792 | 834 | tempfile="$(mktemp -t make-docs.XXX)"
|
|
0 commit comments