#!/bin/sh # The source of this file is https://raw.githubusercontent.com/grafana/writers-toolkit/main/docs/make-docs. # # `make-docs` procedure changelog # # Updates should conform to the guidelines in https://keepachangelog.com/en/1.1.0/. # [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. # ## 4.1.1 (2023-07-20) # ### Fixed # - Replaced use of `realpath` with POSIX compatible alternative to determine default value for REPOS_PATH. # ## 4.1.0 (2023-06-16) # ### Added # - Mounts of `layouts` and `config` directories for the `website` project. # Ensures that local changes to mounts or shortcodes are reflected in the development server. # ### Fixed # - Version inference for versioned docs pages. # Pages in versioned projects now have the `versioned: true` front matter set to ensure that "version" in $.Page.Scratch is set on builds. # ## 4.0.0 (2023-06-06) # ### Removed # - `doc-validator/%` target. # The behavior of the target was not as described. # Instead, to limit `doc-validator` to only specific files, refer to https://grafana.com/docs/writers-toolkit/writing-guide/tooling-and-workflows/validate-technical-documentation/#run-on-specific-files. # ## 3.0.0 (2023-05-18) # ### Fixed # - Compatibility with the updated Make targets in the `website` repository. # `docs` now runs this script itself, `server-docs` builds the site with the `docs` Hugo environment. # ## 2.0.0 (2023-05-18) # ### Added # - Support for the grafana-cloud/frontend-observability/faro-web-sdk project. # - Use of `doc-validator` v2.0.x which includes breaking changes to command line options. # ### Fixed # - Source grafana-cloud project from website repository. # ### Added # - Support for running the Vale linter with `make vale`. # ## 1.2.1 (2023-05-05) # ### Fixed # - Use `latest` tag of `grafana/vale` image by default instead of hardcoded older version. # - Fix mounting multiple projects broken by the changes in 1.0.1 # ## 1.2.0 (2023-05-05) # ### Added # - Support for running the Vale linter with `make vale`. # ### Fixed # ## 1.1.0 (2023-05-05) # ### Added # - Rewrite error output so it can be followed by text editors. # ### Fixed # - Fix `docs-debug` container process port. # ## 1.0.1 (2023-05-04) # ### Fixed # - Ensure complete section hierarchy so that all projects have a visible menu. # ## 1.0.0 (2023-05-04) # ### Added # - Build multiple projects simultaneously if all projects are checked out locally. # - Run [`doc-validator`](https://github.com/grafana/technical-documentation/tree/main/tools/cmd/doc-validator) over projects. # - Redirect project root to mounted version. # For example redirect `/docs/grafana/` to `/docs/grafana/latest/`. # - Support for Podman or Docker containers with `PODMAN` environment variable. # - Support for projects: # - agent # - enterprise-logs # - enterprise-metrics # - enterprise-traces # - grafana # - grafana-cloud # - grafana-cloud/machine-learning # - helm-charts/mimir-distributed # - helm-charts/tempo-distributed # - incident # - loki # - mimir # - oncall # - opentelemetry # - phlare # - plugins # - slo # - tempo # - writers-toolkit set -ef readonly DOCS_CONTAINER="${DOCS_CONTAINER:-make-docs}" readonly DOCS_HOST_PORT="${DOCS_HOST_PORT:-3002}" readonly DOCS_IMAGE="${DOCS_IMAGE:-grafana/docs-base:latest}" readonly DOC_VALIDATOR_INCLUDE="${DOC_VALIDATOR_INCLUDE:-.+\.md$}" readonly DOC_VALIDATOR_SKIP_CHECKS="${DOC_VALIDATOR_SKIP_CHECKS:-^image-}" readonly HUGO_REFLINKSERRORLEVEL="${HUGO_REFLINKSERRORLEVEL:-WARNING}" readonly VALE_MINALERTLEVEL="${VALE_MINALERTLEVEL:-error}" readonly WEBSITE_EXEC="${WEBSITE_EXEC:-make server-docs}" # If set, the docs-base image will run a prebuild script that sets up Hugo mounts. readonly WEBSITE_MOUNTS="${WEBSITE_MOUNTS:-}" PODMAN="$(if command -v podman >/dev/null 2>&1; then echo podman; else echo docker; fi)" about() { cat <...]> $0 [[:[:[:]]]...] Examples: REPOS_PATH=~/ext/grafana/ $0 writers-toolkit tempo:latest helm-charts/mimir-distributed:latest:mimir:docs/sources/mimir-distributed EOF } if [ $# -lt 1 ]; then cat <&2 ERRR: arguments required but not supplied. $(about) $(usage) EOF exit 1 fi readonly REPOS_PATH="${REPOS_PATH:-$(cd "$(git rev-parse --show-toplevel)/.." && echo "${PWD}")}" if [ -z "${REPOS_PATH}" ]; then cat <&2 ERRR: REPOS_PATH environment variable is required but has not been provided. $(usage) EOF exit 1 fi SOURCES_as_code='as-code-docs' SOURCES_beyla='ebpf-autoinstrument' SOURCES_enterprise_metrics='backend-enterprise' SOURCES_enterprise_metrics_='backend-enterprise' SOURCES_grafana_cloud='website' SOURCES_grafana_cloud_alerting_and_irm_machine_learning='machine-learning' SOURCES_grafana_cloud_alerting_and_irm_slo='slo' SOURCES_grafana_cloud_k6='k6-docs' SOURCES_grafana_cloud_data_configuration_integrations='cloud-onboarding' SOURCES_grafana_cloud_frontend_observability_faro_web_sdk='faro-web-sdk' SOURCES_helm_charts_mimir_distributed='mimir' SOURCES_helm_charts_tempo_distributed='tempo' SOURCES_opentelemetry='opentelemetry-docs' SOURCES_plugins_grafana_splunk_datasource='splunk-datasource' VERSIONS_as_code='UNVERSIONED' VERSIONS_grafana_cloud='UNVERSIONED' VERSIONS_grafana_cloud_alerting_and_irm_machine_learning='UNVERSIONED' VERSIONS_grafana_cloud_alerting_and_irm_slo='UNVERSIONED' VERSIONS_grafana_cloud_k6='UNVERSIONED' VERSIONS_grafana_cloud_data_configuration_integrations='UNVERSIONED' VERSIONS_grafana_cloud_frontend_observability_faro_web_sdk='UNVERSIONED' VERSIONS_opentelemetry='UNVERSIONED' VERSIONS_technical_documentation='UNVERSIONED' VERSIONS_website='UNVERSIONED' VERSIONS_writers_toolkit='UNVERSIONED' PATHS_grafana_cloud='content/docs/grafana-cloud' PATHS_helm_charts_mimir_distributed='docs/sources/helm-charts/mimir-distributed' PATHS_helm_charts_tempo_distributed='docs/sources/helm-charts/tempo-distributed' PATHS_mimir='docs/sources/mimir' PATHS_tempo='docs/sources/tempo' PATHS_website='content/docs' # identifier STR # Replace characters that are not valid in an identifier with underscores. identifier() { echo "$1" | tr -C '[:alnum:]_\n' '_' } # aget ARRAY KEY # Get the value of KEY from associative array ARRAY. # Characters that are not valid in an identifier are replaced with underscores. aget() { eval echo '$'"$(identifier "$1")_$(identifier "$2")" } # new_proj populates a new project structure. new_proj() { _project="$1" _version="$2" _repo="$3" _path="$4" # If version is not set, use the script mapping of project to default versions if it exists. # Fallback to 'latest'. if [ -z "${_version}" ]; then if [ -z "$(aget VERSIONS "${_project}")" ]; then _version=latest else _version="$(aget VERSIONS "${_project}")" fi fi # If repo is not set, use the script mapping of project to repo name if it exists. # Fallback to using the project name. if [ -z "${_repo}" ]; then if [ -z "$(aget SOURCES "${_project}")" ]; then _repo="${_project}" else _repo="$(aget SOURCES "${_project}")" fi fi # If path is not set, use the script mapping of project to docs sources path if it exists. # Fallback to using 'docs/sources'. if [ -z "${_path}" ]; then if [ -z "$(aget PATHS "${_project}")" ]; then _path="docs/sources" else _path="$(aget PATHS "${_project}")" fi fi echo "${_project}:${_version}:${_repo}:${_path}" unset _project _version _repo _path } # proj_url returns the webserver URL for a project. # It expects a complete project structure as input. proj_url() { IFS=: read -r _project _version _ _ <&2 echo "NOTE: you must have a checkout of the project '${_repo}' at '${REPOS_PATH##:*}/${_repo}'." >&2 echo "NOTE: if you have cloned the repository into a directory with a different name, consider changing it to ${_repo}." >&2 unset _repo exit 1 } # proj_src returns the host path to content source for a project. # It expects a complete project structure as input. # It looks for the provided repository name in each of the paths specified in the REPOS_PATH environment variable. proj_src() { IFS=: read -r _ _ _repo _path <&2 echo "Is '${_src}' the correct source directory?" >&2 exit 1 fi fi echo "DEBG: Mounting '${_src}' at container path '${_dst}'" >&2 if [ -z "${volumes}" ]; then volumes="--volume=${_src}:${_dst}" else volumes="${volumes} --volume=${_src}:${_dst}" fi if [ -n "${_ver}" ] && [ "${_ver}" != 'UNVERSIONED' ]; then if [ -z "${redirects}" ]; then redirects="${_dst}^${_ver}" else redirects="${redirects} ${_dst}^${_ver}" fi fi unset _url _src _dst _ver done IFS=':' read -r image _ <"${tempfile}" #!/usr/bin/env bash for redirect in ${redirects}; do IFS='^' read -r path ver <<<"\${redirect}" echo -e "---\\nredirectURL: \"\${path/\/hugo\/content/}\"\\ntype: redirect\\nversioned: true\\n---\\n" > "\${path/\${ver}/_index.md}" done for x in "${url_src_dst_vers}"; do IFS='^' read -r _ _ dst _ <<<"\${x}" while [[ -n "\${dst}" ]]; do touch "\${dst}/_index.md" dst="\${dst%/*}" done done if [[ -n "${WEBSITE_MOUNTS}" ]]; then unset WEBSITE_SKIP_MOUNTS fi ${WEBSITE_EXEC} EOF chmod +x "${tempfile}" volumes="${volumes} --volume=${tempfile}:/entrypoint" readonly volumes echo echo "Documentation will be served at the following URLs:" for x in ${url_src_dst_vers}; do IFS='^' read -r url _ _ <