-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
70 lines (58 loc) · 1.92 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
SHELL = bash
default: lint check test build
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)
GO_LDFLAGS := "-X github.com/AndrewChubatiuk/nomad-hcloud-autoscaler/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)"
# Attempt to use gotestsum for running tests, otherwise fallback to go test.
GO_TEST_CMD = $(if $(shell command -v gotestsum 2>/dev/null),gotestsum --,go test)
.PHONY: tools
tools: lint-tools test-tools
.PHONY: test-tools
test-tools: ## Install the tools used to run tests
@echo "==> Installing test tools..."
GO111MODULE=on go install gotest.tools/[email protected]
@echo "==> Done"
.PHONY: lint-tools
lint-tools: ## Install the tools used to lint
@echo "==> Installing lint tools..."
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/[email protected]
GO111MODULE=on go install honnef.co/go/tools/cmd/[email protected]
GO111MODULE=on go install github.com/hashicorp/go-hclog/hclogvet@latest
@echo "==> Done"
.PHONY: build
build:
@echo "==> Building HCloud autoscaler..."
@CGO_ENABLED=0 GO111MODULE=on \
go build \
-ldflags $(GO_LDFLAGS) \
-o ./bin/hcloud-server
@echo "==> Done"
.PHONY: lint
lint: ## Lint the source code
@echo "==> Linting source code..."
@golangci-lint run -j 1
@staticcheck ./...
@hclogvet .
@echo "==> Done"
.PHONY: check
check: check-root-mod
.PHONY: check-root-mod
check-root-mod: ## Checks the root Go mod is tidy
@echo "==> Checking Go mod and Go sum..."
@GO111MODULE=on go mod tidy
@if (git status --porcelain | grep -Eq "go\.(mod|sum)"); then \
echo go.mod or go.sum needs updating; \
git --no-pager diff go.mod; \
git --no-pager diff go.sum; \
exit 1; fi
@echo "==> Done"
.PHONY: test
test: ## Test the source code
@echo "==> Testing source code..."
@$(GO_TEST_CMD) -v -race -cover ./...
@echo "==> Done"
.PHONY: clean
clean:
@echo "==> Cleaning build artifacts..."
@rm -f ./bin/*
@echo "==> Done"