Skip to content

Commit 778a903

Browse files
committed
Use make
1 parent ae5b4ae commit 778a903

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

docs/docs.mk

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,34 @@ export SHELLOPTS := pipefail:errexit
55
MAKEFLAGS += --warn-undefined-variables
66
MAKEFLAGS += --no-builtin-rule
77

8+
.DEFAULT_GOAL: help
9+
10+
# Adapted from https://www.thapaliya.com/en/writings/well-documented-makefiles/
11+
.PHONY: help
12+
help: ## Display this help.
13+
help:
14+
@awk 'BEGIN {FS = ": ##"; printf "Usage:\n make <target>\n\nTargets:\n"} /^[a-zA-Z0-9_\.\-\/%]+: ##/ { printf " %-45s %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
15+
816
GIT_ROOT := $(shell git rev-parse --show-toplevel)
9-
# Support podman over Docker if it is available.
10-
PODMAN := $(shell if command -v podman >/dev/null 2>&1; then echo podman; else echo docker; fi)
1117

12-
# This allows ports and base URL to be overridden, so services like ngrok.io can
13-
# be used to share a local running docs instances.
14-
DOCS_HOST_PORT := 3002
15-
DOCS_LISTEN_PORT := 3002
16-
DOCS_BASE_URL := "localhost:$(DOCS_HOST_PORT)"
18+
# List of projects to provide to the make-docs script.
19+
PROJECTS := grafana-cloud/k6
20+
21+
# Name for the container.
22+
export DOCS_CONTAINER := $(firstword $(subst /,-,$(PROJECTS))-docs)
1723

18-
PROJECT := k6
19-
PROJECT_VERSION :=
20-
ifeq ($(PROJECT_VERSION),)
21-
PROJECT_URL := http://$(DOCS_BASE_URL)/docs/$(PROJECT)/
22-
PROJECT_CONTENT_DIR := /hugo/content/docs/$(PROJECT)
23-
else
24-
PROJECT_URL := http://$(DOCS_BASE_URL)/docs/$(PROJECT)/$(PROJECT_VERSION)
25-
PROJECT_CONTENT_DIR := /hugo/content/docs/$(PROJECT)/$(PROJECT_VERSION)
26-
endif
24+
# Host port to publish container port to.
25+
export DOCS_HOST_PORT := 3002
2726

28-
DOCS_IMAGE := grafana/docs-base:latest
29-
DOCS_CONTAINER := $(PROJECT)-docs
27+
# Container image used to perform Hugo build.
28+
export DOCS_IMAGE := grafana/docs-base:latest
3029

31-
HUGO_REFLINKSERRORLEVEL ?= WARNING
30+
# PATH-like list of directories within which to find projects.
31+
# If all projects are checked out into the same directory, ~/repos/ for example, then the default should work.
32+
export REPOS_PATH := $(realpath $(GIT_ROOT)/..)
33+
34+
# How to treat Hugo relref errors.
35+
export HUGO_REFLINKSERRORLEVEL := WARNING
3236

3337
.PHONY: docs-rm
3438
docs-rm: ## Remove the docs container.
@@ -38,6 +42,26 @@ docs-rm: ## Remove the docs container.
3842
docs-pull: ## Pull documentation base image.
3943
$(PODMAN) pull $(DOCS_IMAGE)
4044

45+
make-docs: ## Fetch the latest make-docs script.
46+
make-docs:
47+
curl -s -LO https://raw.githubusercontent.com/grafana/writers-toolkit/main/scripts/make-docs
48+
chmod +x make-docs
49+
50+
.PHONY: docs
51+
docs: ## Serve documentation locally.
52+
docs: make-docs
53+
$(PWD)/make-docs $(PROJECTS)
54+
55+
.PHONY: docs/lint
56+
docs/lint: ## Run docs-validator on the entire docs folder.
57+
$(PODMAN) run --rm -ti \
58+
--platform linux/amd64 \
59+
--volume "$(GIT_ROOT)/docs/sources:/docs/sources" \
60+
grafana/doc-validator:latest \
61+
--skip-image-validation \
62+
/docs/sources \
63+
/docs/k6
64+
4165
.PHONY: docs/lint
4266
docs/lint: ## Run docs-validator on the entire docs folder.
4367
docker run --rm -ti \
@@ -47,21 +71,3 @@ docs/lint: ## Run docs-validator on the entire docs folder.
4771
--skip-image-validation \
4872
/docs/sources \
4973
/docs/k6
50-
51-
.PHONY: docs
52-
docs: ## Serve documentation locally.
53-
docs: docs-pull
54-
@echo "Documentation will be served at:"
55-
echo $(PROJECT_URL)
56-
echo ""
57-
if [[ -z $${NON_INTERACTIVE} ]]; then \
58-
read -p "Press enter to continue"; \
59-
fi
60-
$(PODMAN) run -ti \
61-
--init \
62-
-v $(GIT_ROOT)/docs/sources:$(PROJECT_CONTENT_DIR):ro,z \
63-
-e HUGO_REFLINKSERRORLEVEL=$(HUGO_REFLINKSERRORLEVEL) \
64-
-p $(DOCS_HOST_PORT):$(DOCS_LISTEN_PORT) \
65-
--name $(DOCS_CONTAINER) \
66-
--rm \
67-
$(DOCS_IMAGE) make server

0 commit comments

Comments
 (0)