Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ permissions:
contents: read

jobs:
toc-update:
toc-verify:
runs-on: ubuntu-latest
name: Verify table of contents
steps:
Expand All @@ -32,3 +32,14 @@ jobs:
with:
go-version-file: scripts/go.mod
- run: make toc-update && git diff --exit-code

spelling-verify:
runs-on: ubuntu-latest
name: Verify spelling
steps:
- uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: scripts/go.mod
- run: make spelling-verify
30 changes: 24 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@ ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
TOOLS_BIN_DIR ?= $(ROOT_DIR)/tmp/bin
export PATH := $(TOOLS_BIN_DIR):$(PATH)
MDTOC_BINARY=$(TOOLS_BIN_DIR)/mdtoc
MISSPELL_BINARY=$(TOOLS_BIN_DIR)/misspell

.PHONY: help
help: ## Display this help.
@awk 'BEGIN { FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\n"} /^[a-zA-Z_0-9-]+:.*##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@awk 'BEGIN { FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\n"} /^[a-zA-Z0-9][a-zA-Z0-9_ -]*:.*##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: clean
clean: ## Remove all generated files and directories.
rm -rf $(TOOLS_BIN_DIR)

##@ Generating

.PHONY: toc-update update-toc
toc-update update-toc: $(MDTOC_BINARY) ## Update table of contents in markdown files.
.PHONY: toc-update
toc-update: $(MDTOC_BINARY) ## Update table of contents in markdown files.
@echo "Updating tables of contents..."
find $(ROOT_DIR) -name '*.md' \
-not -path "*/tmp/*" \
-not -name "MAINTAINERS.md" \
-not -name "PULL_REQUEST_TEMPLATE.md" \
| xargs $(MDTOC_BINARY) --inplace --max-depth=5

.PHONY: spelling-update
spelling-update: $(MISSPELL_BINARY) ## Fix spelling errors in markdown files.
@echo "Fixing spelling errors..."
find $(ROOT_DIR) -name '*.md' \
-not -path "*/tmp/*" \
| xargs $(MISSPELL_BINARY) -w

##@ Checking

.PHONY: toc-verify verify-toc
toc-verify verify-toc: $(MDTOC_BINARY) ## Verify table of contents are up to date.
.PHONY: toc-verify
toc-verify: $(MDTOC_BINARY) ## Verify table of contents are up to date.
@echo "Checking table of contents..."
find $(ROOT_DIR) -name '*.md' \
-not -path "*/tmp/*" \
Expand All @@ -39,6 +47,16 @@ toc-verify verify-toc: $(MDTOC_BINARY) ## Verify table of contents are up to dat
exit 1 \
)

.PHONY: spelling-verify
spelling-verify: $(MISSPELL_BINARY) ## Verify spelling in markdown files.
@echo "Checking spelling..."
find $(ROOT_DIR) -name '*.md' \
-not -path "*/tmp/*" \
| xargs $(MISSPELL_BINARY) -error || ( \
echo "Spelling errors found. Did you run 'make spelling-update'?"; \
exit 1 \
)

##@ Dependencies

.PHONY: tidy
Expand All @@ -51,6 +69,6 @@ tidy: ## Tidy Go module dependencies.
$(TOOLS_BIN_DIR):
mkdir -p $(TOOLS_BIN_DIR)

$(MDTOC_BINARY): $(TOOLS_BIN_DIR)
$(MDTOC_BINARY) $(MISSPELL_BINARY): $(TOOLS_BIN_DIR)
@echo "Installing tools from scripts/tools.go"
@cd $(ROOT_DIR)/scripts && GOBIN=$(TOOLS_BIN_DIR) go install -mod=readonly -modfile=go.mod $$(cat tools.go | grep _ | awk -F'"' '{print $$2}')
5 changes: 4 additions & 1 deletion scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/iflytek/community/scripts

go 1.26.1

require sigs.k8s.io/mdtoc v1.4.0
require (
github.com/client9/misspell v0.3.4
sigs.k8s.io/mdtoc v1.4.0
)

require (
github.com/BurntSushi/toml v0.3.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions scripts/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down
1 change: 1 addition & 0 deletions scripts/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
package tools

import (
_ "github.com/client9/misspell/cmd/misspell"
_ "sigs.k8s.io/mdtoc"
)
Loading