From fe354ec76ea8eb600613e64304db61589ae20fa8 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 --- .codespell.ignorewords | 2 ++ .codespell.skip | 11 ++++++ .github/workflows/build_and_test.yaml | 27 +++++++++++++++ .golangci.yml | 34 +++++++++++++++++++ .yamllint | 49 +++++++++++++++++++++++++++ Makefile | 19 +++++++++++ hack/codespell.sh | 14 ++++++++ hack/golangci-lint | 22 ++++++++++++ hack/yamllint | 20 +++++++++++ 9 files changed, 198 insertions(+) create mode 100644 .codespell.ignorewords create mode 100644 .codespell.skip create mode 100644 .golangci.yml create mode 100644 .yamllint create mode 100755 hack/codespell.sh create mode 100755 hack/golangci-lint create mode 100755 hack/yamllint diff --git a/.codespell.ignorewords b/.codespell.ignorewords new file mode 100644 index 000000000000..5363794a87ff --- /dev/null +++ b/.codespell.ignorewords @@ -0,0 +1,2 @@ +keypair +keypairs \ No newline at end of file diff --git a/.codespell.skip b/.codespell.skip new file mode 100644 index 000000000000..6c72d962ef2c --- /dev/null +++ b/.codespell.skip @@ -0,0 +1,11 @@ +.git +*.png +*.woff +*.woff2 +*.eot +*.ttf +*.jpg +*.ico +*.svg +go.mod +go.sum \ No newline at end of file diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 3af00cd4d7b7..f7f462fd7d31 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -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 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000000..032135136016 --- /dev/null +++ b/.golangci.yml @@ -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 diff --git a/.yamllint b/.yamllint new file mode 100644 index 000000000000..16d16bd3b999 --- /dev/null +++ b/.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 diff --git a/Makefile b/Makefile index aa7019df359b..a15ab91a4dd5 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/hack/codespell.sh b/hack/codespell.sh new file mode 100755 index 000000000000..5ef775275e0a --- /dev/null +++ b/hack/codespell.sh @@ -0,0 +1,14 @@ +#! /usr/bin/env bash + +readonly PROGNAME="codespell" + +if command -v ${PROGNAME} >/dev/null; then + exec ${PROGNAME} "$@" +fi + +cat </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 </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 <