diff --git a/.gitignore b/.gitignore index 9848779d86..7630814d9e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ dist tests-e2e/node_modules tests-e2e/cypress/screenshots tests-e2e/cypress/videos -.eslintcache \ No newline at end of file +.eslintcache + +webapp/src/manifest.js +server/manifest.go diff --git a/Makefile b/Makefile index 7872bffba9..31552b36d9 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ GO ?= $(shell command -v go 2> /dev/null) NPM ?= $(shell command -v npm 2> /dev/null) CURL ?= $(shell command -v curl 2> /dev/null) MM_DEBUG ?= -MANIFEST_FILE ?= plugin.json GOPATH ?= $(shell go env GOPATH) GO_TEST_FLAGS ?= -race GO_BUILD_FLAGS ?= @@ -39,7 +38,7 @@ apply: ## Runs eslint and golangci-lint .PHONY: check-style -check-style: webapp/node_modules +check-style: apply webapp/node_modules @echo Checking for style guide compliance ifneq ($(HAS_WEBAPP),) @@ -98,7 +97,7 @@ endif bundle: rm -rf dist/ mkdir -p dist/$(PLUGIN_ID) - cp $(MANIFEST_FILE) dist/$(PLUGIN_ID)/ + ./build/bin/manifest dist ifneq ($(wildcard $(ASSETS_DIR)/.),) cp -r $(ASSETS_DIR) dist/$(PLUGIN_ID)/ endif @@ -182,7 +181,7 @@ detach: setup-attach ## Runs any lints and unit tests defined for the server and webapp, if they exist. .PHONY: test -test: webapp/node_modules +test: apply webapp/node_modules ifneq ($(HAS_SERVER),) $(GO) test -v $(GO_TEST_FLAGS) ./server/... endif @@ -195,7 +194,7 @@ endif ## Creates a coverage report for the server code. .PHONY: coverage -coverage: webapp/node_modules +coverage: apply webapp/node_modules ifneq ($(HAS_SERVER),) $(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt ./server/... $(GO) tool cover -html=server/coverage.txt diff --git a/build/manifest/main.go b/build/manifest/main.go index 88d3c748d9..ebea3c6d49 100644 --- a/build/manifest/main.go +++ b/build/manifest/main.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "strings" "github.com/mattermost/mattermost-server/v5/model" "github.com/pkg/errors" @@ -43,6 +44,13 @@ export const version = manifest.version; export const pluginId = manifest.id; ` +// These build-time vars are read from shell commands and populated in ../setup.mk +var ( + BuildHashShort string + BuildTagLatest string + BuildTagCurrent string +) + func main() { if len(os.Args) <= 1 { panic("no cmd specified") @@ -76,6 +84,11 @@ func main() { panic("failed to apply manifest: " + err.Error()) } + case "dist": + if err := distManifest(manifest); err != nil { + panic("failed to write manifest to dist directory: " + err.Error()) + } + default: panic("unrecognized command: " + cmd) } @@ -101,6 +114,16 @@ func findManifest() (*model.Manifest, error) { return nil, errors.Wrap(err, "failed to parse manifest") } + // Update the manifest based on the state of the current commit + version := BuildTagCurrent + if version == "" { + version = BuildTagLatest + "+" + BuildHashShort + } + if strings.HasPrefix(version, "v") { + version = version[1:] + } + manifest.Version = version + return &manifest, nil } @@ -156,3 +179,17 @@ func applyManifest(manifest *model.Manifest) error { return nil } + +// distManifest writes the manifest file to the dist directory +func distManifest(manifest *model.Manifest) error { + manifestBytes, err := json.MarshalIndent(manifest, "", " ") + if err != nil { + return err + } + + if err := ioutil.WriteFile(fmt.Sprintf("dist/%s/plugin.json", manifest.Id), manifestBytes, 0600); err != nil { + return errors.Wrap(err, "failed to write plugin.json") + } + + return nil +} diff --git a/build/setup.mk b/build/setup.mk index 493b06fc4c..0db1bf8e42 100644 --- a/build/setup.mk +++ b/build/setup.mk @@ -4,8 +4,13 @@ ifeq ($(GO),) $(error "go is not available: see https://golang.org/doc/install") endif +# Gather build variables to inject into the manifest tool +BUILD_HASH_SHORT = $(shell git rev-parse --short HEAD) +BUILD_TAG_LATEST = $(shell git describe --tags --match 'v*' --abbrev=0) +BUILD_TAG_CURRENT = $(shell git tag --points-at HEAD) + # Ensure that the build tools are compiled. Go's caching makes this quick. -$(shell cd build/manifest && $(GO) build -o ../bin/manifest) +$(shell cd build/manifest && $(GO) build -ldflags '-X "main.BuildHashShort=$(BUILD_HASH_SHORT)" -X "main.BuildTagLatest=$(BUILD_TAG_LATEST)" -X "main.BuildTagCurrent=$(BUILD_TAG_CURRENT)"' -o ../bin/manifest) # Ensure that the deployment tools are compiled. Go's caching makes this quick. $(shell cd build/pluginctl && $(GO) build -o ../bin/pluginctl) diff --git a/plugin.json b/plugin.json index b00c92c02d..92a54d43bb 100644 --- a/plugin.json +++ b/plugin.json @@ -6,14 +6,14 @@ "support_url": "https://github.com/mattermost/mattermost-plugin-incident-management/issues", "release_notes_url": "https://github.com/mattermost/mattermost-plugin-incident-management/releases/tag/v1.2.0", "icon_path": "assets/incident_plugin_icon.svg", - "version": "1.2.0", "min_server_version": "5.28.0", "server": { "executables": { "linux-amd64": "server/dist/plugin-linux-amd64", "darwin-amd64": "server/dist/plugin-darwin-amd64", "windows-amd64": "server/dist/plugin-windows-amd64.exe" - } + }, + "executable": "" }, "webapp": { "bundle_path": "webapp/dist/main.js" diff --git a/server/manifest.go b/server/manifest.go deleted file mode 100644 index b7a7bf908f..0000000000 --- a/server/manifest.go +++ /dev/null @@ -1,45 +0,0 @@ -// This file is automatically generated. Do not modify it manually. - -package main - -import ( - "strings" - - "github.com/mattermost/mattermost-server/v5/model" -) - -var manifest *model.Manifest - -const manifestStr = ` -{ - "id": "com.mattermost.plugin-incident-management", - "name": "Incident Management", - "description": "This plugin allows users to coordinate and manage incidents within Mattermost.", - "homepage_url": "https://github.com/mattermost/mattermost-plugin-incident-management/", - "support_url": "https://github.com/mattermost/mattermost-plugin-incident-management/issues", - "release_notes_url": "https://github.com/mattermost/mattermost-plugin-incident-management/releases/tag/v1.2.0", - "icon_path": "assets/incident_plugin_icon.svg", - "version": "1.2.0", - "min_server_version": "5.28.0", - "server": { - "executables": { - "linux-amd64": "server/dist/plugin-linux-amd64", - "darwin-amd64": "server/dist/plugin-darwin-amd64", - "windows-amd64": "server/dist/plugin-windows-amd64.exe" - }, - "executable": "" - }, - "webapp": { - "bundle_path": "webapp/dist/main.js" - }, - "settings_schema": { - "header": "", - "footer": "", - "settings": [] - } -} -` - -func init() { - manifest = model.ManifestFromJson(strings.NewReader(manifestStr)) -} diff --git a/webapp/src/manifest.js b/webapp/src/manifest.js deleted file mode 100644 index e7a910ea14..0000000000 --- a/webapp/src/manifest.js +++ /dev/null @@ -1,36 +0,0 @@ -// This file is automatically generated. Do not modify it manually. - -const manifest = JSON.parse(` -{ - "id": "com.mattermost.plugin-incident-management", - "name": "Incident Management", - "description": "This plugin allows users to coordinate and manage incidents within Mattermost.", - "homepage_url": "https://github.com/mattermost/mattermost-plugin-incident-management/", - "support_url": "https://github.com/mattermost/mattermost-plugin-incident-management/issues", - "release_notes_url": "https://github.com/mattermost/mattermost-plugin-incident-management/releases/tag/v1.2.0", - "icon_path": "assets/incident_plugin_icon.svg", - "version": "1.2.0", - "min_server_version": "5.28.0", - "server": { - "executables": { - "linux-amd64": "server/dist/plugin-linux-amd64", - "darwin-amd64": "server/dist/plugin-darwin-amd64", - "windows-amd64": "server/dist/plugin-windows-amd64.exe" - }, - "executable": "" - }, - "webapp": { - "bundle_path": "webapp/dist/main.js" - }, - "settings_schema": { - "header": "", - "footer": "", - "settings": [] - } -} -`); - -export default manifest; -export const id = manifest.id; -export const version = manifest.version; -export const pluginId = manifest.id;