forked from mccutchen/go-httpbin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
108 lines (82 loc) · 3.21 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# The version that will be used in docker tags (e.g. to push a
# go-httpbin:latest image use `make imagepush VERSION=latest)`
VERSION ?= $(shell git rev-parse --short HEAD)
DOCKER_TAG ?= mccutchen/go-httpbin:$(VERSION)
# Built binaries will be placed here
DIST_PATH ?= dist
# Default flags used by the test, testci, testcover targets
COVERAGE_PATH ?= coverage.txt
COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH)
TEST_ARGS ?= -race
# Tool dependencies
TOOL_BIN_DIR ?= $(shell go env GOPATH)/bin
TOOL_GOLINT := $(TOOL_BIN_DIR)/golint
TOOL_STATICCHECK := $(TOOL_BIN_DIR)/staticcheck
GO_SOURCES = $(shell find . -name *.go)
# =============================================================================
# build
# =============================================================================
build: $(DIST_PATH)/go-httpbin
buildtests: $(DIST_PATH)/go-httpbin.test
$(DIST_PATH)/go-httpbin: $(GO_SOURCES)
mkdir -p $(DIST_PATH)
CGO_ENABLED=0 go build -ldflags="-s -w" -o $(DIST_PATH)/go-httpbin ./cmd/go-httpbin
$(DIST_PATH)/go-httpbin.test: $(GO_SOURCES)
CGO_ENABLED=0 go test -ldflags="-s -w" -v -c -o $(DIST_PATH)/go-httpbin.test ./httpbin
clean:
rm -rf $(DIST_PATH) $(COVERAGE_PATH)
.PHONY: clean
# =============================================================================
# test & lint
# =============================================================================
test:
go test $(TEST_ARGS) ./...
.PHONY: test
# Test command to run for continuous integration, which includes code coverage
# based on codecov.io's documentation:
# https://github.com/codecov/example-go/blob/b85638743b972bd0bd2af63421fe513c6f968930/README.md
testci: build
go test $(TEST_ARGS) $(COVERAGE_ARGS) ./...
git diff --exit-code
.PHONY: testci
testcover: testci
go tool cover -html=$(COVERAGE_PATH)
.PHONY: testcover
lint: $(TOOL_GOLINT) $(TOOL_STATICCHECK)
test -z "$$(gofmt -d -s -e .)" || (echo "Error: gofmt failed"; gofmt -d -s -e . ; exit 1)
go vet ./...
$(TOOL_GOLINT) -set_exit_status ./...
$(TOOL_STATICCHECK) ./...
.PHONY: lint
# =============================================================================
# run locally
# =============================================================================
run: build
$(DIST_PATH)/go-httpbin
.PHONY: run
watch: $(TOOL_REFLEX)
reflex -s -r '\.(go|html)$$' make run
.PHONY: watch
# =============================================================================
# docker images
# =============================================================================
image:
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_TAG) .
.PHONY: image
imagepush:
docker buildx create --name httpbin
docker buildx use httpbin
docker buildx build --push --platform linux/amd64,linux/arm64 -t $(DOCKER_TAG) .
docker buildx rm httpbin
.PHONY: imagepush
# =============================================================================
# dependencies
#
# Deps are installed outside of working dir to avoid polluting go modules
# =============================================================================
$(TOOL_GOLINT):
go install golang.org/x/lint/golint@latest
$(TOOL_REFLEX):
go install github.com/cespare/[email protected]
$(TOOL_STATICCHECK):
go install honnef.co/go/tools/cmd/[email protected]