-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
141 lines (114 loc) · 4.77 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# UpCloud CLI Makefile
GO = go
PYTHON = python3
PIP = pip3
CLI = upctl
MODULE = $(shell env GO111MODULE=on $(GO) list -m)
DATE ?= $(shell date +%FT%T%z)
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \
cat $(CURDIR)/.version 2> /dev/null || echo v0)
LATEST_RELEASE ?= $(shell git describe --tags --match=v* --abbrev=0 | grep -o "[0-9]\.[0-9]\.[0-9]")
PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./...))
TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \
'{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \
$(PKGS))
BIN_DIR = $(CURDIR)/bin
CLI_BIN = $(CLI)
BIN_LINUX = $(CLI_BIN)-$(VERSION)-linux-amd64
BIN_DOCKERISED_LINUX = $(CLI_BIN)-$(VERSION)-dockerised-linux-amd64
BIN_DARWIN = $(CLI_BIN)-$(VERSION)-darwin-amd64
BIN_WINDOWS = $(CLI_BIN)-$(VERSION)-windows-amd64.exe
BIN_FREEBSD = $(CLI_BIN)-$(VERSION)-freebsd-amd64
V = 0
Q = $(if $(filter 1,$V),,@)
export GO111MODULE=on
.PHONY: build
build: fmt | $(BIN_DIR) ; $(info building executable for the current target…) @ ## Build program binary for current os/arch
$Q $(GO) build \
-tags release \
-ldflags '-X $(MODULE)/internal/config.Version=$(VERSION) -X $(MODULE)/internal/config.BuildDate=$(DATE)' \
-o $(BIN_DIR)/$(CLI_BIN) cmd/$(CLI)/main.go
.PHONY: clean-md-docs
clean-md-docs:
rm -f docs/changelog.md
rm -rf docs/commands_reference/
rm -rf docs/examples/
.PHONY: md-docs
md-docs: clean-md-docs ## Generate documentation (markdown)
$(GO) run ./.ci/docs/
cp CHANGELOG.md docs/changelog.md
cp -r examples/ docs/examples/
.PHONY: clean-docs
clean-docs:
rm -f mkdocs.yaml
rm -rf site/
.PHONY: install-docs-tools
install-docs-tools:
$(PIP) install -r requirements.txt
.PHONY: docs
docs: clean-docs md-docs install-docs-tools ## Generate documentation (mkdocs site)
$(PYTHON) .ci/docs/generate_dynamic_nav.py
$(PYTHON) .ci/docs/prepare_info_texts_for_mkdocs.py
echo "latest_release: $(LATEST_RELEASE)" > vars.yaml
mkdocs build
.PHONY: build-all
build-all: build-linux build-darwin build-windows build-freebsd ## Build all targets
.PHONY: build-linux
build-linux: ; $(info building executable for Linux x86_64…) @ ## Build program binary for linux x86_64
$Q GOOS=linux GOARCH=amd64 $(GO) build \
-tags release \
-ldflags '-X $(MODULE)/internal/config.Version=$(VERSION) -X $(MODULE)/internal/config.BuildDate=$(DATE)' \
-o $(BIN_DIR)/$(BIN_LINUX) cmd/$(CLI)/main.go
.PHONY: build-freebsd
build-freebsd: ; $(info building executable for FreeBSD x86_64…) @ ## Build program binary for freebsd x86_64
$Q GOOS=freebsd GOARCH=amd64 $(GO) build \
-tags release \
-ldflags '-X $(MODULE)/internal/config.Version=$(VERSION) -X $(MODULE)/internal/config.BuildDate=$(DATE)' \
-o $(BIN_DIR)/$(BIN_FREEBSD) cmd/$(CLI)/main.go
.PHONY: build-dockerised
build-dockerised: ; $(info building executable for dockerised Linux x86_64…) @ ## Build program binary for dockerised linux x86_64
$Q GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build \
-tags release \
-ldflags '-X $(MODULE)/internal/config.Version=$(VERSION) -X $(MODULE)/internal/config.BuildDate=$(DATE) -w' \
-o $(BIN_DIR)/$(BIN_DOCKERISED_LINUX) cmd/$(CLI)/main.go
.PHONY: build-darwin
build-darwin: $(BIN_DIR) ; $(info building executable for Darwin x86_64…) @ ## Build program binary for darwin x86_64
$Q GOOS=darwin GOARCH=amd64 $(GO) build \
-tags release \
-ldflags '-X $(MODULE)/internal/config.Version=$(VERSION) -X $(MODULE)/internal/config.BuildDate=$(DATE)' \
-o $(BIN_DIR)/$(BIN_DARWIN) cmd/$(CLI)/main.go
.PHONY: build-windows
build-windows: $(BIN_DIR) ; $(info building executable for Windows x86_64…) @ ## Build program binary for windows x86_64
$Q GOOS=windows GOARCH=amd64 $(GO) build \
-tags release \
-ldflags '-X $(MODULE)/internal/config.Version=$(VERSION) -X $(MODULE)/internal/config.BuildDate=$(DATE)' \
-o $(BIN_DIR)/$(BIN_WINDOWS) cmd/$(CLI)/main.go
# Tests
.PHONY: test
test: fmt; $(info running $(NAME:%=% )tests…) @ ## Run tests
$Q $(GO) test $(TESTPKGS)
.PHONY: fmt
fmt: ; $(info running gofmt…) @ ## Run gofmt on all source files
$Q $(GO) fmt $(PKGS)
# Misc
$(BIN_DIR):
@mkdir -p $@
.PHONY: clean
clean: ; $(info cleaning…) @ ## Cleanup everything
@rm -rf $(BIN_DIR)
.PHONY: help
help:
@grep -hE '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "%-20s %s\n", $$1, $$2}'
.PHONY: version
version:
@echo $(VERSION)
.PHONY: release-notes
release-notes: CHANGELOG_HEADER = ^\#\# \[
release-notes: CHANGELOG_VERSION = $(subst v,,$(VERSION))
release-notes:
@awk \
'/${CHANGELOG_HEADER}${CHANGELOG_VERSION}/ { flag = 1; next } \
/${CHANGELOG_HEADER}/ { if ( flag ) { exit; } } \
flag { if ( n ) { print prev; } n++; prev = $$0 }' \
CHANGELOG.md