Skip to content

Commit ea510ae

Browse files
authored
CI: Add misspell spelling checker tool and CI verification
CI: Add misspell spelling checker tool and CI verification
2 parents de5e439 + 7840b0c commit ea510ae

5 files changed

Lines changed: 43 additions & 8 deletions

File tree

.github/workflows/check.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ permissions:
2222
contents: read
2323

2424
jobs:
25-
toc-update:
25+
toc-verify:
2626
runs-on: ubuntu-latest
2727
name: Verify table of contents
2828
steps:
@@ -32,3 +32,14 @@ jobs:
3232
with:
3333
go-version-file: scripts/go.mod
3434
- run: make toc-update && git diff --exit-code
35+
36+
spelling-verify:
37+
runs-on: ubuntu-latest
38+
name: Verify spelling
39+
steps:
40+
- uses: actions/checkout@v6
41+
- name: Set up Go
42+
uses: actions/setup-go@v6
43+
with:
44+
go-version-file: scripts/go.mod
45+
- run: make spelling-verify

Makefile

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,38 @@ ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
55
TOOLS_BIN_DIR ?= $(ROOT_DIR)/tmp/bin
66
export PATH := $(TOOLS_BIN_DIR):$(PATH)
77
MDTOC_BINARY=$(TOOLS_BIN_DIR)/mdtoc
8+
MISSPELL_BINARY=$(TOOLS_BIN_DIR)/misspell
89

910
.PHONY: help
1011
help: ## Display this help.
11-
@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)
12+
@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)
1213

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

1718
##@ Generating
1819

19-
.PHONY: toc-update update-toc
20-
toc-update update-toc: $(MDTOC_BINARY) ## Update table of contents in markdown files.
20+
.PHONY: toc-update
21+
toc-update: $(MDTOC_BINARY) ## Update table of contents in markdown files.
2122
@echo "Updating tables of contents..."
2223
find $(ROOT_DIR) -name '*.md' \
2324
-not -path "*/tmp/*" \
2425
-not -name "MAINTAINERS.md" \
2526
-not -name "PULL_REQUEST_TEMPLATE.md" \
2627
| xargs $(MDTOC_BINARY) --inplace --max-depth=5
2728

29+
.PHONY: spelling-update
30+
spelling-update: $(MISSPELL_BINARY) ## Fix spelling errors in markdown files.
31+
@echo "Fixing spelling errors..."
32+
find $(ROOT_DIR) -name '*.md' \
33+
-not -path "*/tmp/*" \
34+
| xargs $(MISSPELL_BINARY) -w
35+
2836
##@ Checking
2937

30-
.PHONY: toc-verify verify-toc
31-
toc-verify verify-toc: $(MDTOC_BINARY) ## Verify table of contents are up to date.
38+
.PHONY: toc-verify
39+
toc-verify: $(MDTOC_BINARY) ## Verify table of contents are up to date.
3240
@echo "Checking table of contents..."
3341
find $(ROOT_DIR) -name '*.md' \
3442
-not -path "*/tmp/*" \
@@ -39,6 +47,16 @@ toc-verify verify-toc: $(MDTOC_BINARY) ## Verify table of contents are up to dat
3947
exit 1 \
4048
)
4149

50+
.PHONY: spelling-verify
51+
spelling-verify: $(MISSPELL_BINARY) ## Verify spelling in markdown files.
52+
@echo "Checking spelling..."
53+
find $(ROOT_DIR) -name '*.md' \
54+
-not -path "*/tmp/*" \
55+
| xargs $(MISSPELL_BINARY) -error || ( \
56+
echo "Spelling errors found. Did you run 'make spelling-update'?"; \
57+
exit 1 \
58+
)
59+
4260
##@ Dependencies
4361

4462
.PHONY: tidy
@@ -51,6 +69,6 @@ tidy: ## Tidy Go module dependencies.
5169
$(TOOLS_BIN_DIR):
5270
mkdir -p $(TOOLS_BIN_DIR)
5371

54-
$(MDTOC_BINARY): $(TOOLS_BIN_DIR)
72+
$(MDTOC_BINARY) $(MISSPELL_BINARY): $(TOOLS_BIN_DIR)
5573
@echo "Installing tools from scripts/tools.go"
5674
@cd $(ROOT_DIR)/scripts && GOBIN=$(TOOLS_BIN_DIR) go install -mod=readonly -modfile=go.mod $$(cat tools.go | grep _ | awk -F'"' '{print $$2}')

scripts/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ module github.com/iflytek/community/scripts
22

33
go 1.26.1
44

5-
require sigs.k8s.io/mdtoc v1.4.0
5+
require (
6+
github.com/client9/misspell v0.3.4
7+
sigs.k8s.io/mdtoc v1.4.0
8+
)
69

710
require (
811
github.com/BurntSushi/toml v0.3.1 // indirect

scripts/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
4+
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
35
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
46
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
57
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=

scripts/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
package tools
2020

2121
import (
22+
_ "github.com/client9/misspell/cmd/misspell"
2223
_ "sigs.k8s.io/mdtoc"
2324
)

0 commit comments

Comments
 (0)