-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
88 lines (69 loc) · 2.71 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
80
81
82
83
84
85
86
87
88
BINARY = super_hooks
VET_REPORT = vet.report
TEST_REPORT = tests.xml
GITHUB_TOKEN?=""
VERSION?=0.0.0
DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
SOURCE?="github.com/frankywahl/super_hooks"
# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS = -ldflags "-X ${SOURCE}/version.GitRevision=${COMMIT} -X ${SOURCE}/version.Version=${VERSION} -X ${SOURCE}/version.CreatedAt=${DATE}"
COMMIT=$(shell git rev-parse HEAD)
GO=go
GOLINT=golangci-lint
GORELEASER=goreleaser
ifeq ($(DOCKER), true)
GO=docker run --rm --volume $(shell pwd):/app --workdir /app golang:latest go
GOLINT=docker run --rm --volume $(shell pwd):/app --workdir /app golangci/golangci-lint:latest golangci-lint
GORELEASER=docker run --rm --privileged \
--volume $(shell pwd):/go/src/github.com/frankywahl/super_hooks \
--volume /var/run/docker.sock:/var/run/docker.sock \
--workdir /go/src/github.com/frankywahl/super_hooks \
--env GITHUB_TOKEN=${GITHUB_TOKEN} \
--env SOURCE=${SOURCE} \
goreleaser/goreleaser
endif
.PHONY: default
default: help
%-docker: ## Run a make command using docker
@DOCKER=true $(MAKE) $*
.PHONY: build
build: ## Build will create a binary for this system. Similar to `go build`, but uses goreleaser.
$(GORELEASER) build --snapshot --clean --single-target
.PHONY: clean
clean: ## Clean all dependencies
-rm -f ${TEST_REPORT}
-rm -f ${VET_REPORT}
.PHONY: coverage
coverage: ## Run coverage analysis with go cover
$(GO) test -race -v -count=1 -coverprofile=cover.out ./...
$(GO) tool cover -html=cover.out
.PHONY: docker
docker: ## Build a docker image
docker build -t ghcr.io/frankywahl/super_hooks .
.PHONY: fmt
fmt: ## Run fmt on go files
@test -z $(shell $(GO) fmt $$($(GO) list ./... | grep -v /vendor/)) || (echo "Unsucsessfull format - files changed" && exit 1) # This will return non-0 if unsuccessful run `go fmt ./...` to fix
.PHONY: gorelease
gorelease: ## Build a release locally. This will not be published
SOURCE=$(shell hostname) $(GORELEASER) release --clean --snapshot --skip=publish
.PHONY: help
help: ## Show this help
@echo "Usage: make <target>"
@echo
@echo "Targets:"
@grep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?\#\# "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
.PHONY: install
install: ## Install the binary on the machine
$(GO) build ${LDFLAGS} -o ${GOPATH}/bin/${BINARY} *.go
.PHONY: test
test: ## Run the test suite
$(GO) test -v --race -count=1 ./... 2>&1 | tee ${TEST_REPORT} ;
.PHONY: vendor
vendor: ## Vendor dependencies locally
$(GO) mod vendor
.PHONY: vet
vet: ## Run vet on go files
$(GO) vet ./... > ${VET_REPORT} 2>&1 ;
.PHONY: vulncheck
vulncheck: ## Run vulnerability scanner check
$(GO) run golang.org/x/vuln/cmd/govulncheck ./...