Skip to content

Commit 892052b

Browse files
committed
BUILD/MEDIUM: update linters, use local version
1 parent 213c160 commit 892052b

File tree

6 files changed

+77
-13
lines changed

6 files changed

+77
-13
lines changed

.github/workflows/actions.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,39 @@ jobs:
5151
run: go mod tidy
5252
- name: changes
5353
run: test -z "$(git diff 2> /dev/null)" || exit "Go modules not tidied, issue \`go mod tidy\` and commit the result"
54+
gofumpt:
55+
name: gofumpt
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Check out code
59+
uses: actions/checkout@v2
60+
- name: Set up Go
61+
uses: actions/setup-go@v2
62+
with:
63+
go-version: 1.19
64+
- uses: actions/cache@v2
65+
with:
66+
path: |
67+
~/.cache/go-build
68+
~/go/pkg/mod
69+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
70+
restore-keys: |
71+
${{ runner.os }}-go-
72+
- name: tidy
73+
run: make gofumpt
74+
- name: changes
75+
run: test -z "$(git diff 2> /dev/null)" || exit "Go code not formatted, issue \`make gofumpt\` and commit the result"
5476
lint:
5577
name: golangci-lint
5678
needs: ["generate", "tidy"]
5779
runs-on: ubuntu-latest
5880
steps:
5981
- name: Check out code into the Go module directory
6082
uses: actions/checkout@v2
83+
- name: Set up Go
84+
uses: actions/setup-go@v2
85+
with:
86+
go-version: 1.19
6187
- uses: actions/cache@v2
6288
with:
6389
path: |
@@ -66,10 +92,9 @@ jobs:
6692
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
6793
restore-keys: |
6894
${{ runner.os }}-go-
69-
- name: golangci-lint
70-
uses: docker://ghcr.io/haproxytech/go-linter:1.50.0
71-
with:
72-
args: --timeout 5m
95+
- name: Lint
96+
run: |
97+
make lint
7398
build:
7499
name: build
75100
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
kubernetes-ingress
44
dist/
55
.code-generator/
6+
bin/golangci-lint

.gitlab-ci.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,33 @@ tidy:
4545
script:
4646
- go mod tidy
4747
- test -z "$(git diff 2> /dev/null)" || exit 'Go modules not tidied, issue \`go mod tidy\` and commit the result'
48+
gofumpt:
49+
stage: lint
50+
needs: []
51+
rules:
52+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
53+
- if: $CI_PIPELINE_SOURCE == 'push'
54+
image:
55+
name: $CI_REGISTRY_GO/golang:1.19
56+
entrypoint: [""]
57+
tags:
58+
- go
59+
script:
60+
- make gofumpt
61+
- test -z "$(git diff 2> /dev/null)" || exit 'Go code not formatted, issue \`make gofumpt\` and commit the result'
4862
golangci_lint:
4963
stage: lint
5064
needs: []
5165
rules:
5266
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
5367
- if: $CI_PIPELINE_SOURCE == 'push'
5468
image:
55-
name: $CI_REGISTRY_GO/lint:1.50.0
69+
name: $CI_REGISTRY_GO/golang:1.19
5670
entrypoint: [""]
5771
tags:
5872
- go
5973
script:
60-
- golangci-lint run --enable-all --timeout=10m
74+
- make lint
6175
lint-commit-msg:
6276
stage: lint
6377
needs: []
@@ -192,7 +206,6 @@ docker-build-sch:
192206
parallel:
193207
matrix:
194208
- TEST_PART: [ "18#e2e_parallel", "18#e2e_https", "1#e2e_sequential" ]
195-
VAR_DUMMY: "YES"
196209
script:
197210
- CI_ENV=gitlab deploy/tests/create.sh
198211
- kubectl get pods -A

.golangci.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ linters-settings:
1414
- name: var-naming
1515
severity: warning
1616
disabled: true
17-
1817
linters:
1918
enable-all: true
2019
disable:
@@ -29,7 +28,6 @@ linters:
2928
- gocyclo
3029
- godot
3130
- goerr113
32-
- gofumpt
3331
- gomnd
3432
- lll
3533
- nestif
@@ -39,9 +37,19 @@ linters:
3937
- nakedret
4038
- paralleltest
4139
- testpackage
42-
- nonamedreturns
43-
- nosnakecase
4440
- varnamelen
45-
- staticcheck
41+
- nosnakecase
4642
- exhaustruct
43+
- nonamedreturns
4744
- forcetypeassert
45+
- golint #deprecated
46+
- varcheck #deprecated
47+
- ifshort #deprecated
48+
- structcheck #deprecated
49+
- maligned #deprecated
50+
- scopelint #deprecated
51+
- interfacer #deprecated
52+
- deadcode #deprecated
53+
- rowserrcheck #rowserrcheck is disabled because of generics
54+
- sqlclosecheck #rowserrcheck is disabled because of generics
55+
- wastedassign #rowserrcheck is disabled because of generics

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PROJECT_PATH=${PWD}
22
TARGETPLATFORM?=linux/amd64
3+
GOLANGCI_LINT_VERSION=1.50.1
34

45
.PHONY: test
56
test:
@@ -21,8 +22,12 @@ doc:
2122

2223
.PHONY: lint
2324
lint:
25+
cd bin;GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} sh lint-check.sh
26+
bin/golangci-lint run --timeout 5m --color always --max-issues-per-linter 0 --max-same-issues 0
27+
28+
.PHONY: yaml-lint
29+
yaml-lint:
2430
docker run --rm -v $(pwd):/data cytopia/yamllint .
25-
docker run --rm -v ${PROJECT_PATH}:/app -w /app ghcr.io/haproxytech/go-linter:1.50.0 -v --timeout 5m --color always --max-issues-per-linter 0 --max-same-issues 0
2631

2732
.PHONY: example
2833
example:
@@ -49,3 +54,8 @@ cr_generate:
4954
crs/code-generator.sh
5055
grep -lir defaultses crs/* | xargs sed -i 's/Defaultses/Defaults/g'
5156
grep -lir defaultses crs/* | xargs sed -i 's/defaultses/defaults/g'
57+
58+
.PHONY: gofumpt
59+
gofumpt:
60+
go install mvdan.cc/gofumpt@latest
61+
gofumpt -l -w .

bin/lint-check.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
V=$(./golangci-lint --version)
3+
4+
case "$V" in
5+
*$GOLANGCI_LINT_VERSION*) echo "$V" ;;
6+
*) curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(pwd) "v$GOLANGCI_LINT_VERSION" ;;
7+
esac

0 commit comments

Comments
 (0)