From dcfd476beb058d70e5f5352e9aa15002db982b5d Mon Sep 17 00:00:00 2001 From: lianghao208 Date: Sat, 28 May 2022 10:57:02 +0800 Subject: [PATCH] ci: add golangci-lint, yamlllint and codespell Signed-off-by: lianghao208 --- .github/workflows/build_and_test.yaml | 18 +++++++++- DEVELOPER.md | 8 +++-- Makefile | 12 +++---- Makefile.targets.mk | 19 ++++++++++ docs/design/SYSTEM_DESIGN.md | 4 +-- tools/Dockerfile.builder | 19 ++++++++-- tools/codespell/.codespell.ignorewords | 2 ++ tools/codespell/.codespell.skip | 12 +++++++ tools/golangci-lint/.golangci.yml | 33 +++++++++++++++++ tools/yamllint/.yamllint | 49 ++++++++++++++++++++++++++ 10 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 tools/codespell/.codespell.ignorewords create mode 100644 tools/codespell/.codespell.skip create mode 100644 tools/golangci-lint/.golangci.yml create mode 100644 tools/yamllint/.yamllint diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 60a8824db4..bf2be67beb 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -23,10 +23,26 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Run yamllint + run: | + MAKE_IN_DOCKER=1 make lint-yamllint + - name: Run Codespell + uses: codespell-project/actions-codespell@master + with: + # can't reuse tools/codespell/.codespell.skip, shell is not supported + skip: .git,*.png,*.woff,*.woff2,*.eot,*.ttf,*.jpg,*.ico,*.svg,go.mod,go.sum + ignore_words_file: 'tools/codespell/.codespell.ignorewords' + check_filenames: true + check_hidden: true - uses: actions/setup-go@v3 with: go-version: ${{ env.GO_VERSION }} cache: true + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.46.2 + args: --build-tags=e2e - name: Build run: make build-all - name: Test and report coverage @@ -44,7 +60,7 @@ jobs: uses: docker/build-push-action@v3 with: file: ./Dockerfile - context: bin + context: bin platforms: linux/amd64 tags: ${{ env.ENVOY_GATEWAY_DEV_IMAGE }}:${{ github.sha }} cache-from: type=gha diff --git a/DEVELOPER.md b/DEVELOPER.md index 1ce2ffbbc4..3e1abea303 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -15,15 +15,17 @@ build system. Our CI is based on [Github Actions](https://docs.github.com/en/act ### docker * Optional when you want to build a Docker image or run make inside Docker. -* Recommened Version: 20.10.16 +* Recommended Version: 20.10.16 * Installation Guide: https://docs.docker.com/engine/install/ ### linters -* [TODO](https://github.com/envoyproxy/gateway/issues/73) - +* If you already have tools: `golangci-lint, yamllint and codespell` installed on your machine, you can run `make ` +directly on your machine. * If you do not have these tools installed on your machine, you can alternatively run `MAKE_IN_DOCKER=1 make ` to run `make` inside a Docker container which has all the preinstalled tools needed to support all the `make` targets. +* Installation Guide: [golangci-lint](https://github.com/golangci/golangci-lint#install), [yamllint](https://github.com/adrienverge/yamllint#installation), +[codespell](https://github.com/codespell-project/codespell#installation) ## Quick start diff --git a/Makefile b/Makefile index 1e23087f5e..0c665eee93 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -# This is a wrapper around `make` so it can run +# This is a wrapper around `make` so it can run # directly on the host or inside a container # -# All make targets must be defined in Makefile.targets.mk +# All make targets must be defined in Makefile.targets.mk -# Set MAKE_IN_DOCKER=1 as an envioronment variable to run `make` inside +# Set MAKE_IN_DOCKER=1 as an environment variable to run `make` inside # a Docker container with preinstalled tools. DOCKER_BUILDER_IMAGE ?= envoyproxy/gateway-dev-builder @@ -11,9 +11,9 @@ DOCKER_BUILDER_TAG ?= latest DOCKER_BUILD_CMD ?= DOCKER_BUILDKIT=1 docker build DOCKER_RUN_CMD ?= docker run \ --rm \ - -it \ + -t \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v ${PWD}:/workspace + -v ${PWD}:/workspace %: ifeq ($(MAKE_IN_DOCKER), 1) @@ -23,6 +23,6 @@ ifeq ($(MAKE_IN_DOCKER), 1) # Run with MAKE_IN_DOCKER=0 to eliminate an infinite loop @$(DOCKER_RUN_CMD) $(DOCKER_BUILDER_IMAGE):$(DOCKER_BUILDER_TAG) MAKE_IN_DOCKER=0 $@ else -# Run make locally +# Run make locally @$(MAKE) -f Makefile.targets.mk $@ endif diff --git a/Makefile.targets.mk b/Makefile.targets.mk index 42319cfc58..0139780450 100644 --- a/Makefile.targets.mk +++ b/Makefile.targets.mk @@ -43,3 +43,22 @@ help: ## Display this help @echo Targets: @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9._-]+:.*?## / {printf " %-25s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort +.PHONY: lint +lint: ## Run lint checks +lint: lint-golint lint-yamllint lint-codespell + +.PHONY: lint-golint +lint-golint: + @echo Running Go linter ... + @golangci-lint run --build-tags=e2e --config=tools/golangci-lint/.golangci.yml + +.PHONY: lint-yamllint +lint-yamllint: + @echo Running YAML linter ... + ## TODO(lianghao208): add other directories later + @yamllint --config-file=tools/yamllint/.yamllint changelogs/ + +.PHONY: lint-codespell +lint-codespell: CODESPELL_SKIP := $(shell cat tools/codespell/.codespell.skip | tr \\n ',') +lint-codespell: + @codespell --skip $(CODESPELL_SKIP) --ignore-words tools/codespell/.codespell.ignorewords --check-filenames --check-hidden -q2 diff --git a/docs/design/SYSTEM_DESIGN.md b/docs/design/SYSTEM_DESIGN.md index a52cbe7a3f..4b3c7e565e 100644 --- a/docs/design/SYSTEM_DESIGN.md +++ b/docs/design/SYSTEM_DESIGN.md @@ -14,7 +14,7 @@ #### Bootstrap Config This is the configuration provided by the Infrastructure Administrator that allows them to bootstrap and configure various internal aspects of Envoy Gateway. It can be defined using a CLI argument similar to what [Envoy Proxy has](https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-c). -For e.g. users wanting to run Envoy Gateway in Kubernetes and use a custom [Envoy Proxy bootstrap config](https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-msg-config-bootstrap-v3-bootstrap) could define their Boostrap Config as - +For e.g. users wanting to run Envoy Gateway in Kubernetes and use a custom [Envoy Proxy bootstrap config](https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-msg-config-bootstrap-v3-bootstrap) could define their Bootstrap Config as - ``` platform: kubernetes envoyProxy: @@ -85,7 +85,7 @@ This component is a xDS gRPC Server based on the [Envoy Go Control Plane](https: and is responsible for configuring xDS resources in Envoy Proxy. #### Provisioner -The provisioner configures any infrastruture needed based on the IR. +The provisioner configures any infrastructure needed based on the IR. * Envoy - This is a platform specific component that provisions all the infrastructure required to run the managed Envoy Proxy fleet. For example, a Terraform or Ansible provisioner could be added in the future to provision the Envoy infrastructure in a non-Kubernetes environment. diff --git a/tools/Dockerfile.builder b/tools/Dockerfile.builder index d58801f89e..853140e3ad 100644 --- a/tools/Dockerfile.builder +++ b/tools/Dockerfile.builder @@ -4,8 +4,23 @@ # go FROM golang:1.18.2 as builder + +ENV YAMLLINT_VERSION=1.24.2 +ENV GOLINT_VERSION=v1.46.2 +ENV CODESPELL_VERSION=v2.1.0 + # docker CLI -RUN curl -fsSL https://get.docker.com | VERSION=20.10.16 sh +RUN curl -fsSL https://get.docker.com | VERSION=20.10.16 sh + +# python +RUN apt-get update && apt-get install -y --no-install-recommends python3-pip + +# golangci Lint +Run curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s ${GOLINT_VERSION} + +# pip install +RUN python3 -m pip install --no-cache-dir yamllint==${YAMLLINT_VERSION} +RUN python3 -m pip install --no-cache-dir codespell==${CODESPELL_VERSION} WORKDIR /workspace -ENTRYPOINT ["make"] +ENTRYPOINT ["make"] \ No newline at end of file diff --git a/tools/codespell/.codespell.ignorewords b/tools/codespell/.codespell.ignorewords new file mode 100644 index 0000000000..5363794a87 --- /dev/null +++ b/tools/codespell/.codespell.ignorewords @@ -0,0 +1,2 @@ +keypair +keypairs \ No newline at end of file diff --git a/tools/codespell/.codespell.skip b/tools/codespell/.codespell.skip new file mode 100644 index 0000000000..12f7525da8 --- /dev/null +++ b/tools/codespell/.codespell.skip @@ -0,0 +1,12 @@ +.git +.idea +*.png +*.woff +*.woff2 +*.eot +*.ttf +*.jpg +*.ico +*.svg +go.mod +go.sum \ No newline at end of file diff --git a/tools/golangci-lint/.golangci.yml b/tools/golangci-lint/.golangci.yml new file mode 100644 index 0000000000..c0bc456a2f --- /dev/null +++ b/tools/golangci-lint/.golangci.yml @@ -0,0 +1,33 @@ +run: + deadline: 10m + +linters: + enable: + - bodyclose + - gofmt + - goimports + - revive + - gosec + - misspell + - unconvert + - unparam + - goheader + - gocritic + +linters-settings: + gofmt: + simplify: true + unparam: + check-exported: false + +issues: + exclude-rules: + - path: zz_generated + linters: + - goimports + - linters: + - staticcheck + text: "SA1019:" + - path: test/e2e + linters: + - bodyclose diff --git a/tools/yamllint/.yamllint b/tools/yamllint/.yamllint new file mode 100644 index 0000000000..16d16bd3b9 --- /dev/null +++ b/tools/yamllint/.yamllint @@ -0,0 +1,49 @@ +--- + +rules: + braces: + min-spaces-inside: 0 + max-spaces-inside: 0 + min-spaces-inside-empty: -1 + max-spaces-inside-empty: -1 + brackets: + min-spaces-inside: 0 + max-spaces-inside: 1 + min-spaces-inside-empty: -1 + max-spaces-inside-empty: -1 + colons: + max-spaces-before: 0 + max-spaces-after: 1 + commas: + max-spaces-before: 1 + min-spaces-after: 1 + max-spaces-after: 1 + comments: + level: warning + require-starting-space: true + min-spaces-from-content: 2 + comments-indentation: + level: warning + document-end: disable + document-start: disable + empty-lines: + max: 2 + max-start: 0 + max-end: 1 + empty-values: + forbid-in-block-mappings: false + forbid-in-flow-mappings: true + hyphens: + max-spaces-after: 1 + indentation: + spaces: 2 + indent-sequences: whatever + check-multi-line-strings: false + key-duplicates: enable + key-ordering: disable + new-line-at-end-of-file: enable + new-lines: + type: unix + trailing-spaces: disable + truthy: + level: warning \ No newline at end of file