forked from chef/automate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.common_go
66 lines (51 loc) · 2.47 KB
/
Makefile.common_go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Note: this looks weird -- it's because this Makefile is to be included from
# components/xyz-service/Makefile
REPOROOT?=../..
# Convert, e.g., "src/github.com/chef/automate/components/teams-service" to "components/teams-service"
REPO_DIR := $(shell cd $(REPOROOT) && pwd)/
COMPONENT_DIR := $(shell echo $${PWD\#"$(REPO_DIR)"})
LIBRARY_PATH = github.com/chef/automate/lib
UNAME_S:=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
PLATFORM:=linux-amd64
endif
ifeq ($(UNAME_S),Darwin)
PLATFORM:=darwin-amd64
endif
GOLANGCILINTVERSION?=1.26.0
GOLANGCILINTTARBALL:=golangci-lint-$(GOLANGCILINTVERSION)-$(PLATFORM).tar.gz
LINTERARGS?=./...
# Semgrep by default respects .gitignore; these are additive:
SEMGREP_IGNORE := --exclude third_party --exclude *_test.go --exclude *.pb.go --exclude *.pb.*.go --exclude *.bindata.go
SEMGREP_CONFIG := https://semgrep.dev/p/r2c-ci
$(REPOROOT)/cache/$(GOLANGCILINTTARBALL):
curl --output $(REPOROOT)/cache/$(GOLANGCILINTTARBALL) -L https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCILINTVERSION)/$(GOLANGCILINTTARBALL)
$(REPOROOT)/cache/golangci-lint-$(GOLANGCILINTVERSION)-$(PLATFORM)/golangci-lint: $(REPOROOT)/cache/$(GOLANGCILINTTARBALL)
tar zxf $(REPOROOT)/cache/$(GOLANGCILINTTARBALL) -C $(REPOROOT)/cache/
touch $(REPOROOT)/cache/golangci-lint-$(GOLANGCILINTVERSION)-$(PLATFORM)/golangci-lint
lint: $(REPOROOT)/cache/golangci-lint-$(GOLANGCILINTVERSION)-$(PLATFORM)/golangci-lint
$(REPOROOT)/cache/golangci-lint-$(GOLANGCILINTVERSION)-$(PLATFORM)/golangci-lint run -c $(REPOROOT)/.golangci.yml $(LINTERARGS)
golang_version_check:
@$(REPOROOT)/scripts/golang_version_check.sh
fmt:
@gofmt -w -l ./
fmt-check:
@test -z $(shell gofmt -l ./cmd/ ./pkg/)
spell:
@pushd $(REPOROOT) > /dev/null; \
./scripts/spellcheck.sh $(COMPONENT_DIR); \
EXIT_CODE=$$?; \
popd > /dev/null; \
exit $$EXIT_CODE
#: Security validation via semgrep
# NB: "third_party" only exists for automate-gateway, but no harm having it for other dirs here.
semgrep:
# uncomment if custom rules beyond automate-ui ever get added
# semgrep --config $(REPOROOT)/.semgrep $(SEMGREP_IGNORE)
semgrep --config $(SEMGREP_CONFIG) $(SEMGREP_IGNORE)
#: Security validation via semgrep; autofix where possible
semgrep-and-fix:
# uncomment if custom rules beyond automate-ui ever get added
# semgrep --config $(REPOROOT)/.semgrep $(SEMGREP_IGNORE) --autofix
semgrep --config $(SEMGREP_CONFIG) $(SEMGREP_IGNORE) --autofix
.PHONY: lint fmt fmt-check golang_version_check semgrep semgrep-and-fix