-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
75 lines (63 loc) · 2.34 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
Version := $(shell git describe --tags --dirty --always)
GitCommit := $(shell git rev-parse HEAD)
LDFLAGS := "-s -w -X awssh/cmd.Version=$(Version) -X awssh/cmd.GitCommit=$(GitCommit)"
SOURCE_DIRS = cmd config internal main.go
OUTDIR := bin
GOLANGCI_VERSION = 1.31.0
## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
bin/golangci-lint-${GOLANGCI_VERSION}:
@mkdir -p bin
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ./bin/ v${GOLANGCI_VERSION}
@mv bin/golangci-lint "$@"
## audit: tidy and vendor dependencies and format, vet, lint and test all code
.PHONY: audit
audit: fmt vendor lint vet test
## fmt: formatting the code
fmt:
@echo 'Formatting code...'
@go fmt $(shell go list ./... | grep -v /vendor/|xargs echo)
## vendor: tidy and vendor dependencies
.PHONY: vendor
vendor:
@echo 'Tidying and verifying module dependencies...'
@go mod tidy
@go mod verify
@echo 'Vendoring dependencies...'
@go mod vendor
## lint: linting the code
.PHONY: lint
lint: bin/golangci-lint
@echo 'Linting code...'
bin/golangci-lint run
## test: run unit test
.PHONY: test
test:
@echo 'Running tests...'
@mkdir -p output
@go test $(shell go list ./... | grep -v /vendor/|xargs echo) -cover -coverprofile=./output/coverage.out -race && \
go tool cover -html=./output/coverage.out -o ./output/coverage.html && \
go tool cover -func=./output/coverage.out
## vet: run vetting the code
.PHONY: vet
vet:
@echo 'Vetting code...'
@go vet $(shell go list ./... | grep -v /vendor/|xargs echo)
## build/dist: build application distributions
.PHONY: build/dist
build/dist:
mkdir -p $(OUTDIR)
CGO_ENABLED=0 GOOS=linux go build -ldflags $(LDFLAGS) -o $(OUTDIR)/awssh
CGO_ENABLED=0 GOOS=darwin go build -ldflags $(LDFLAGS) -o $(OUTDIR)/awssh-darwin
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags $(LDFLAGS) -o $(OUTDIR)/awssh-armhf
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags $(LDFLAGS) -o $(OUTDIR)/awssh-arm64
CGO_ENABLED=0 GOOS=windows go build -ldflags $(LDFLAGS) -o $(OUTDIR)/awssh.exe
## build: build an application binary
.PHONY: build
build:
CGO_ENABLED=0 go build -ldflags $(LDFLAGS) -o awssh