Skip to content

Commit

Permalink
Merge pull request #29 from hanzei/downstream
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyhulen committed Oct 23, 2018
2 parents 5a6afd9 + 78c69b1 commit d014265
Show file tree
Hide file tree
Showing 397 changed files with 8,067 additions and 16,995 deletions.
29 changes: 1 addition & 28 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

# Build
/coverage.txt
/plugin.exe
/mattermost-zoom-plugin*.tar.gz
/dist
server/vendor
node_modules
.npminstall
webapp/dist

# Mac
*.swp
.DS_Store
dist
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: go
go:
- "1.11.x"

install:
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

script:
- make check-style
- make test
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

The changelog can be found at https://github.com/mattermost/mattermost-plugin-autolink
/releases.
214 changes: 144 additions & 70 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,89 +1,163 @@
.PHONY: build test run clean stop check-style gofmt dist
GO ?= $(shell command -v go 2> /dev/null)
DEP ?= $(shell command -v dep 2> /dev/null)
NPM ?= $(shell command -v npm 2> /dev/null)
HTTP ?= $(shell command -v http 2> /dev/null)
CURL ?= $(shell command -v curl 2> /dev/null)
MANIFEST_FILE ?= plugin.json

MKFILE_PATH=$(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_DIR_NAME=$(notdir $(patsubst %/,%,$(dir $(MKFILE_PATH))))
PLUGIN_NAME=$(CURRENT_DIR_NAME)
GOOS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
GOARCH=amd64
# Verify environment, and define PLUGIN_ID, PLUGIN_VERSION, HAS_SERVER and HAS_WEBAPP as needed.
include build/setup.mk

all: dist
BUNDLE_NAME ?= $(PLUGIN_ID)-$(PLUGIN_VERSION).tar.gz

check-style: gofmt
# all, the default target, tests, builds and bundles the plugin.
all: check-style test dist

# apply propagates the plugin id into the server/ and webapp/ folders as required.
.PHONY: apply
apply:
./build/bin/manifest apply

.PHONY: check-style
check-style: server/.depensure webapp/.npminstall gofmt govet
@echo Checking for style guide compliance

gofmt:
@echo Running GOFMT
ifneq ($(HAS_WEBAPP),)
cd webapp && npm run lint
endif

.PHONY: gofmt
gofmt:
ifneq ($(HAS_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 -d -s $$files 2>&1); \
if [ "$$gofmt_output" ]; then \
echo "$$gofmt_output"; \
echo "gofmt failure"; \
echo "Gofmt failure"; \
exit 1; \
fi; \
fi; \
done
@echo "gofmt success"; \

test:
go test -v -coverprofile=coverage.txt ./...

vendor: server/Gopkg.lock
@echo Run this to updated the go lang dependencies after a major release
cd server && dep ensure -update

dist: check-style
@echo Building plugin

# Clean old dist
rm -rf dist
rm -rf webapp/dist
rm -f server/plugin.exe

# Build files from server
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

# Copy plugin files
mkdir -p dist/$(PLUGIN_NAME)/
cp plugin.json dist/$(PLUGIN_NAME)/

# Copy server executables & compress plugin
mkdir -p dist/$(PLUGIN_NAME)/server
mv dist/intermediate/plugin_darwin_amd64 dist/$(PLUGIN_NAME)/server/plugin.exe
cd dist && tar -zcvf $(PLUGIN_NAME)-darwin-amd64.tar.gz $(PLUGIN_NAME)/*
mv dist/intermediate/plugin_linux_amd64 dist/$(PLUGIN_NAME)/server/plugin.exe
cd dist && tar -zcvf $(PLUGIN_NAME)-linux-amd64.tar.gz $(PLUGIN_NAME)/*
mv dist/intermediate/plugin_windows_amd64.exe dist/$(PLUGIN_NAME)/server/plugin.exe
cd dist && tar -zcvf $(PLUGIN_NAME)-windows-amd64.tar.gz $(PLUGIN_NAME)/*

# Clean up temp files
rm -rf dist/$(PLUGIN_NAME)
rm -rf dist/intermediate

@echo MacOS X plugin built at: dist/$(PLUGIN_NAME)-darwin-amd64.tar.gz
@echo Linux plugin built at: dist/$(PLUGIN_NAME)-linux-amd64.tar.gz
@echo Windows plugin built at: dist/$(PLUGIN_NAME)-windows-amd64.tar.gz

@echo Gofmt success
endif

.PHONY: govet
govet:
ifneq ($(HAS_SERVER),)
@echo Running govet
@$(GO) vet $$(go list ./server/...) || exit 1
@echo Govet success
endif

# server/.depensure ensures the server dependencies are installed
server/.depensure:
ifneq ($(HAS_SERVER),)
cd server && $(DEP) ensure
touch $@
endif

# server builds the server, if it exists, including support for multiple architectures
.PHONY: server
server: server/.depensure
ifneq ($(HAS_SERVER),)
mkdir -p server/dist;
cd server && env GOOS=linux GOARCH=amd64 $(GO) build -o dist/plugin-linux-amd64;
cd server && env GOOS=darwin GOARCH=amd64 $(GO) build -o dist/plugin-darwin-amd64;
cd server && env GOOS=windows GOARCH=amd64 $(GO) build -o dist/plugin-windows-amd64.exe;
endif

# webapp/.npminstall ensures NPM dependencies are installed without having to run this all the time
webapp/.npminstall:
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) install
touch $@
endif

# webapp builds the webapp, if it exists
.PHONY: webapp
webapp: webapp/.npminstall
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) run build;
endif

# bundle generates a tar bundle of the plugin for install
.PHONY: bundle
bundle:
rm -rf dist/
mkdir -p dist/$(PLUGIN_ID)
cp $(MANIFEST_FILE) dist/$(PLUGIN_ID)/
ifneq ($(HAS_SERVER),)
mkdir -p dist/$(PLUGIN_ID)/server/dist;
cp -r server/dist/* dist/$(PLUGIN_ID)/server/dist/;
endif
ifneq ($(HAS_WEBAPP),)
mkdir -p dist/$(PLUGIN_ID)/webapp/dist;
cp -r webapp/dist/* dist/$(PLUGIN_ID)/webapp/dist/;
endif
cd dist && tar -cvzf $(BUNDLE_NAME) $(PLUGIN_ID)

@echo plugin built at: dist/$(BUNDLE_NAME)

# dist builds and bundles the plugin
.PHONY: dist
dist: apply \
server \
webapp \
bundle

# 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: dist
cp dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH).tar.gz ../mattermost-server/plugins/
rm -rf ../mattermost-server/plugins/$(PLUGIN_NAME)
tar -C ../mattermost-server/plugins/ -zxvf ../mattermost-server/plugins/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH).tar.gz

run: .npminstall
@echo Not yet implemented

stop:
@echo Not yet implemented

ifneq ($(and $(MM_SERVICESETTINGS_SITEURL),$(MM_ADMIN_USERNAME),$(MM_ADMIN_PASSWORD),$(HTTP)),)
@echo "Installing plugin via API"
(TOKEN=`http --print h POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/login login_id=$(MM_ADMIN_USERNAME) password=$(MM_ADMIN_PASSWORD) | grep Token | cut -f2 -d' '` && \
http --print b GET $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/me Authorization:"Bearer $$TOKEN" && \
http --print b DELETE $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID) Authorization:"Bearer $$TOKEN" && \
http --print b --check-status --form POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins plugin@dist/$(BUNDLE_NAME) Authorization:"Bearer $$TOKEN" && \
http --print b POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID)/enable Authorization:"Bearer $$TOKEN" && \
http --print b POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/logout Authorization:"Bearer $$TOKEN" \
)
else ifneq ($(and $(MM_SERVICESETTINGS_SITEURL),$(MM_ADMIN_USERNAME),$(MM_ADMIN_PASSWORD),$(CURL)),)
@echo "Installing plugin via API"
$(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))
@curl -s -H "Authorization: Bearer $(TOKEN)" -X DELETE $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID) > /dev/null
@curl -s -H "Authorization: Bearer $(TOKEN)" -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins -F "plugin=@dist/$(BUNDLE_NAME)" > /dev/null && \
curl -s -H "Authorization: Bearer $(TOKEN)" -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID)/enable > /dev/null && \
echo "OK." || echo "Sorry, something went wrong."
else ifneq ($(wildcard ../mattermost-server/.*),)
@echo "Installing plugin via filesystem. Server restart and manual plugin enabling required"
mkdir -p ../mattermost-server/plugins
tar -C ../mattermost-server/plugins -zxvf dist/$(BUNDLE_NAME)
else
@echo "No supported deployment method available. Install plugin manually."
endif

# test runs any lints and unit tests defined for the server and webapp, if they exist
.PHONY: test
test: server/.depensure webapp/.npminstall
ifneq ($(HAS_SERVER),)
cd server && $(GO) test -race -v -coverprofile=coverage.txt ./...
endif
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) run fix;
endif

# clean removes all build artifacts
.PHONY: clean
clean:
@echo Cleaning plugin

rm -rf dist
rm -rf webapp/dist
rm -rf webapp/node_modules
rm -rf webapp/.npminstall
rm -f server/plugin.exe
rm -fr dist/
ifneq ($(HAS_SERVER),)
rm -fr server/dist
rm -fr server/.depensure
endif
ifneq ($(HAS_WEBAPP),)
rm -fr webapp/.npminstall
rm -fr webapp/dist
rm -fr webapp/node_modules
endif
rm -fr build/bin/
1 change: 1 addition & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
Empty file added build/manifest/.gitignore
Empty file.
Loading

0 comments on commit d014265

Please sign in to comment.