forked from justwatchcom/github-releases-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
73 lines (55 loc) · 1.84 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
DIST := dist
BIN := bin
EXECUTABLE := github-releases-notifier
PWD := $(shell pwd)
VERSION := $(shell cat VERSION)
SHA := $(shell cat COMMIT 2>/dev/null || git rev-parse --short=8 HEAD)
DATE := $(shell date -u '+%FT%T%z')
GOLDFLAGS += -X "main.version=$(VERSION)"
GOLDFLAGS += -X "main.date=$(DATE)"
GOLDFLAGS += -X "main.commit=$(SHA)"
GOLDFLAGS += -extldflags '-static'
GO := CGO_ENABLED=0 go
GOOS ?= $(shell go version | cut -d' ' -f4 | cut -d'/' -f1)
GOARCH ?= $(shell go version | cut -d' ' -f4 | cut -d'/' -f2)
PACKAGES ?= $(shell go list ./... | grep -v /vendor/ | grep -v /tests)
TAGS ?= netgo
.PHONY: all
all: clean test build
.PHONY: clean
clean:
$(GO) clean -i ./...
find . -type f -name "coverage.out" -delete
.PHONY: fmt
fmt:
$(GO) fmt $(PACKAGES)
.PHONY: tests
tests: test vet lint errcheck megacheck
.PHONY: vet
vet:
$(GO) vet $(PACKAGES)
.PHONY: lint
lint:
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/golang/lint/golint; \
fi
STATUS=0; for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || STATUS=1; done; exit $$STATUS
.PHONY: errcheck
errcheck:
@which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/kisielk/errcheck; \
fi
STATUS=0; for PKG in $(PACKAGES); do errcheck $$PKG || STATUS=1; done; exit $$STATUS
.PHONY: megacheck
megacheck:
@which megacheck > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u honnef.co/go/tools/cmd/megacheck; \
fi
STATUS=0; for PKG in $(PACKAGES); do megacheck $$PKG || STATUS=1; done; exit $$STATUS
.PHONY: test
test:
STATUS=0; for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || STATUS=1; done; exit $$STATUS
.PHONY: build
build: $(EXECUTABLE)-$(GOOS)-$(GOARCH)
$(EXECUTABLE)-$(GOOS)-$(GOARCH): $(wildcard *.go)
$(GO) build -tags '$(TAGS)' -ldflags '-s -w $(GOLDFLAGS)' -o $(EXECUTABLE)