Skip to content

Commit

Permalink
MI-321: Update the plugin boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
chetanyakan committed Feb 11, 2019
1 parent 98e2820 commit 50baf5b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 127 deletions.
5 changes: 1 addition & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ jobs:
name: Restore NPM dependencies cache
key: dependency-cache-{{ checksum "./webapp/package-lock.json" }}
- type: shell
name: 'Build artifacts'
name: 'Check for style guide compliance, run test cases and build artifacts'
command: make dist
environment:
TERM: dumb
- run:
name: Test
command: make test
- save_cache:
name: Save Golang dependencies cache
key: dependency-cache-{{ checksum "./server/glide.lock" }}
Expand Down
89 changes: 35 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,39 @@ HAS_SERVER=$(shell if [ "$(shell grep -E '[\^"]server["][ ]*[:]' $(MANIFEST_FILE
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`
BLACK=`tput -Txterm setaf 0`
RED=`tput -Txterm setaf 1`
GREEN=`tput -Txterm setaf 2`
YELLOW=`tput -Txterm setaf 3`
BLUE=`tput -Txterm setaf 4`
MAGENTA=`tput -Txterm setaf 5`
CYAN=`tput -Txterm setaf 6`
WHITE=`tput -Txterm setaf 7`
BOLD=`tput bold`
INVERSE=`tput rev`
RESET=`tput sgr0`
BOLD=`tput -Txterm bold`
INVERSE=`tput -Txterm rev`
RESET=`tput -Txterm sgr0`
.PHONY: default pre-run test clean check-style check-js check-go govet golint gofmt .distclean dist fix format fix-js fix-go github-release
.PHONY: default 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: check-style test dist
default: dist
pre-run:
setup-plugin:
ifneq ($(HAS_WEBAPP),)
@echo "export const PLUGIN_NAME = '`echo $(PLUGINNAME)`';\
" > webapp/src/constants/manifest.js
@echo "export const PLUGIN_NAME = '`echo $(PLUGINNAME)`';" > webapp/src/constants/manifest.js
endif
ifneq ($(HAS_SERVER),)
@echo "package config\n\nconst (\n\
PluginName = \""`echo $(PLUGINNAME)`"\"\n)" > server/config/manifest.go
@echo "package config\n\nconst (\n\tPluginName = \""`echo $(PLUGINNAME)`"\"\n)" > server/config/manifest.go
endif
github-release:
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: .npminstall vendor
@echo ${BOLD}"Checking for style guide compliance\n"${RESET}
@make check-js
@make check-go
check-style: check-js check-go
check-js:
ifneq ($(HAS_WEBAPP),)
Expand All @@ -65,11 +59,7 @@ check-go: server 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}${RED}
@echo ${BOLD}Running GOVET${RESET}
@cd server
$(eval PKGS := $(shell go list ./... | grep -v /vendor/))
@$(GO) vet $(PKGS)
Expand All @@ -78,11 +68,7 @@ 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}${RED}
@echo ${BOLD}Running GOLINT${RESET}
@cd server
$(eval PKGS := $(shell go list ./... | grep -v /vendor/))
@touch $(TMPFILEGOLINT)
Expand All @@ -91,14 +77,12 @@ ifneq ($(HAS_SERVER),)
done
@grep -Ev "^$$" $(TMPFILEGOLINT) || true
@if [ "$$(grep -Ev "^$$" $(TMPFILEGOLINT) | wc -l)" -gt "0" ]; then \
rm -f $(TMPFILEGOLINT); echo "golint failure\n"${RESET}; exit 1; else \
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
fix: fix-js fix-go
format: fix-js fix-go
fix-js:
ifneq ($(HAS_WEBAPP),)
Expand All @@ -109,10 +93,6 @@ 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 giles${RESET}
@cd server
@find ./ -type f -name "*.go" -not -path "./server/vendor/*" -exec goimports -w {} \;
Expand All @@ -121,14 +101,14 @@ endif
gofmt:
ifneq ($(HAS_SERVER),)
@echo ${BOLD}Running GOFMT${RESET}${RED}
@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 "gofmt failure\n"; \
echo ${RED}"gofmt failure\n"${RESET}; \
exit 1; \
fi; \
fi; \
Expand Down Expand Up @@ -156,31 +136,32 @@ ifneq ($(HAS_SERVER),)
@echo "\n"
endif
dist: .distclean check-style $(MANIFEST_FILE)
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/
else ifneq ($(HAS_SERVER),)
mkdir -p dist/$(PLUGINNAME)/
endif
ifneq ($(HAS_SERVER),)
# Build files from 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
endif
mkdir -p dist/$(PLUGINNAME)/server
# Copy plugin files
cp $(MANIFEST_FILE) dist/$(PLUGINNAME)/
endif
# Compress plugin
ifneq ($(HAS_SERVER),)
# 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)/*
Expand Down
6 changes: 3 additions & 3 deletions server/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/glide.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package: github.com/Brightscout/mattermost-plugin-boilerplate/server
import:
- package: github.com/mattermost/mattermost-server
version: ~5.6.0
version: ~5.7.1
subpackages:
- plugin
- package: golang.org/x/tools/cmd/vet
Expand Down
Loading

0 comments on commit 50baf5b

Please sign in to comment.