Skip to content

Commit da69afc

Browse files
committed
Some makefile improvements. Updated golangci-lint to v2.
1 parent d90befd commit da69afc

File tree

3 files changed

+131
-101
lines changed

3 files changed

+131
-101
lines changed

.golangci.yml

Lines changed: 72 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,79 @@
1+
version: "2"
12
linters:
2-
disable-all: true
3+
default: none
34
enable:
4-
- govet
5-
- unused
6-
- staticcheck
7-
- revive
85
- errcheck
6+
- gosec
7+
- govet
98
- ineffassign
109
- misspell
1110
- nlreturn
12-
- gosec
13-
14-
run:
15-
timeout: 5m
16-
17-
issues:
18-
exclude-rules:
19-
- path: _test\.go
20-
linters:
21-
- funlen
22-
- bodyclose
23-
- gosec
24-
- revive
25-
- path: example/
26-
text: "avoid magic numbers"
27-
28-
linters-settings:
29-
govet:
30-
disable:
31-
- fieldalignment
32-
revive:
33-
enable-all-rules: true
11+
- revive
12+
- staticcheck
13+
- unused
14+
settings:
15+
govet:
16+
disable:
17+
- fieldalignment
18+
revive:
19+
enable-all-rules: true
20+
rules:
21+
- name: cognitive-complexity
22+
disabled: true
23+
- name: line-length-limit
24+
arguments:
25+
- 120
26+
- name: function-length
27+
arguments:
28+
- 50
29+
- 0
30+
- name: argument-limit
31+
disabled: true
32+
- name: banned-characters
33+
disabled: true
34+
- name: cyclomatic
35+
arguments:
36+
- 15
37+
- name: function-result-limit
38+
arguments:
39+
- 3
40+
- name: max-public-structs
41+
arguments:
42+
- 3
43+
- name: file-header
44+
disabled: true
45+
- name: add-constant
46+
arguments:
47+
- allowInts: 0,1,2
48+
allowStrs: '""'
49+
- name: unhandled-error
50+
arguments:
51+
- fmt.Printf
52+
- fmt.Println
53+
exclusions:
54+
generated: lax
55+
presets:
56+
- comments
57+
- common-false-positives
58+
- legacy
59+
- std-error-handling
3460
rules:
35-
- name: cognitive-complexity
36-
disabled: true
37-
- name: line-length-limit
38-
arguments: [120]
39-
- name: function-length
40-
arguments: [50, 0]
41-
- name: argument-limit
42-
disabled: true
43-
- name: banned-characters
44-
disabled: true
45-
- name: cyclomatic
46-
arguments: [15]
47-
- name: function-result-limit
48-
arguments: [3]
49-
- name: max-public-structs
50-
arguments: [3]
51-
- name: file-header
52-
disabled: true
53-
- name: add-constant
54-
arguments:
55-
- allowStrs: '""'
56-
allowInts: "0,1,2"
57-
- name: unhandled-error
58-
arguments:
59-
- "fmt.Printf"
60-
- "fmt.Println"
61+
- linters:
62+
- bodyclose
63+
- funlen
64+
- gosec
65+
- revive
66+
path: _test\.go
67+
- path: example/
68+
text: avoid magic numbers
69+
paths:
70+
- third_party$
71+
- builtin$
72+
- examples$
73+
formatters:
74+
exclusions:
75+
generated: lax
76+
paths:
77+
- third_party$
78+
- builtin$
79+
- examples$

Makefile

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,77 @@
1-
.PHONY: all
1+
.PHONY: all help
2+
.DEFAULT_GOAL := help
23

3-
GOLANG_CI_LINT_VERSION=1.64.5
4+
# COLORS
5+
YELLOW = \033[33m
6+
GREEN = \033[32m
7+
WHITE = \033[37m
8+
RESET = \033[0m
9+
10+
GOLANG_CI_LINT_VERSION=2.2.2
411
GO_BIN=$(shell pwd)/.build
512
export
613

714
all: test lint
815

9-
build:
10-
@echo "Building AWS RDS Store"
11-
cd store/awsrds && $(MAKE) build
12-
@echo "Building Vault store"
13-
cd store/vault && $(MAKE) build
14-
@echo "Building main module"
15-
go build ./...
16+
build: ## Build library and sample stores
17+
@printf "$(GREEN)Building AWS RDS Store$(RESET)\n"
18+
@cd store/awsrds && $(MAKE) -s build
19+
@printf "$(GREEN)Building Vault store$(RESET)\n"
20+
@cd store/vault && $(MAKE) -s build
21+
@printf "$(GREEN)Building main module$(RESET)\n"
22+
@go build ./...
1623

17-
test:
18-
@echo "Testing AWS RDS store"
19-
cd store/awsrds && $(MAKE) test
20-
@echo "Testing Vault store"
21-
cd store/vault && $(MAKE) test
22-
@echo "Testing main module"
23-
go test github.com/davepgreene/go-db-credential-refresh/driver -count=1 -coverprofile=cover.out
24+
test: ## Test everything
25+
@printf "$(GREEN)Testing AWS RDS store$(RESET)\n"
26+
@cd store/awsrds && $(MAKE) -s test
27+
@printf "\n$(GREEN)Testing Vault store$(RESET)\n"
28+
@cd store/vault && $(MAKE) -s test
29+
@printf "\n$(GREEN)Testing main module$(RESET)\n"
30+
@go test github.com/davepgreene/go-db-credential-refresh/driver -count=1 -coverprofile=cover.out
2431

25-
lint: lint-setup
26-
@echo "Linting AWS RDS store"
27-
cd store/awsrds && $(MAKE) lint
28-
@echo "Linting Vault store"
29-
cd store/vault && $(MAKE) lint
30-
@echo "Linting main module"
31-
"$(GO_BIN)/golangci-lint" run ./...
32+
lint: lint-setup ## Lint everything
33+
@printf "$(GREEN)Linting AWS RDS store$(RESET)\n"
34+
@cd store/awsrds && $(MAKE) -s lint
35+
@printf "\n$(GREEN)Linting Vault store$(RESET)\n"
36+
@cd store/vault && $(MAKE) -s lint
37+
@printf "\n$(GREEN)Linting main module$(RESET)\n"
38+
@"$(GO_BIN)/golangci-lint" run ./...
3239

33-
bench:
34-
@echo "Benching AWS RDS store"
35-
cd store/awsrds && $(MAKE) bench
36-
@echo "Benching Vault store"
37-
cd store/vault && $(MAKE) bench
38-
@echo "Benching main module"
39-
go test ./... -bench -count=1 -coverprofile=cover.out
40+
bench: ## Go test with benchmarks
41+
@printf "$(GREEN)Benching AWS RDS store$(RESET)\n"
42+
@cd store/awsrds && $(MAKE) -s bench
43+
@printf "\n$(GREEN)Benching Vault store$(RESET)\n"
44+
@cd store/vault && $(MAKE) -s bench
45+
@printf "\n$(GREEN)Benching main module$(RESET)\n"
46+
@go test ./... -bench -count=1 -coverprofile=cover.out
4047

41-
cover: test
42-
mkdir -p "$(GO_BIN)/coverage"
48+
cover: test ## Go test with coverage
49+
@mkdir -p "$(GO_BIN)/coverage"
4350
@echo "Generating coverage for AWS RDS store"
44-
cd store/awsrds && $(MAKE) cover
51+
@cd store/awsrds && $(MAKE) -s cover
4552
@echo "Generating coverage for Vault store"
46-
cd store/vault && $(MAKE) cover
53+
@cd store/vault && $(MAKE) -s cover
4754
@echo "Generating coverage for main module"
48-
go tool cover -html=cover.out -o "$(GO_BIN)/coverage/main.html"
55+
@go tool cover -html=cover.out -o "$(GO_BIN)/coverage/main.html"
4956

5057
lint-setup: _bin
5158
@# Make sure linter is up to date
52-
$(eval CURRENT_VERSION := $(strip $(shell $(GO_BIN)/bin/golangci-lint version 2>&1 | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')))
59+
$(eval CURRENT_VERSION := $(strip $(shell $(GO_BIN)/golangci-lint version 2>&1 | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')))
5360
@if [ "$(CURRENT_VERSION)" != "$(GOLANG_CI_LINT_VERSION)" ]; then \
61+
echo "Updating golangci-lint from $(CURRENT_VERSION) to version $(GOLANG_CI_LINT_VERSION)"; \
5462
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(GO_BIN)" "v$(GOLANG_CI_LINT_VERSION)" ; \
5563
fi
5664

5765
_bin:
58-
mkdir -p "$(GO_BIN)"
66+
@mkdir -p "$(GO_BIN)"
67+
68+
format: ## Gofmt
69+
@gofmt -w -e .
5970

60-
format:
61-
gofmt -w -e .
71+
tidy: ## Tidy up go modules
72+
@go mod tidy
73+
@cd store/awsrds && go mod tidy
74+
@cd store/vault && go mod tidy
6275

63-
tidy:
64-
go mod tidy
65-
cd store/awsrds && go mod tidy
66-
cd store/vault && go mod tidy
76+
help:
77+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

tools/tools.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ else
1515
endif
1616

1717
build-default:
18-
go build ./...
18+
@go build ./...
1919

2020
test-default:
21-
go test ./... -count=1 -coverprofile=cover.out
21+
@go test ./... -count=1 -coverprofile=cover.out
2222

2323
bench-default:
24-
go test ./... -bench -count=1 -coverprofile=cover.out
24+
@go test ./... -bench -count=1 -coverprofile=cover.out
2525

2626
cover-default: test-default
27-
go tool cover -html=cover.out -o "$(GO_BIN)/coverage/$(MODULE).html"
27+
@go tool cover -html=cover.out -o "$(GO_BIN)/coverage/$(MODULE).html"
2828

2929
lint-default:
30-
"$(GO_BIN)/golangci-lint" run ./...
30+
@"$(GO_BIN)/golangci-lint" run ./...
3131

3232
%: %-default
3333
@ true

0 commit comments

Comments
 (0)