forked from standup-raven/standup-raven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
202 lines (158 loc) · 6.1 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
GOOS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
GOARCH=amd64
GOFLAGS ?= $(GOFLAGS:)
MANIFEST_FILE ?= plugin.json
define GetFromPkg
$(shell node -p "require('./build_properties.json').$(1)")
endef
define GetPluginId
$(shell node -p "require('./plugin.json').id")
endef
define GetPluginVersion
$(shell node -p "'v' + require('./plugin.json').version")
endef
define AddTimeZoneOptions
$(shell node -e
"
let fs = require('fs');
try {
let manifest = fs.readFileSync('plugin.json', 'utf8');
manifest = JSON.parse(manifest);
let timezones = fs.readFileSync('timezones.json', 'utf8');
timezones = JSON.parse(timezones);
manifest.settings_schema.settings[0].options=timezones;
let json = JSON.stringify(manifest, null, 2);
fs.writeFileSync('plugin.json', json, 'utf8');
} catch (err) {
console.log(err);
};"
)
endef
define RemoveTimeZoneOptions
$(shell node -e
"
let fs = require('fs');
try {
let manifest = fs.readFileSync('plugin.json', 'utf8');
manifest = JSON.parse(manifest);
manifest.settings_schema.settings[0].options=[];
let json = JSON.stringify(manifest, null, 2);
fs.writeFileSync('plugin.json', json, 'utf8');
} catch (err) {
console.log(err);
};"
)
endef
PLUGINNAME=$(call GetPluginId)
PLUGINVERSION=$(call GetPluginVersion)
PACKAGENAME=mattermost-plugin-$(PLUGINNAME)-$(PLUGINVERSION)
.PHONY: default build test run clean stop check-style check-style-server .distclean dist fix-style release
default: check-style test dist
check-style: check-style-server check-style-webapp
check-style-webapp: .npminstall
@echo Checking for style guide compliance
cd webapp && npm run lint
check-style-server:
@echo Running GOFMT
@for package in $$(go list ./server/...); do \
echo "Checking "$$package; \
files=$$(go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' $$package); \
if [ "$$files" ]; then \
gofmt_output=$$(gofmt -w -s $$files 2>&1); \
if [ "$$gofmt_output" ]; then \
echo "$$gofmt_output"; \
echo "gofmt failure"; \
exit 1; \
fi; \
fi; \
done
@echo "gofmt success"; \
fix-style: .npminstall check-style-server
@echo Checking for style guide compliance
cd webapp && npm run fix
test-server: vendor
@echo Running server tests
go test -v -coverprofile=coverage.txt ./...
test: test-server
cover: test-server
go tool cover -html=coverage.txt -o coverage.html
.npminstall: webapp/package-lock.json
@echo Getting dependencies using npm
cd webapp && npm install
vendor: server/glide.lock
cd server && go get github.com/Masterminds/glide
cd server && $(shell go env GOPATH)/bin/glide install
prequickdist: .distclean plugin.json
@echo Updating plugin.json with timezones
$(call AddTimeZoneOptions)
doquickdist:
@echo $(PLUGINNAME)
@echo $(PACKAGENAME)
@echo $(PLUGINVERSION)
@echo Quick building plugin
# Build and copy files from webapp
cd webapp && npm run build
mkdir -p dist/$(PLUGINNAME)/webapp
cp -r webapp/dist/* dist/$(PLUGINNAME)/webapp/
# Build files from server
cd server && go get github.com/mitchellh/gox
$(shell go env GOPATH)/bin/gox -ldflags="-X main.SentryEnabled=$(call GetFromPkg,sentry.enabled) -X main.SentryDSN=$(call GetFromPkg,sentry.dsn)" -osarch='darwin/amd64 linux/amd64 windows/amd64' -gcflags='all=-N -l' -output 'dist/intermediate/plugin_{{.OS}}_{{.Arch}}' ./server
# Copy plugin files
cp plugin.json dist/$(PLUGINNAME)/
# Copy server executables & compress plugin
mkdir -p dist/$(PLUGINNAME)/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)/*
# Clean up temp files
rm -rf dist/$(PLUGINNAME)
rm -rf dist/intermediate
@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
postquickdist:
@echo Remove data from plugin.json
$(call RemoveTimeZoneOptions)
quickdist: prequickdist doquickdist postquickdist
dist: vendor .npminstall quickdist
@echo Building plugin
run: .npminstall
@echo Not yet implemented
stop:
@echo Not yet implemented
.distclean:
@echo Cleaning dist files
rm -rf dist
rm -rf webapp/dist
rm -f server/plugin.exe
clean: .distclean
@echo Cleaning plugin
rm -rf webapp/node_modules
rm -rf webapp/.npminstall
# deploy installs the plugin to a (development) server, using the API if appropriate environment
# variables are defined, or copying the files directly to a sibling mattermost-server directory
.PHONY: deploy
deploy:
@echo "Installing plugin via API"
@echo "Authenticating admin user..." && \
TOKEN=`http --print h POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/login login_id=$(MM_ADMIN_USERNAME) password=$(MM_ADMIN_PASSWORD) X-Requested-With:"XMLHttpRequest" | grep Token | cut -f2 -d' '` && \
http GET $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/me Authorization:"Bearer $$TOKEN" > /dev/null && \
echo "Deleting existing plugin..." && \
http DELETE $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGINNAME) Authorization:"Bearer $$TOKEN" > /dev/null && \
echo "Uploading plugin..." && \
http --check-status --form POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins plugin@dist/$(PACKAGENAME)-$(PLATFORM)-amd64.tar.gz Authorization:"Bearer $$TOKEN" > /dev/null && \
echo "Enabling uploaded plugin..." && \
http POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGINNAME)/enable Authorization:"Bearer $$TOKEN" > /dev/null && \
echo "Logging out admin user..." && \
http POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/logout Authorization:"Bearer $$TOKEN" > /dev/null && \
echo "Plugin uploaded successfully"
release: dist
@echo "Installing ghr"
@go get -u github.com/tcnksm/ghr
@echo "Create new tag"
$(shell git tag $(PLUGINVERSION))
@echo "Uploading artifacts"
@ghr -t $(GITHUB_TOKEN) -u $(ORG_NAME) -r $(REPO_NAME) $(PLUGINVERSION) dist/