-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
72 lines (52 loc) · 1.99 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
.PHONY: build
GO_PACKAGES=$(shell go list ./...)
GO ?= $(shell command -v go 2> /dev/null)
BUILD_HASH ?= $(shell git rev-parse HEAD)
BUILD_VERSION ?= $(shell git ls-remote --tags --refs https://github.com/coltoneshaw/mmhealth.git | tail -n1 | sed 's/.*\///')
DOCKER_IMAGE_PROD ?= ghcr.io/coltoneshaw/mmhealth
DOCKER_IMAGE_DEV ?= mmhealth
BUILD_ENV ?= dev
ifeq ($(BUILD_ENV),prod)
LDFLAGS += -X "github.com/coltoneshaw/mmhealth/mmhealth.GitCommit=$(BUILD_HASH)"
LDFLAGS += -X "github.com/coltoneshaw/mmhealth/mmhealth.GitVersion=$(BUILD_VERSION)"
else
endif
BUILD_COMMAND ?= go build -ldflags '$(LDFLAGS)' -o ./bin/mmhealth
build: test
mkdir -p bin
$(BUILD_COMMAND)
buildDocker: build
docker build --platform=linux/amd64 -f ./docker/dockerfile -t $(DOCKER_IMAGE_DEV) .
run:
go run ./main.go
package: test
mkdir -p build bin
@echo Build Linux amd64
env GOOS=linux GOARCH=amd64 $(BUILD_COMMAND)
tar cf - -C bin mmhealth | gzip -9 > build/linux_amd64.tar.gz
@echo Build OSX amd64
env GOOS=darwin GOARCH=amd64 $(BUILD_COMMAND)
tar cf - -C bin mmhealth | gzip -9 > build/darwin_amd64.tar.gz
@echo Build OSX arm64
env GOOS=darwin GOARCH=arm64 $(BUILD_COMMAND)
tar cf - -C bin mmhealth | gzip -9 > build/darwin_arm64.tar.gz
@echo Build Windows amd64
env GOOS=windows GOARCH=amd64 go build -ldflags '$(LDFLAGS)' -o ./bin/mmhealth.exe
zip -9 build/windows_amd64.zip ./bin/mmhealth.exe
rm ./bin/mmhealth ./bin/mmhealth.exe
check-style:
# https://stackoverflow.com/a/677212/1027058 (check if a command exists or not)
@if ! [ -x "$$(command -v golangci-lint)" ]; then \
echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
exit 1; \
fi; \
@echo Running golangci-lint
golangci-lint run --skip-dirs-use-default --timeout 5m -E gofmt ./...
test: check-style
@echo Running tests
$(GO) test -race -cover -v $(GO_PACKAGES)
verify-gomod:
$(GO) mod download
$(GO) mod verify
make plugins:
bash ./scripts/update_plugins.sh