Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add golangci-lint, yamlllint and codespell #79

Merged
merged 1 commit into from
Jun 15, 2022
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
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,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
arkodg marked this conversation as resolved.
Show resolved Hide resolved
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
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
lianghao208 marked this conversation as resolved.
Show resolved Hide resolved
* [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
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# 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
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
arkodg marked this conversation as resolved.
Show resolved Hide resolved

%:
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:
lianghao208 marked this conversation as resolved.
Show resolved Hide resolved
@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