From 8cb9ff92df7b999bbd6d0a909b9f196737bc4387 Mon Sep 17 00:00:00 2001 From: Hanzei Date: Fri, 24 Aug 2018 23:07:03 +0200 Subject: [PATCH 1/2] Extract plugin version from manifest --- build/manifest/main.go | 28 ++++++++++++++++++++-------- build/setup.mk | 2 +- server/{plugin_id.go => manifest.go} | 1 + webapp/src/index.js | 4 ++-- webapp/src/manifest.js | 4 ++++ webapp/src/plugin_id.js | 1 - 6 files changed, 28 insertions(+), 12 deletions(-) rename server/{plugin_id.go => manifest.go} (67%) create mode 100644 webapp/src/manifest.js delete mode 100644 webapp/src/plugin_id.js diff --git a/build/manifest/main.go b/build/manifest/main.go index 4fc73c6..1869bdc 100644 --- a/build/manifest/main.go +++ b/build/manifest/main.go @@ -13,9 +13,13 @@ import ( const PluginIdGoFileTemplate = `package main const PluginId = "%s" +const PluginVersion = "%s" ` -const PluginIdJsFileTemplate = `export default '%s'; +const PluginIdJsFileTemplate = `export default { + PluginId: '%s', + PluginVersion: '%s', +}; ` func main() { @@ -30,9 +34,12 @@ func main() { cmd := os.Args[1] switch cmd { - case "plugin_id": + case "id": dumpPluginId(manifest) + case "version": + dumpPluginVersion(manifest) + case "has_server": if manifest.HasServer() { fmt.Printf("true") @@ -81,25 +88,30 @@ func dumpPluginId(manifest *model.Manifest) { fmt.Printf("%s", manifest.Id) } +// dumpPluginVersion writes the plugin version from the given manifest to standard out +func dumpPluginVersion(manifest *model.Manifest) { + fmt.Printf("%s", manifest.Version) +} + // applyManifest propagates the plugin_id into the server and webapp folders, as necessary func applyManifest(manifest *model.Manifest) error { if manifest.HasServer() { if err := ioutil.WriteFile( - "server/plugin_id.go", - []byte(fmt.Sprintf(PluginIdGoFileTemplate, manifest.Id)), + "server/manifest.go", + []byte(fmt.Sprintf(PluginIdGoFileTemplate, manifest.Id, manifest.Version)), 0644, ); err != nil { - return errors.Wrap(err, "failed to write server/plugin_id.go") + return errors.Wrap(err, "failed to write server/manifest.go") } } if manifest.HasWebapp() { if err := ioutil.WriteFile( - "webapp/src/plugin_id.js", - []byte(fmt.Sprintf(PluginIdJsFileTemplate, manifest.Id)), + "webapp/src/manifest.js", + []byte(fmt.Sprintf(PluginIdJsFileTemplate, manifest.Id, manifest.Version)), 0644, ); err != nil { - return errors.Wrap(err, "failed to open webapp/src/plugin_id.js") + return errors.Wrap(err, "failed to open webapp/src/manifest.js") } } diff --git a/build/setup.mk b/build/setup.mk index 7550a9d..fb44d6e 100644 --- a/build/setup.mk +++ b/build/setup.mk @@ -8,7 +8,7 @@ endif $(shell cd build/manifest && $(GO) build -o ../bin/manifest) # Extract the plugin id from the manifest. -PLUGIN_ID ?= $(shell build/bin/manifest plugin_id) +PLUGIN_ID ?= $(shell build/bin/manifest id) ifeq ($(PLUGIN_ID),) $(error "Cannot parse id from $(MANIFEST_FILE)") endif diff --git a/server/plugin_id.go b/server/manifest.go similarity index 67% rename from server/plugin_id.go rename to server/manifest.go index 4a5e2e6..fec0191 100644 --- a/server/plugin_id.go +++ b/server/manifest.go @@ -1,3 +1,4 @@ package main const PluginId = "com.mattermost.sample-plugin" +const PluginVersion = "0.0.1" diff --git a/webapp/src/index.js b/webapp/src/index.js index 7b7c624..5f2d4ca 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -1,4 +1,4 @@ -import PluginId from './plugin_id'; +import Manifest from './manifest'; export default class Plugin { // eslint-disable-next-line no-unused-vars @@ -7,4 +7,4 @@ export default class Plugin { } } -window.registerPlugin(PluginId, new Plugin()); +window.registerPlugin(Manifest.PluginId, new Plugin()); diff --git a/webapp/src/manifest.js b/webapp/src/manifest.js new file mode 100644 index 0000000..2b7d02f --- /dev/null +++ b/webapp/src/manifest.js @@ -0,0 +1,4 @@ +export default { + PluginId: 'com.mattermost.sample-plugin', + PluginVersion: '0.0.1', +}; diff --git a/webapp/src/plugin_id.js b/webapp/src/plugin_id.js deleted file mode 100644 index c7b1591..0000000 --- a/webapp/src/plugin_id.js +++ /dev/null @@ -1 +0,0 @@ -export default 'com.mattermost.sample-plugin'; From ed143d89d417dfcbf8f385bc632ba195e7288259 Mon Sep 17 00:00:00 2001 From: Hanzei Date: Tue, 18 Sep 2018 08:19:42 +0200 Subject: [PATCH 2/2] Include version into bundle name --- Makefile | 9 +++++---- build/setup.mk | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1fdeb20..b395721 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ 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 +BUNDLE_NAME = $(PLUGIN_ID)_$(PLUGIN_VERSION).tar.gz # Verify environment, and define PLUGIN_ID, HAS_SERVER and HAS_WEBAPP as needed. include build/setup.mk @@ -61,9 +62,9 @@ ifneq ($(HAS_WEBAPP),) mkdir -p dist/$(PLUGIN_ID)/webapp/dist; cp -r webapp/dist/* dist/$(PLUGIN_ID)/webapp/dist/; endif - cd dist && tar -cvzf $(PLUGIN_ID).tar.gz $(PLUGIN_ID) + cd dist && tar -cvzf $(BUNDLE_NAME) $(PLUGIN_ID) - @echo plugin built at: dist/$(PLUGIN_ID).tar.gz + @echo plugin built at: dist/$(BUNDLE_NAME) # dist builds and bundles the plugin .PHONY: dist @@ -81,7 +82,7 @@ ifneq ($(and $(MM_SERVICESETTINGS_SITEURL),$(MM_ADMIN_USERNAME),$(MM_ADMIN_PASSW (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/$(PLUGIN_ID).tar.gz 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" \ ) @@ -89,7 +90,7 @@ else ifneq ($(and $(MM_SERVICESETTINGS_SITEURL),$(MM_ADMIN_USERNAME),$(MM_ADMIN_ @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/$(PLUGIN_ID).tar.gz" > /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/.*),) diff --git a/build/setup.mk b/build/setup.mk index fb44d6e..e89e47b 100644 --- a/build/setup.mk +++ b/build/setup.mk @@ -13,6 +13,12 @@ ifeq ($(PLUGIN_ID),) $(error "Cannot parse id from $(MANIFEST_FILE)") endif +# Extract the plugin version from the manifest. +PLUGIN_VERSION ?= $(shell build/bin/manifest version) +ifeq ($(PLUGIN_VERSION),) + $(error "Cannot parse id from $(MANIFEST_FILE)") +endif + # Determine if a server is defined in the manifest. HAS_SERVER ?= $(shell build/bin/manifest has_server)