forked from Brightscout/mattermost-plugin-disable-dm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
214 lines (179 loc) · 6.39 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
210
211
212
213
214
GO:=go
GOARCH:=amd64
GOOS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
GOPATH ?= $(GOPATH:)
MANIFEST_FILE ?= plugin.json
PLUGINNAME=$(shell echo `grep '"'"id"'"\s*:\s*"' $(MANIFEST_FILE) | head -1 | cut -d'"' -f4`)
PLUGINVERSION=v$(shell echo `grep '"'"version"'"\s*:\s*"' $(MANIFEST_FILE) | head -1 | cut -d'"' -f4`)
PACKAGENAME=mattermost-plugin-$(PLUGINNAME)-$(PLUGINVERSION)
HAS_WEBAPP=$(shell if [ "$(shell grep -E '[\^"]webapp["][ ]*[:]' $(MANIFEST_FILE) | wc -l)" -gt "0" ]; then echo "true"; fi)
HAS_SERVER=$(shell if [ "$(shell grep -E '[\^"]server["][ ]*[:]' $(MANIFEST_FILE) | wc -l)" -gt "0" ]; then echo "true"; fi)
TMPFILEGOLINT=golint.tmp
BLACK=`tput setaf 0`
RED=`tput setaf 1`
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
BLUE=`tput setaf 4`
MAGENTA=`tput setaf 5`
CYAN=`tput setaf 6`
WHITE=`tput setaf 7`
BOLD=`tput bold`
INVERSE=`tput rev`
RESET=`tput sgr0`
.PHONY: default .npminstall vendor setup-plugin build test clean check-style check-js check-go govet golint gofmt .distclean dist format fix-js fix-go trigger-release install-dependencies
default: dist
setup-plugin:
ifneq ($(HAS_WEBAPP),)
@echo "export const PLUGIN_NAME = '`echo $(PLUGINNAME)`';" > webapp/src/constants/manifest.js
endif
ifneq ($(HAS_SERVER),)
@echo "package config\n\nconst (\n\tPluginName = \""`echo $(PLUGINNAME)`"\"\n)" > server/config/manifest.go
endif
trigger-release:
@if [ $$(git status --porcelain | wc -l) != "0" -o $$(git rev-list HEAD@{upstream}..HEAD | wc -l) != "0" ]; \
then echo ${RED}"local repo is not clean"${RESET}; exit 1; fi;
@echo ${BOLD}"Creating a tag to trigger circleci build-and-release job\n"${RESET}
git tag $(PLUGINVERSION)
git push origin $(PLUGINVERSION)
check-style: check-js check-go
check-js:
ifneq ($(HAS_WEBAPP),)
@echo ${BOLD}Running ESLINT${RESET}
@cd webapp && npm run lint
@echo ${GREEN}"eslint success\n"${RESET}
endif
check-go: govet golint gofmt
govet:
ifneq ($(HAS_SERVER),)
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
echo "--> installing govet"; \
go get golang.org/x/tools/cmd/vet; \
fi
@echo ${BOLD}Running GOVET${RESET}
@$(GO) get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
@$(eval PKGS := $(shell go list ./server/... | grep -v /vendor/))
@$(GO) vet $(PKGS)
@$(GO) vet -vettool=$(GOPATH)/bin/shadow $(PKGS)
@echo ${GREEN}"govet success\n"${RESET}
endif
golint:
ifneq ($(HAS_SERVER),)
@command -v golint >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing golint"; \
go get -u golang.org/x/lint/golint; \
fi
@echo ${BOLD}Running GOLINT${RESET}
@cd server
$(eval PKGS := $(shell go list ./... | grep -v /vendor/))
@touch $(TMPFILEGOLINT)
-@for pkg in $(PKGS) ; do \
echo `golint $$pkg | grep -v "have comment" | grep -v "comment on exported" | grep -v "lint suggestions"` >> $(TMPFILEGOLINT) ; \
done
@grep -Ev "^$$" $(TMPFILEGOLINT) || true
@if [ "$$(grep -Ev "^$$" $(TMPFILEGOLINT) | wc -l)" -gt "0" ]; then \
rm -f $(TMPFILEGOLINT); echo ${RED}"golint failure\n"${RESET}; exit 1; else \
rm -f $(TMPFILEGOLINT); echo ${GREEN}"golint success\n"${RESET}; \
fi
endif
format: fix-js fix-go
fix-js:
ifneq ($(HAS_WEBAPP),)
@echo ${BOLD}Formatting js files${RESET}
@cd webapp && npm run fix
@echo "formatted js files\n"
endif
fix-go:
ifneq ($(HAS_SERVER),)
@command -v goimports >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing goimports"; \
go get golang.org/x/tools/cmd/goimports; \
fi
@echo ${BOLD}Formatting go files${RESET}
@cd server
@find ./ -type f -name "*.go" -not -path "./server/vendor/*" -exec goimports -w {} \;
@echo "formatted go files\n"
endif
gofmt:
ifneq ($(HAS_SERVER),)
@echo ${BOLD}Running GOFMT${RESET}
@for package in $$(go list ./server/...); do \
files=$$(go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' $$package); \
if [ "$$files" ]; then \
gofmt_output=$$(gofmt -d -s $$files 2>&1); \
if [ "$$gofmt_output" ]; then \
echo "$$gofmt_output"; \
echo ${RED}"gofmt failure\n"${RESET}; \
exit 1; \
fi; \
fi; \
done
@echo ${GREEN}"gofmt success\n"${RESET}
endif
test:
ifneq ($(HAS_SERVER),)
go test -v -coverprofile=coverage.txt ./...
endif
.npminstall:
ifneq ($(HAS_WEBAPP),)
@echo ${BOLD}"Getting dependencies using npm\n"${RESET}
cd webapp && npm install
@echo "\n"
endif
vendor:
ifneq ($(HAS_SERVER),)
@echo ${BOLD}"Getting dependencies using glide\n"${RESET}
cd server && go get github.com/Masterminds/glide
cd server && $(shell go env GOPATH)/bin/glide install
@echo "\n"
endif
install-dependencies: .npminstall vendor
dist: install-dependencies check-style test build
build: .distclean $(MANIFEST_FILE)
@echo ${BOLD}"Building plugin\n"${RESET}
mkdir -p dist/$(PLUGINNAME)/
cp $(MANIFEST_FILE) dist/$(PLUGINNAME)/
ifneq ($(HAS_WEBAPP),)
# Build and copy files from webapp
cd webapp && npm run build
mkdir -p dist/$(PLUGINNAME)/webapp
cp -r webapp/dist/* dist/$(PLUGINNAME)/webapp/
endif
ifneq ($(HAS_SERVER),)
# Build files from server and copy server executables
cd server && go get github.com/mitchellh/gox
$(shell go env GOPATH)/bin/gox -osarch='darwin/amd64 linux/amd64 windows/amd64' -output 'dist/intermediate/plugin_{{.OS}}_{{.Arch}}' ./server
mkdir -p dist/$(PLUGINNAME)/server
endif
# Compress plugin
ifneq ($(HAS_SERVER),)
mv dist/intermediate/plugin_darwin_amd64 dist/$(PLUGINNAME)/server/plugin.exe
cd dist && tar -zcvf $(PACKAGENAME)-darwin-amd64.tar.gz $(PLUGINNAME)/*
mv dist/intermediate/plugin_linux_amd64 dist/$(PLUGINNAME)/server/plugin.exe
cd dist && tar -zcvf $(PACKAGENAME)-linux-amd64.tar.gz $(PLUGINNAME)/*
mv dist/intermediate/plugin_windows_amd64.exe dist/$(PLUGINNAME)/server/plugin.exe
cd dist && tar -zcvf $(PACKAGENAME)-windows-amd64.tar.gz $(PLUGINNAME)/*
else ifneq ($(HAS_WEBAPP),)
cd dist && tar -zcvf $(PACKAGENAME).tar.gz $(PLUGINNAME)/*
endif
# Clean up temp files
rm -rf dist/$(PLUGINNAME)
rm -rf dist/intermediate
ifneq ($(HAS_SERVER),)
@echo Linux plugin built at: dist/$(PACKAGENAME)-linux-amd64.tar.gz
@echo MacOS X plugin built at: dist/$(PACKAGENAME)-darwin-amd64.tar.gz
@echo Windows plugin built at: dist/$(PACKAGENAME)-windows-amd64.tar.gz
else ifneq ($(HAS_WEBAPP),)
@echo Cross-platform plugin built at: dist/$(PACKAGENAME)-amd64.tar.gz
endif
.distclean:
@echo ${BOLD}"Cleaning dist files\n"${RESET}
rm -rf dist
rm -rf webapp/dist
rm -f server/plugin.exe
@echo "\n"
clean: .distclean
@echo ${BOLD}"Cleaning plugin\n"${RESET}
rm -rf server/vendor
rm -rf webapp/node_modules
rm -rf webapp/.npminstall
@echo "\n"