Skip to content

Commit 08dc793

Browse files
committed
feat: enhance docs-related make targets with changed-files focus
- Add detection of changed markdown files in the docs directory - Make lint/docs focus on changed files by default - Add --all option to check all files instead of just changed ones - Update Vale style checking to only validate changed files - Improve message clarity for all documentation targets
1 parent 53bdc1f commit 08dc793

File tree

1 file changed

+93
-3
lines changed

1 file changed

+93
-3
lines changed

Makefile

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ MOST_GO_SRC_FILES := $(shell \
6666
)
6767
# All the shell files in the repo, excluding ignored files.
6868
SHELL_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.sh')
69+
# All markdown files in docs directory, used to determine if docs targets should run
70+
DOCS_MD_FILES := $(shell find ./docs $(FIND_EXCLUSIONS) -type f -name '*.md' 2>/dev/null | wc -l | tr -d ' ')
71+
# Changed markdown files (if in a git repo), otherwise empty
72+
DOCS_CHANGED_FILES := $(shell git diff --name-only --diff-filter=ACMR HEAD 2>/dev/null | grep -E '^docs/.*\.md$$' 2>/dev/null || echo "")
6973

7074
# Ensure we don't use the user's git configs which might cause side-effects
7175
GIT_FLAGS = GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null
@@ -501,13 +505,54 @@ endif
501505
.PHONY: fmt/shfmt
502506

503507
fmt/markdown: node_modules/.installed
504-
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/markdown$(RESET)"
505-
pnpm format-docs
508+
@if [ "$(DOCS_MD_FILES)" -gt 0 ]; then \
509+
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/markdown$(RESET)"; \
510+
if echo "$(MAKEFLAGS)" | grep -q "all"; then \
511+
echo "Formatting all documentation files..."; \
512+
pnpm format-docs; \
513+
else \
514+
if [ -n "$(DOCS_CHANGED_FILES)" ]; then \
515+
echo "Formatting changed files only: $(DOCS_CHANGED_FILES)"; \
516+
pnpm exec markdown-table-formatter $(DOCS_CHANGED_FILES) 2>/dev/null || echo "No tables found to format"; \
517+
else \
518+
echo "No changed files detected, running standard format..."; \
519+
pnpm format-docs; \
520+
fi; \
521+
fi; \
522+
else \
523+
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/markdown$(RESET) (skipped - no docs files)"; \
524+
fi
506525
.PHONY: fmt/markdown
507526

508527
lint: lint/shellcheck lint/go lint/ts lint/examples lint/helm lint/site-icons lint/markdown
509528
.PHONY: lint
510529

530+
# Check document style with Vale (optional, opt-in, --all to check all files)
531+
lint/docs-style: node_modules/.installed
532+
@if [ "$(DOCS_MD_FILES)" -gt 0 ]; then \
533+
echo "$(GREEN)==>$(RESET) $(BOLD)lint/docs-style$(RESET)"; \
534+
if command -v vale >/dev/null 2>&1; then \
535+
if echo "$(MAKEFLAGS)" | grep -q "all"; then \
536+
echo "Checking all documentation files..."; \
537+
vale --no-exit --config=.github/docs/vale/.vale.ini docs/; \
538+
else \
539+
if [ -n "$(DOCS_CHANGED_FILES)" ]; then \
540+
echo "Checking changed files only: $(DOCS_CHANGED_FILES)"; \
541+
vale --no-exit --config=.github/docs/vale/.vale.ini $(DOCS_CHANGED_FILES); \
542+
else \
543+
echo "No changed files detected, checking representative files..."; \
544+
vale --no-exit --config=.github/docs/vale/.vale.ini docs/README.md docs/index.md 2>/dev/null || echo "No representative files found"; \
545+
fi; \
546+
fi; \
547+
else \
548+
echo "Vale is an optional tool for style checking."; \
549+
echo "If you want to install it: brew install vale (or see https://vale.sh)"; \
550+
fi; \
551+
else \
552+
echo "$(GREEN)==>$(RESET) $(BOLD)lint/docs-style$(RESET) (skipped - no docs files)"; \
553+
fi
554+
.PHONY: lint/docs-style
555+
511556
lint/site-icons:
512557
./scripts/check_site_icons.sh
513558
.PHONY: lint/site-icons
@@ -540,9 +585,54 @@ lint/helm:
540585
.PHONY: lint/helm
541586

542587
lint/markdown: node_modules/.installed
543-
pnpm lint-docs
588+
@if [ "$(DOCS_MD_FILES)" -gt 0 ]; then \
589+
echo "$(GREEN)==>$(RESET) $(BOLD)lint/markdown$(RESET)"; \
590+
if echo "$(MAKEFLAGS)" | grep -q "all"; then \
591+
echo "Checking all documentation files..."; \
592+
pnpm lint-docs; \
593+
else \
594+
if [ -n "$(DOCS_CHANGED_FILES)" ]; then \
595+
echo "Checking changed files only: $(DOCS_CHANGED_FILES)"; \
596+
pnpm exec markdownlint-cli2 $(DOCS_CHANGED_FILES); \
597+
else \
598+
echo "No changed files detected, running standard lint..."; \
599+
pnpm lint-docs; \
600+
fi; \
601+
fi; \
602+
else \
603+
echo "$(GREEN)==>$(RESET) $(BOLD)lint/markdown$(RESET) (skipped - no docs files)"; \
604+
fi
544605
.PHONY: lint/markdown
545606

607+
# Comprehensive documentation check (--all to check all files, otherwise only changed files)
608+
lint/docs: lint/markdown
609+
@if [ "$(DOCS_MD_FILES)" -gt 0 ]; then \
610+
echo "$(GREEN)==>$(RESET) $(BOLD)lint/docs$(RESET)"; \
611+
echo "Checking for broken links in markdown files..."; \
612+
if command -v lychee >/dev/null 2>&1; then \
613+
if echo "$(MAKEFLAGS)" | grep -q "all"; then \
614+
echo "Checking all documentation files..."; \
615+
lychee --config .github/docs/.lycheeignore docs/**/*.md; \
616+
else \
617+
if [ -n "$(DOCS_CHANGED_FILES)" ]; then \
618+
echo "Checking changed files only: $(DOCS_CHANGED_FILES)"; \
619+
lychee --config .github/docs/.lycheeignore $(DOCS_CHANGED_FILES); \
620+
else \
621+
echo "No changed files detected, checking representative files..."; \
622+
lychee --config .github/docs/.lycheeignore docs/README.md docs/index.md; \
623+
fi; \
624+
fi; \
625+
else \
626+
echo "Lychee not found for link checking. Install with 'cargo install lychee' or see https://github.com/lycheeverse/lychee"; \
627+
fi; \
628+
echo ""; \
629+
echo "To run additional style checks, use: make lint/docs-style"; \
630+
echo "To check all files (not just changed ones), use: make lint/docs --all"; \
631+
else \
632+
echo "$(GREEN)==>$(RESET) $(BOLD)lint/docs$(RESET) (skipped - no docs files)"; \
633+
fi
634+
.PHONY: lint/docs
635+
546636
# All files generated by the database should be added here, and this can be used
547637
# as a target for jobs that need to run after the database is generated.
548638
DB_GEN_FILES := \

0 commit comments

Comments
 (0)