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 May 28, 2022
1 parent f08f90b commit fe354ec
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 0 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
27 changes: 27 additions & 0 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,34 @@ on:
env:
GO_VERSION: 1.18.2
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.45.0
args: --build-tags=e2e
- name: yamllint
run: |
make lint-yamllint
codespell:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- name: 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
build:
needs:
- lint
- codespell
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
34 changes: 34 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
run:
deadline: 10m

linters:
enable:
- bodyclose
- gofmt
- goimports
- revive
- gosec
- misspell
- unconvert
- unparam
- goheader
- gocritic

# TODO(lianghao208): enable misspell
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
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,22 @@ build:
test:
@go test ./...

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

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

.PHONY: lint-yamllint
lint-yamllint:
@echo Running YAML linter ...
## TODO(lianghao208): add other directories later
@./hack/yamllint 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
14 changes: 14 additions & 0 deletions hack/codespell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /usr/bin/env bash

readonly PROGNAME="codespell"

if command -v ${PROGNAME} >/dev/null; then
exec ${PROGNAME} "$@"
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
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.45.0 ${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
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):/workdir \
giantswarm/yamllint "$@"
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 fe354ec

Please sign in to comment.