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 8, 2022
1 parent 27606e4 commit b7662a8
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .codespell.ignorewords
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
keypair
keypairs
11 changes: 11 additions & 0 deletions .codespell.skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git
*.png
*.woff
*.woff2
*.eot
*.ttf
*.jpg
*.ico
*.svg
go.mod
go.sum
17 changes: 16 additions & 1 deletion .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ 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 lint-yamllint
- name: Run Codespell
uses: codespell-project/actions-codespell@master
with:
skip: .git,*.png,*.woff,*.woff2,*.eot,*.ttf,*.jpg,*.ico,*.svg,go.mod,go.sum
ignore_words_file: './.codespell.ignorewords'
check_filenames: true
check_hidden: true
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
Expand All @@ -44,7 +59,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
33 changes: 33 additions & 0 deletions .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 .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
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,28 @@ test:

.PHONY: docker-build
docker-build: build-all ## Build the envoy-gateway docker image.
@DOCKER_BUILDKIT=1 docker build -t $(IMAGE):$(TAG) -f Dockerfile bin
@DOCKER_BUILDKIT=1 docker build -t $(IMAGE):$(TAG) -f Dockerfile bin

.PHONY: docker-push
docker-push: ## Push the docker image for envoy-gateway.
docker push $(IMAGE):$(TAG)

.PHONY: lint
lint: ## Run lint checks
lint: lint-golint lint-yamllint lint-codespell

.PHONY: lint-golint
lint-golint:
@echo Running Go linter ...
@./hack/golangci-lint.sh run --build-tags=e2e

.PHONY: lint-yamllint
lint-yamllint:
@echo Running YAML linter ...
## TODO(lianghao208): add other directories later
@./hack/yamllint.sh changelogs/

.PHONY: lint-codespell
lint-codespell: CODESPELL_SKIP := $(shell cat .codespell.skip | tr \\n ',')
lint-codespell:
@./hack/codespell.sh --skip $(CODESPELL_SKIP) --ignore-words .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
20 changes: 20 additions & 0 deletions hack/codespell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env bash

readonly PROGNAME="codespell"

if command -v ${PROGNAME} >/dev/null; then
exec ${PROGNAME} "$@"
fi

if command -v docker >/dev/null; then
exec docker run --rm -i \
-v $(pwd):/workdir \
lianghao208/codespell:v2.1.0 "$@"
fi

cat <<EOF
Unable to run codespell. Please check installation instructions:
https://github.com/codespell-project/codespell#installation
EOF

exit 69 # EX_UNAVAILABLE
22 changes: 22 additions & 0 deletions hack/golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env bash

readonly PROGNAME="golangci-lint"

if command -v ${PROGNAME} >/dev/null; then
exec ${PROGNAME} "$@"
fi

if command -v docker >/dev/null; then
exec docker run \
--rm \
--volume $(pwd):/app \
--workdir /app \
golangci/golangci-lint:v1.46.2 ${PROGNAME} "$@"
fi

cat <<EOF
Unable to run golang-ci. Please check installation instructions:
https://github.com/golangci/golangci-lint#install
EOF

exit 69 # EX_UNAVAILABLE
20 changes: 20 additions & 0 deletions hack/yamllint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env bash

readonly PROGNAME="yamllint"

if command -v ${PROGNAME} >/dev/null; then
exec ${PROGNAME} "$@"
fi

if command -v docker >/dev/null; then
exec docker run --rm -i \
-v $(pwd):/data \
giantswarm/yamllint:1.25 "$@"
fi

cat <<EOF
Unable to run yamllint. Please check installation instructions:
https://github.com/adrienverge/yamllint#installation
EOF

exit 69 # EX_UNAVAILABLE

0 comments on commit b7662a8

Please sign in to comment.