2023-05-18 09:50:20 -05:00
# The source of this file is https://raw.githubusercontent.com/grafana/writers-toolkit/main/docs/docs.mk.
2023-07-18 03:52:11 -05:00
# A changelog is included in the head of the `make-docs` script.
2023-04-18 05:46:10 -05:00
i n c l u d e v a r i a b l e s . m k
- i n c l u d e v a r i a b l e s . m k . l o c a l
.ONESHELL :
.DELETE_ON_ERROR :
export SHELL := bash
export SHELLOPTS := pipefail:errexit
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rule
.DEFAULT_GOAL : help
# Adapted from https://www.thapaliya.com/en/writings/well-documented-makefiles/
.PHONY : help
help : ## Display this help.
help :
2023-04-24 10:23:33 -05:00
@awk ' BEGIN { \
FS = ": ##" ; \
printf "Usage:\n make <target>\n\nTargets:\n" \
} \
/^[ a-zA-Z0-9_\. \- \/ %] +: ##/ { printf " %-15s %s\n", $$1, $$2 }' \
$( MAKEFILE_LIST)
2023-04-18 05:46:10 -05:00
GIT_ROOT := $( shell git rev-parse --show-toplevel)
PODMAN := $( shell if command -v podman >/dev/null 2>& 1; then echo podman; else echo docker; fi )
i f e q ( $( PROJECTS ) , )
$( error "PROJECTS variable must be defined in variables .mk ")
e n d i f
# First project is considered the primary one used for doc-validator.
2023-04-24 10:23:33 -05:00
PRIMARY_PROJECT := $( subst /,-,$( firstword $( subst :, ,$( firstword $( PROJECTS) ) ) ) )
2023-04-18 05:46:10 -05:00
# Host port to publish container port to.
2023-04-24 10:23:33 -05:00
i f e q ( $( origin DOCS_HOST_PORT ) , u n d e f i n e d )
2023-04-18 05:46:10 -05:00
export DOCS_HOST_PORT := 3002
2023-04-24 10:23:33 -05:00
e n d i f
2023-04-18 05:46:10 -05:00
# Container image used to perform Hugo build.
2023-04-24 10:23:33 -05:00
i f e q ( $( origin DOCS_IMAGE ) , u n d e f i n e d )
2023-04-18 05:46:10 -05:00
export DOCS_IMAGE := grafana/docs-base:latest
2023-04-24 10:23:33 -05:00
e n d i f
2023-04-18 05:46:10 -05:00
# Container image used for doc-validator linting.
2023-04-24 10:23:33 -05:00
i f e q ( $( origin DOC_VALIDATOR_IMAGE ) , u n d e f i n e d )
2023-04-18 05:46:10 -05:00
export DOC_VALIDATOR_IMAGE := grafana/doc-validator:latest
2023-04-24 10:23:33 -05:00
e n d i f
2023-04-18 05:46:10 -05:00
2023-05-18 09:50:20 -05:00
# Container image used for vale linting.
i f e q ( $( origin VALE_IMAGE ) , u n d e f i n e d )
export VALE_IMAGE := grafana/vale:latest
e n d i f
2023-04-18 05:46:10 -05:00
# PATH-like list of directories within which to find projects.
# If all projects are checked out into the same directory, ~/repos/ for example, then the default should work.
2023-04-24 10:23:33 -05:00
i f e q ( $( origin REPOS_PATH ) , u n d e f i n e d )
2023-04-18 05:46:10 -05:00
export REPOS_PATH := $( realpath $( GIT_ROOT) /..)
2023-04-24 10:23:33 -05:00
e n d i f
2023-04-18 05:46:10 -05:00
# How to treat Hugo relref errors.
2023-04-24 10:23:33 -05:00
i f e q ( $( origin HUGO_REFLINKSERRORLEVEL ) , u n d e f i n e d )
2023-04-18 05:46:10 -05:00
export HUGO_REFLINKSERRORLEVEL := WARNING
2023-04-24 10:23:33 -05:00
e n d i f
2023-04-18 05:46:10 -05:00
2024-05-16 06:00:32 -05:00
# Whether to pull the latest container image before running the container.
i f e q ( $( origin PULL ) , u n d e f i n e d )
export PULL := true
e n d i f
2023-04-18 05:46:10 -05:00
.PHONY : docs -rm
docs-rm : ## Remove the docs container.
$( PODMAN) rm -f $( DOCS_CONTAINER)
.PHONY : docs -pull
docs-pull : ## Pull documentation base image.
2023-08-21 02:56:54 -05:00
$( PODMAN) pull -q $( DOCS_IMAGE)
2023-04-18 05:46:10 -05:00
make-docs : ## Fetch the latest make-docs script.
make-docs :
2023-09-20 11:19:40 -05:00
if [ [ ! -f " $( CURDIR) /make-docs " ] ] ; then
2023-04-24 10:23:33 -05:00
echo 'WARN: No make-docs script found in the working directory. Run `make update` to download it.' >& 2
exit 1
fi
2023-04-18 05:46:10 -05:00
.PHONY : docs
2024-05-16 06:00:32 -05:00
docs : ## Serve documentation locally, which includes pulling the latest `DOCS_IMAGE` (default: `grafana/docs-base:latest`) container image. To not pull the image, set `PULL=false`.
i f e q ( $( PULL ) , t r u e )
2023-04-18 05:46:10 -05:00
docs : docs -pull make -docs
2024-05-16 06:00:32 -05:00
e l s e
docs : make -docs
e n d i f
2023-09-20 11:19:40 -05:00
$( CURDIR) /make-docs $( PROJECTS)
2023-04-18 05:46:10 -05:00
2023-04-24 10:23:33 -05:00
.PHONY : docs -debug
docs-debug : ## Run Hugo web server with debugging enabled. TODO: support all SERVER_FLAGS defined in website Makefile.
docs-debug : make -docs
2023-09-20 11:19:40 -05:00
WEBSITE_EXEC = 'hugo server --bind 0.0.0.0 --port 3002 --debug' $( CURDIR) /make-docs $( PROJECTS)
2023-04-24 10:23:33 -05:00
2023-04-18 05:46:10 -05:00
.PHONY : doc -validator
2024-05-16 06:00:32 -05:00
doc-validator : ## Run doc-validator on the entire docs folder which includes pulling the latest `DOC_VALIDATOR_IMAGE` (default: `grafana/doc-validator:latest`) container image. To not pull the image, set `PULL=false`.
2023-04-24 10:23:33 -05:00
doc-validator : make -docs
2024-05-16 06:00:32 -05:00
i f e q ( $( PULL ) , t r u e )
$( PODMAN) pull -q $( DOC_VALIDATOR_IMAGE)
e n d i f
2023-09-20 11:19:40 -05:00
DOCS_IMAGE = $( DOC_VALIDATOR_IMAGE) $( CURDIR) /make-docs $( PROJECTS)
2023-04-18 05:46:10 -05:00
2023-05-18 09:50:20 -05:00
.PHONY : vale
2024-05-16 06:00:32 -05:00
vale : ## Run vale on the entire docs folder which includes pulling the latest `VALE_IMAGE` (default: `grafana/vale:latest`) container image. To not pull the image, set `PULL=false`.
2023-05-18 09:50:20 -05:00
vale : make -docs
2024-05-16 06:00:32 -05:00
i f e q ( $( PULL ) , t r u e )
$( PODMAN) pull -q $( VALE_IMAGE)
e n d i f
2023-09-20 11:19:40 -05:00
DOCS_IMAGE = $( VALE_IMAGE) $( CURDIR) /make-docs $( PROJECTS)
2023-05-18 09:50:20 -05:00
2023-04-24 10:23:33 -05:00
.PHONY : update
update : ## Fetch the latest version of this Makefile and the `make-docs` script from Writers' Toolkit.
2023-04-18 05:46:10 -05:00
curl -s -LO https://raw.githubusercontent.com/grafana/writers-toolkit/main/docs/docs.mk
2023-04-24 10:23:33 -05:00
curl -s -LO https://raw.githubusercontent.com/grafana/writers-toolkit/main/docs/make-docs
chmod +x make-docs