Skip to content

Commit

Permalink
ci: add golangci-lint, yamlllint and codespell
Browse files Browse the repository at this point in the history
Signed-off-by: lianghao208 <roylizard3@gmail.com>
  • Loading branch information
lianghao208 committed Jun 14, 2022
1 parent 08b8eac commit 74c2000
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 13 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.46.2
args: --build-tags=e2e
- 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 }}
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <target>`
directly on your machine.
* If you do not have these tools installed on your machine,
you can alternatively run `MAKE_IN_DOCKER=1 make <target>` 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

Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,7 +13,7 @@ DOCKER_RUN_CMD ?= docker run \
--rm \
-it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ${PWD}:/workspace
-v ${PWD}:/workspace

%:
ifeq ($(MAKE_IN_DOCKER), 1)
Expand All @@ -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
19 changes: 19 additions & 0 deletions Makefile.targets.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions docs/design/SYSTEM_DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 17 additions & 2 deletions tools/Dockerfile.builder
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions tools/codespell/.codespell.ignorewords
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
keypair
keypairs
12 changes: 12 additions & 0 deletions tools/codespell/.codespell.skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git
.idea
*.png
*.woff
*.woff2
*.eot
*.ttf
*.jpg
*.ico
*.svg
go.mod
go.sum
33 changes: 33 additions & 0 deletions tools/golangci-lint/.golangci.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions tools/yamllint/.yamllint
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 74c2000

Please sign in to comment.