-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
209 lines (168 loc) · 5.69 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
205
206
207
208
209
DIST := dist
EXECUTABLE := gohook
DEPLOY_ACCOUNT := tonka
DEPLOY_IMAGE := $(EXECUTABLE)
GOFMT ?= gofmt "-s"
TARGETS ?= linux darwin windows
ARCHS ?= amd64 386
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
SOURCES ?= $(shell find . -name "*.go" -type f)
TEMPLATES ?= $(shell find template -name "*.html" -type f ! -name "master.html")
TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)'
TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'tempdir')
STYLESHEETS := $(wildcard assets/dist/less/innhp.less assets/dist/less/_*.less)
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
else
EXTLDFLAGS =
endif
ifneq ($(DRONE_TAG),)
VERSION ?= $(DRONE_TAG)
else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif
all: build
.PHONY: tar
tar:
tar -zcvf release.tar.gz bin env Dockerfile Makefile
.PHONY: check_image
check_image:
if [ "$(shell docker ps -aq -f name=$(EXECUTABLE))" ]; then \
docker rm -f $(EXECUTABLE); \
fi
.PHONY: dev
dev: build_image check_image
docker run -d --name $(DEPLOY_IMAGE) --env-file env/env.$@ --net host --log-opt max-size=10m --log-opt max-file=10 --restart always $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE)
.PHONY: prod
prod: build_image check_image
docker run -d --name $(DEPLOY_IMAGE) --env-file env/env.$@ --net host --log-opt max-size=10m --log-opt max-file=10 --restart always $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE)
.PHONY: generate
generate:
@which fileb0x > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/UnnoTed/fileb0x; \
fi
go generate $(PACKAGES)
.PHONY: stylesheets-check
stylesheets-check: stylesheets
@diff=$$(git diff assets/dist/css/innhp.css); \
if [ -n "$$diff" ]; then \
echo "Please run 'make stylesheets' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
.PHONY: stylesheets
stylesheets: assets/dist/css/innhp.css
.IGNORE:assets/dist/css/innhp.css
assets/dist/css/innhp.css: $(STYLESHEETS)
@which lessc > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/kib357/less-go/lessc; \
fi
lessc -i $< -o $@
.PHONY: fmt
fmt:
$(GOFMT) -w $(GOFILES)
.PHONY: fmt-check
fmt-check:
# get all go files and run go fmt on them
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
embedmd:
@hash embedmd > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/campoy/embedmd; \
fi
embedmd -d *.md
gtfmt-check:
@hash gtfmt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/gotpl/gtfmt; \
fi
# get all go files and run gtfmt on them
@diff=$$(gtfmt -l $(TEMPLATES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make gtfmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
gtfmt:
@hash gtfmt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/gotpl/gtfmt; \
fi
gtfmt $(TEMPLATES)
vet:
go vet $(PACKAGES)
errcheck:
@hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/kisielk/errcheck; \
fi
errcheck $(PACKAGES)
lint:
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u golang.org/x/lint/golint; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
unconvert:
@hash unconvert > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/mdempsky/unconvert; \
fi
for PKG in $(PACKAGES); do unconvert -v $$PKG || exit 1; done;
install: $(SOURCES)
go install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@ ./cmd
.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -error $(GOFILES)
.PHONY: misspell
misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -w $(GOFILES)
unused-check:
@hash unused > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u honnef.co/go/tools/cmd/unused; \
fi
for PKG in $(PACKAGES); do unused $$PKG || exit 1; done;
test:
rm -rf tests
mkdir -p tests
go test -v -coverprofile=tests/cover.out -covermode=atomic ./...
.PHONY: test-vendor
test-vendor:
@hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/kardianos/govendor; \
fi
govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused"
[ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\"
govendor list +outside | tee "$(TMPDIR)/wc-gitea-outside"
[ $$(cat "$(TMPDIR)/wc-gitea-outside" | wc -l) -eq 0 ] || exit 1
govendor status || exit 1
release: release-dirs release-build release-copy release-check
release-dirs:
mkdir -p $(DIST)/binaries $(DIST)/release
release-build:
@hash gox > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/mitchellh/gox; \
fi
gox -os="$(TARGETS)" -arch="$(ARCHS)" -tags="$(TAGS)" -ldflags="$(EXTLDFLAGS)-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
docker_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags "$(EXTLDFLAGS)-s -w $(LDFLAGS)" -o bin/$(EXECUTABLE) ./cmd
build_image:
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) -f Dockerfile .
docker_release: build_image
clean:
go clean -x -i ./...
rm -rf bin