This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (56 loc) · 3.06 KB
/
Makefile
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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/make -f
VERSION := $(shell echo $(shell git describe --tags --always) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
BuildTime :=$(shell date '+%Y-%m-%dT%H:%M:%SZ%z')
ldflags = '-X github.com/FunctionX/cosmos-firewall.Version=$(VERSION) \
-X github.com/FunctionX/cosmos-firewall.Commit=$(COMMIT) \
-X github.com/FunctionX/cosmos-firewall.BuildTime=$(BuildTime) \
-w -s'
BUILDDIR ?= $(CURDIR)/build
###############################################################################
### Build ###
###############################################################################
all: build lint test
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
go mod verify
go mod tidy
@echo "--> Download go modules to local cache"
go mod download
build: go.sum
go build -mod=readonly -v -ldflags $(ldflags) -o $(BUILDDIR)/bin/firewalld ./cmd/
@echo "--> Done building."
build-linux:
@GOOS=linux GOARCH=amd64 $(MAKE) build
INSTALL_DIR := $(shell go env GOPATH)/bin
install: build $(INSTALL_DIR)
mv $(BUILDDIR)/bin/firewalld $(shell go env GOPATH)/bin/firewalld
@echo "--> Run \"firewalld start\" or \"$(shell go env GOPATH)/bin/firewalld start\" to launch firewalld."
$(INSTALL_DIR):
@echo "Folder $(INSTALL_DIR) does not exist"
mkdir -p $@
.PHONY: build build-win install docker go.sum
###############################################################################
### Linting ###
###############################################################################
lint:
@echo "--> Running linter"
@which golangci-lint > /dev/null || echo "\033[91m install golangci-lint ...\033[0m" && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@which gocyclo > /dev/null || echo "\033[91m install gocyclo ...\033[0m" && go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
@which gofumpt > /dev/null || echo "\033[91m install gofumpt ...\033[0m" && go install mvdan.cc/gofumpt@latest
golangci-lint run -v --go=1.19 --timeout 10m
find . -name '*.go' -type f -not -path "./build*" -not -path "*.git*" -not -name '*.pb.*' | xargs gofumpt -d | xargs gocyclo -over 15
find . -name '*.go' -type f -not -path "./build*" -not -path "*.git*" -not -name '*.pb.*' | xargs gofumpt -d | xargs gofumpt -d
format: format-goimports
golangci-lint run --fix --out-format=tab --issues-exit-code=0
format-goimports:
@go install github.com/incu6us/goimports-reviser/v3@latest
@find . -name '*.go' -type f -not -path './build*' -not -name 'statik.go' -not -name '*.pb.go' -not -name '*.pb.gw.go' -exec goimports-reviser -use-cache -rm-unused {} \;
.PHONY: format lint format-goimports
###############################################################################
### Tests & Simulation ###
###############################################################################
test:
@echo "--> Running tests"
go test -mod=readonly ./...
.PHONY: test