@@ -2,6 +2,9 @@ GO ?= $(shell command -v go 2> /dev/null)
22NPM ?= $(shell command -v npm 2> /dev/null)
33CURL ?= $(shell command -v curl 2> /dev/null)
44MANIFEST_FILE ?= plugin.json
5+ GOPATH ?= $(shell go env GOPATH)
6+ GO_TEST_FLAGS ?= -race
7+ GO_BUILD_FLAGS ?=
58MM_UTILITIES_DIR ?= ../mattermost-utilities
69
710export GO111MODULE =on
@@ -14,6 +17,11 @@ include build/setup.mk
1417
1518BUNDLE_NAME ?= $(PLUGIN_ID ) -$(PLUGIN_VERSION ) .tar.gz
1619
20+ # Include custom makefile, if present
21+ ifneq ($(wildcard build/custom.mk) ,)
22+ include build/custom.mk
23+ endif
24+
1725# # Checks the code style, tests, builds and bundles the plugin.
1826all : check-style test dist
1927
@@ -22,55 +30,34 @@ all: check-style test dist
2230apply :
2331 ./build/bin/manifest apply
2432
25- # # Runs govet and gofmt against all packages .
33+ # # Runs golangci-lint and eslint .
2634.PHONY : check-style
27- check-style : webapp/.npminstall gofmt govet
35+ check-style : webapp/.npminstall golangci-lint
2836 @echo Checking for style guide compliance
2937
3038ifneq ($(HAS_WEBAPP ) ,)
3139 cd webapp && npm run lint
3240endif
3341
34- # # Runs gofmt against all packages.
35- .PHONY : gofmt
36- gofmt :
37- ifneq ($(HAS_SERVER ) ,)
38- @echo Running gofmt
39- @for package in $$(go list ./server/...); do \
40- echo "Checking "$$package; \
41- files=$$(go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' $$package); \
42- if [ "$$files" ]; then \
43- gofmt_output=$$(gofmt -d -s $$files 2>&1); \
44- if [ "$$gofmt_output" ]; then \
45- echo "$$gofmt_output"; \
46- echo "Gofmt failure"; \
47- exit 1; \
48- fi; \
49- fi; \
50- done
51- @echo Gofmt success
52- endif
53-
54- # # Runs govet against all packages.
55- .PHONY : govet
56- govet :
57- ifneq ($(HAS_SERVER ) ,)
58- @echo Running govet
59- @# Workaroung because you can't install binaries without adding them to go.mod
60- env GO111MODULE=off $(GO) get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
61- $(GO) vet ./server/...
62- $(GO) vet -vettool=$(GOPATH)/bin/shadow ./server/...
63- @echo Govet success
64- endif
42+ # # Run golangci-lint on codebase.
43+ .PHONY : golangci-lint
44+ golangci-lint :
45+ @if ! [ -x " $$ (command -v golangci-lint)" ]; then \
46+ echo " golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions." ; \
47+ exit 1; \
48+ fi ; \
49+
50+ @echo Running golangci-lint
51+ golangci-lint run ./...
6552
6653# # Builds the server, if it exists, including support for multiple architectures.
6754.PHONY : server
6855server :
6956ifneq ($(HAS_SERVER ) ,)
7057 mkdir -p server/dist;
71- cd server && env GOOS=linux GOARCH=amd64 $(GO) build -o dist/plugin-linux-amd64;
72- cd server && env GOOS=darwin GOARCH=amd64 $(GO) build -o dist/plugin-darwin-amd64;
73- cd server && env GOOS=windows GOARCH=amd64 $(GO) build -o dist/plugin-windows-amd64.exe;
58+ cd server && env GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -o dist/plugin-linux-amd64;
59+ cd server && env GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -o dist/plugin-darwin-amd64;
60+ cd server && env GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -o dist/plugin-windows-amd64.exe;
7461endif
7562
7663# # Ensures NPM dependencies are installed without having to run this all the time.
@@ -87,6 +74,14 @@ ifneq ($(HAS_WEBAPP),)
8774 cd webapp && $(NPM) run build;
8875endif
8976
77+ # # Builds the webapp in debug mode, if it exists.
78+ .PHONY : webapp-debug
79+ webapp-debug : webapp/.npminstall
80+ ifneq ($(HAS_WEBAPP ) ,)
81+ cd webapp && \
82+ $(NPM) run debug;
83+ endif
84+
9085# # Generates a tar bundle of the plugin for install.
9186.PHONY : bundle
9287bundle :
@@ -116,64 +111,63 @@ endif
116111dist : apply server webapp bundle
117112
118113# # Installs the plugin to a (development) server.
114+ # # It uses the API if appropriate environment variables are defined,
115+ # # and otherwise falls back to trying to copy the plugin to a sibling mattermost-server directory.
119116.PHONY : deploy
120117deploy : dist
121- # # It uses the API if appropriate environment variables are defined,
122- # # or copying the files directly to a sibling mattermost-server directory.
123- ifneq ($(and $(MM_SERVICESETTINGS_SITEURL ) ,$(MM_ADMIN_USERNAME ) ,$(MM_ADMIN_PASSWORD ) ,$(CURL ) ) ,)
124- @echo "Installing plugin via API"
125- $(eval TOKEN := $(shell curl -i -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/login -d '{"login_id": "$(MM_ADMIN_USERNAME)", "password": "$(MM_ADMIN_PASSWORD)"}' | grep Token | cut -f2 -d' ' 2> /dev/null))
126- @curl -s -H "Authorization: Bearer $(TOKEN)" -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins -F "plugin=@dist/$(BUNDLE_NAME)" -F "force=true" > /dev/null && \
127- curl -s -H "Authorization: Bearer $(TOKEN)" -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID)/enable > /dev/null && \
128- echo "OK." || echo "Sorry, something went wrong."
129- else ifneq ($(wildcard ../mattermost-server/.*),)
130- @echo "Installing plugin via filesystem. Server restart and manual plugin enabling required"
131- mkdir -p ../mattermost-server/plugins
132- tar -C ../mattermost-server/plugins -zxvf dist/$(BUNDLE_NAME)
133- else
134- @echo "No supported deployment method available. Install plugin manually."
135- endif
118+ ./build/bin/deploy $(PLUGIN_ID ) dist/$(BUNDLE_NAME )
119+
120+ .PHONY : debug-deploy
121+ debug-deploy : debug-dist deploy
122+
123+ .PHONY : debug-dist
124+ debug-dist : apply server webapp-debug bundle
136125
137126# # Runs any lints and unit tests defined for the server and webapp, if they exist.
138127.PHONY : test
139128test : webapp/.npminstall
140129ifneq ($(HAS_SERVER ) ,)
141- $(GO) test -race -v ./server/...
130+ $(GO) test -v $(GO_TEST_FLAGS) ./server/...
142131endif
143132ifneq ($(HAS_WEBAPP ) ,)
144- cd webapp && $(NPM) run fix;
133+ cd webapp && $(NPM) run fix && $(NPM) run test ;
145134endif
146135
147136# # Creates a coverage report for the server code.
148137.PHONY : coverage
149138coverage : webapp/.npminstall
150139ifneq ($(HAS_SERVER ) ,)
151- $(GO) test -race -coverprofile=server/coverage.txt ./server/...
140+ $(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt ./server/...
152141 $(GO) tool cover -html=server/coverage.txt
153142endif
154143
155144# # Extract strings for translation from the source code.
156145.PHONY : i18n-extract
157- i18n-extract :
146+ i18n-extract :
158147ifneq ($(HAS_WEBAPP ) ,)
159- @[[ -d $(MM_UTILITIES_DIR) ]] || echo "You must clone github.com/mattermost/mattermost-utilities repo in .. to use this command"
160- @[[ -d $(MM_UTILITIES_DIR) ]] && cd $(MM_UTILITIES_DIR) && npm install && npm run babel && node mmjstool/build/index.js i18n extract-webapp --webapp-dir ../mattermost-plugin-demo/webapp
148+ ifeq ($(HAS_MM_UTILITIES ) ,)
149+ @echo "You must clone github.com/mattermost/mattermost-utilities repo in .. to use this command"
150+ else
151+ cd $(MM_UTILITIES_DIR) && npm install && npm run babel && node mmjstool/build/index.js i18n extract-webapp --webapp-dir $(PWD)/webapp
152+ endif
161153endif
162154
163155# # Clean removes all build artifacts.
164156.PHONY : clean
165157clean :
166158 rm -fr dist/
167159ifneq ($(HAS_SERVER ) ,)
160+ rm -fr server/coverage.txt
168161 rm -fr server/dist
169162endif
170163ifneq ($(HAS_WEBAPP ) ,)
171164 rm -fr webapp/.npminstall
165+ rm -fr webapp/junit.xml
172166 rm -fr webapp/dist
173167 rm -fr webapp/node_modules
174168endif
175169 rm -fr build/bin/
176170
177- # Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
171+ # Help documentation à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
178172help :
179- @cat Makefile | grep -v ' \.PHONY' | grep -v ' \help:' | grep -B1 -E ' ^[a-zA-Z0-9_.-]+:.*' | sed -e " s/:.*//" | sed -e " s/^## //" | grep -v ' \-\-' | sed ' 1!G;h;$$!d' | awk ' NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
173+ @cat Makefile | grep -v ' \.PHONY' | grep -v ' \help:' | grep -B1 -E ' ^[a-zA-Z0-9_.-]+:.*' | sed -e " s/:.*//" | sed -e " s/^## //" | grep -v ' \-\-' | sed ' 1!G;h;$$!d' | awk ' NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
0 commit comments