Skip to content

Commit 8dcabc3

Browse files
CharlieTLehanyuancheungdmathieupellaredMrAlias
authored
feat(ci): Add codespell to Makefile and GitHub Actions (#3996)
* feat(ci): Add codespell to Makefile and GitHub Actions This is a followup from #3980 to add the automation for checking for code spelling errors to a different PR. [Codespell][] makes use of the `.codespellrc` file automatically as a config file for convenience. The configuration file specifies directories and flags to pass to `codespell`. Codespell also makes use of the `.codespellignore` file to ignore certain word spellings. There is a new section in `Makefile` for installing python tooling. It is similar to how the go tools are installed. It sets up a virtualenv in `venv `and installs python tooling there if it hasn't been installed yet. The new [codespell workflow][] will run in pull requests to annotate misspelled words. It is set up to only warn the user with annotations in the pull request if there are typos, but we can fail the pull request as well if we want to by deleting the [warn_only][] key. [codespell]: https://github.com/codespell-project/codespell [codespell workflow]: https://github.com/codespell-project/actions-codespell [warn_only]: https://github.com/codespell-project/actions-codespell#parameter-only_warn * Use docker to run python and codespell Since this is a Go project, having a dependency on python seemed disconcerting. So, docker is used to create a virtual environment with a python image and also run the tools that were installed. * Remove wording on requirement for python * Apply suggestions from code review Co-authored-by: Damien Mathieu <[email protected]> * Pin versions into requirements.txt * Pin version in requirements.txt * Fix typo in license * Revert typo fix on deleted file * Update .github/workflows/codespell.yaml Co-authored-by: Robert Pająk <[email protected]> * Update codespell.yaml * Update codespell.yaml --------- Co-authored-by: Chester Cheung <[email protected]> Co-authored-by: Damien Mathieu <[email protected]> Co-authored-by: Robert Pająk <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent c3b48e2 commit 8dcabc3

File tree

8 files changed

+74
-1
lines changed

8 files changed

+74
-1
lines changed

.codespellignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ot
2+
fo
3+
te
4+
collison
5+
consequentially

.codespellrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# https://github.com/codespell-project/codespell
2+
[codespell]
3+
builtin = clear,rare,informal
4+
check-filenames =
5+
check-hidden =
6+
ignore-words = .codespellignore
7+
interactive = 1
8+
skip = .git,go.mod,go.sum,semconv,venv,.tools
9+
uri-ignore-words-list = *
10+
write =

.github/workflows/codespell.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: codespell
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
codespell:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout Repo
12+
uses: actions/checkout@v3
13+
- name: Codespell
14+
run: make codespell

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Thumbs.db
33

44
.tools/
5+
venv/
56
.idea/
67
.vscode/
78
*.iml

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ linters-settings:
113113
- name: constant-logical-expr
114114
disabled: false
115115
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument
116-
# TODO (#3372) reenable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280
116+
# TODO (#3372) re-enable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280
117117
- name: context-as-argument
118118
disabled: true
119119
arguments:

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ precommit` - the `precommit` target is the default).
2828
The `precommit` target also fixes the formatting of the code and
2929
checks the status of the go module files.
3030

31+
Additionally, there is a `codespell` target that checks for common
32+
typos in the code. It is not run by default, but you can run it
33+
manually with `make codespell`. It will set up a virtual environment
34+
in `venv` and install `codespell` there.
35+
3136
If after running `make precommit` the output of `git status` contains
3237
`nothing to commit, working tree clean` then it means that everything
3338
is up-to-date and properly formatted.

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,39 @@ $(TOOLS)/gojq: PACKAGE=github.com/itchyny/gojq/cmd/gojq
7474
.PHONY: tools
7575
tools: $(CROSSLINK) $(DBOTCONF) $(GOLANGCI_LINT) $(MISSPELL) $(GOCOVMERGE) $(STRINGER) $(PORTO) $(GOJQ) $(SEMCONVGEN) $(MULTIMOD) $(SEMCONVKIT)
7676

77+
# Virtualized python tools via docker
78+
79+
# The directory where the virtual environment is created.
80+
VENVDIR := venv
81+
82+
# The directory where the python tools are installed.
83+
PYTOOLS := $(VENVDIR)/bin
84+
85+
# The pip executable in the virtual environment.
86+
PIP := $(PYTOOLS)/pip
87+
88+
# The directory in the docker image where the current directory is mounted.
89+
WORKDIR := /workdir
90+
91+
# The python image to use for the virtual environment.
92+
PYTHONIMAGE := python:3.11.3-slim-bullseye
93+
94+
# Run the python image with the current directory mounted.
95+
DOCKERPY := docker run --rm -v "$(CURDIR):$(WORKDIR)" -w $(WORKDIR) $(PYTHONIMAGE)
96+
97+
# Create a virtual environment for Python tools.
98+
$(PYTOOLS):
99+
# The `--upgrade` flag is needed to ensure that the virtual environment is
100+
# created with the latest pip version.
101+
@$(DOCKERPY) bash -c "python3 -m venv $(VENVDIR) && $(PIP) install --upgrade pip"
102+
103+
# Install python packages into the virtual environment.
104+
$(PYTOOLS)/%: | $(PYTOOLS)
105+
@$(DOCKERPY) $(PIP) install -r requirements.txt
106+
107+
CODESPELL = $(PYTOOLS)/codespell
108+
$(CODESPELL): PACKAGE=codespell
109+
77110
# Generate
78111

79112
.PHONY: generate
@@ -180,6 +213,10 @@ vanity-import-fix: | $(PORTO)
180213
misspell: | $(MISSPELL)
181214
@$(MISSPELL) -w $(ALL_DOCS)
182215

216+
.PHONY: codespell
217+
codespell: | $(CODESPELL)
218+
@$(DOCKERPY) $(CODESPELL)
219+
183220
.PHONY: license-check
184221
license-check:
185222
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path '**/third_party/*' ! -path './.git/*' ) ; do \

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codespell==2.2.4

0 commit comments

Comments
 (0)