-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
204 lines (154 loc) · 5.65 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
include .bingo/Variables.mk
SHELL := bash
NAME := github_exporter
IMPORT := github.com/promhippie/$(NAME)
BIN := bin
DIST := dist
ifeq ($(OS), Windows_NT)
EXECUTABLE := $(NAME).exe
UNAME := Windows
else
EXECUTABLE := $(NAME)
UNAME := $(shell uname -s)
endif
GOBUILD ?= CGO_ENABLED=0 go build
PACKAGES ?= $(shell go list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f -not -path ./.devenv/\* -not -path ./.direnv/\*)
GENERATE ?= $(PACKAGES)
TAGS ?= netgo chai sqlite
ifndef OUTPUT
ifeq ($(GITHUB_REF_TYPE), tag)
OUTPUT ?= $(subst v,,$(GITHUB_REF_NAME))
else
OUTPUT ?= testing
endif
endif
ifndef VERSION
ifeq ($(GITHUB_REF_TYPE), tag)
VERSION ?= $(subst v,,$(GITHUB_REF_NAME))
else
VERSION ?= $(shell git rev-parse --short HEAD)
endif
endif
ifndef DATE
DATE := $(shell date -u '+%Y%m%d')
endif
ifndef SHA
SHA := $(shell git rev-parse --short HEAD)
endif
LDFLAGS += -s -w -extldflags "-static" -X "$(IMPORT)/pkg/version.String=$(VERSION)" -X "$(IMPORT)/pkg/version.Revision=$(SHA)" -X "$(IMPORT)/pkg/version.Date=$(DATE)"
GCFLAGS += all=-N -l
.PHONY: all
all: build
.PHONY: sync
sync:
go mod download
.PHONY: clean
clean:
go clean -i ./...
rm -rf $(BIN) $(DIST)
.PHONY: fmt
fmt:
gofmt -s -w $(SOURCES)
.PHONY: vet
vet:
go vet $(PACKAGES)
.PHONY: staticcheck
staticcheck: $(STATICCHECK)
$(STATICCHECK) -tags '$(TAGS)' $(PACKAGES)
.PHONY: lint
lint: $(REVIVE)
for PKG in $(PACKAGES); do $(REVIVE) -config revive.toml -set_exit_status $$PKG || exit 1; done;
.PHONY: generate
generate:
go generate $(GENERATE)
.PHONY: changelog
changelog: $(CALENS)
$(CALENS) >| CHANGELOG.md
.PHONY: test
test:
go test -coverprofile coverage.out $(PACKAGES)
.PHONY: install
install: $(SOURCES)
go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME)
.PHONY: build
build: $(BIN)/$(EXECUTABLE)
$(BIN)/$(EXECUTABLE): $(SOURCES)
$(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(BIN)/$(EXECUTABLE)-debug: $(SOURCES)
$(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -gcflags '$(GCFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release
release: $(DIST) release-linux release-darwin release-windows release-reduce release-checksum
$(DIST):
mkdir -p $(DIST)
.PHONY: release-linux
release-linux: $(DIST) \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-386 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-amd64 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-5 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-6 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-7 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm64 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-mips \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-mips64 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-mipsle \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-mips64le
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-386:
GOOS=linux GOARCH=386 $(GOBUILD) -v -tags 'netgo sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-amd64:
GOOS=linux GOARCH=amd64 $(GOBUILD) -v -tags 'netgo chai sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-5:
GOOS=linux GOARCH=arm GOARM=5 $(GOBUILD) -v -tags 'netgo sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-6:
GOOS=linux GOARCH=arm GOARM=6 $(GOBUILD) -v -tags 'netgo sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm-7:
GOOS=linux GOARCH=arm GOARM=7 $(GOBUILD) -v -tags 'netgo sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-arm64:
GOOS=linux GOARCH=arm64 $(GOBUILD) -v -tags 'netgo chai sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-mips:
GOOS=linux GOARCH=mips $(GOBUILD) -v -tags 'netgo' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-mips64:
GOOS=linux GOARCH=mips64 $(GOBUILD) -v -tags 'netgo chai' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-mipsle:
GOOS=linux GOARCH=mipsle $(GOBUILD) -v -tags 'netgo' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-linux-mips64le:
GOOS=linux GOARCH=mips64le $(GOBUILD) -v -tags 'netgo chai' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release-darwin
release-darwin: $(DIST) \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-darwin-amd64 \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-darwin-arm64
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-darwin-amd64:
GOOS=darwin GOARCH=amd64 $(GOBUILD) -v -tags 'chai sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-darwin-arm64:
GOOS=darwin GOARCH=arm64 $(GOBUILD) -v -tags 'chai sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release-windows
release-windows: $(DIST) \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-windows-4.0-386.exe \
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-windows-4.0-amd64.exe
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-windows-4.0-386.exe:
GOOS=windows GOARCH=386 $(GOBUILD) -v -tags '' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(DIST)/$(EXECUTABLE)-$(OUTPUT)-windows-4.0-amd64.exe:
GOOS=windows GOARCH=amd64 $(GOBUILD) -v -tags 'chai sqlite' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release-reduce
release-reduce:
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),upx $(notdir $(file));)
.PHONY: release-checksum
release-checksum:
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
.PHONY: release-finish
release-finish: release-reduce release-checksum
.PHONY: docs
docs:
hugo -s docs/
.PHONY: envvars
envvars:
go run hack/generate-envvars-docs.go
.PHONY: metrics
metrics:
go run hack/generate-metrics-docs.go
.PHONY: labels
labels:
go run hack/generate-labels-docs.go
.PHONY: watch
watch: $(REFLEX)
$(REFLEX) -c reflex.conf