fix: make template build, lint and test cleanly out of the box

This commit is contained in:
2026-09-25 09:05:40 +03:00
parent f3452876da
commit f0e09ef8c9
24 changed files with 128 additions and 244 deletions
+7 -62
View File
@@ -1,58 +1,18 @@
# Include custome targets and environment variables here
# Include custom targets and environment variables here
default: all
# If there's no MM_RUDDER_PLUGINS_PROD, add DEV data
RUDDER_WRITE_KEY = ""
ifdef MM_RUDDER_PLUGINS_PROD
RUDDER_WRITE_KEY = $(MM_RUDDER_PLUGINS_PROD)
endif
BUILD_DATE = $(shell date -u)
BUILD_HASH = $(shell git rev-parse HEAD)
BUILD_HASH_SHORT = $(shell git rev-parse --short HEAD)
LDFLAGS += -X "plugin.buildHash=$(BUILD_HASH)"
LDFLAGS+= -X "plugin.isDebug=$(MM_DEBUG)"
LDFLAGS += -X "plugin.rudderWriteKey=$(MM_RUDDER_CALLS_PROD)"
LDFLAGS += -X "plugin.rudderDataplaneURL=$(MM_RUDDER_DATAPLANE_URL)"
GO_MODULE := $(shell $(GO) list -m)
BUILD_HASH = $(shell git rev-parse HEAD 2>/dev/null)
LDFLAGS += -X "$(GO_MODULE)/server/plugin.buildHash=$(BUILD_HASH)"
LDFLAGS += -X "$(GO_MODULE)/server/plugin.rudderWriteKey=$(MM_RUDDER_CALLS_PROD)"
LDFLAGS += -X "$(GO_MODULE)/server/plugin.rudderDataplaneURL=$(MM_RUDDER_DATAPLANE_URL)"
GO_BUILD_FLAGS += -ldflags '$(LDFLAGS)'
GO_TEST_FLAGS += -ldflags '$(LDFLAGS)'
MM_SERVER_PATH ?= ${PWD}/../mattermost-server
export MM_SERVER_PATH
## Generates mock golang interfaces for testing
.PHONY: mock
mock:
ifneq ($(HAS_SERVER),)
go install github.com/golang/mock/mockgen@v1.6.0
mockgen -destination server/mocks/mock_proxy/mock_expand_getter.go git.wilix.dev/loop/loop-plugin-starter-template/server/proxy ExpandGetter
mockgen -destination server/mocks/mock_upstream/mock_upstream.go git.wilix.dev/loop/loop-plugin-starter-template/upstream Upstream
mockgen -destination server/mocks/mock_store/mock_appstore.go git.wilix.dev/loop/loop-plugin-starter-template/server/store AppStore
mockgen -destination server/mocks/mock_store/mock_session.go git.wilix.dev/loop/loop-plugin-starter-template/server/store SessionStore
endif
## Generates mock golang interfaces for testing
.PHONY: clean_mock
clean_mock:
ifneq ($(HAS_SERVER),)
rm -rf ./server/mocks
endif
## Run Go REST API system tests
.PHONY: test-rest-api
test-rest-api: dist
@echo Running REST API tests
ifneq ($(RUN),)
PLUGIN_BUNDLE=$(shell pwd)/dist/$(BUNDLE_NAME) $(GO) test -v $(GO_TEST_FLAGS) ./test/restapitest --run $(RUN)
else
PLUGIN_BUNDLE=$(shell pwd)/dist/$(BUNDLE_NAME) $(GO) test -v $(GO_TEST_FLAGS) ./test/restapitest
endif
## Extract new translation messages
.PHONY: i18n-extract-server
i18n-extract-server:
@goi18n extract -format json -outdir assets/i18n/ server/ utils/ apps/ cmd/ upstream/
@goi18n extract -format json -outdir assets/i18n/ server/
@for x in assets/i18n/active.*.json; do echo $$x | sed 's/active/translate/' | sed 's/^/touch /' | bash; done
@goi18n merge -format json -outdir assets/i18n/ assets/i18n/active.*.json
@echo "Please update your assets/i18n/translate.*.json files and execute \"make i18n-merge-server\""
@@ -65,18 +25,3 @@ i18n-merge-server:
@goi18n merge -format json -outdir assets/i18n/ assets/i18n/active.*.json assets/i18n/translate.*.json
@rm -f assets/i18n/translate.*.json
@echo "Translations merged, please verify your "git diff" before you submit the changes"
## Run a simple Mattermost Server
.PHONY: dev_server
dev_server:
cd dev && docker-compose up mattermost db
## Run the hello-world app
.PHONY: run-example-hello-4000
run-example-hello-4000:
cd test/hello-world && go run .
## Run the test app
.PHONY: run-test-app-8081
run-test-app-8081:
cd test/app && go run .
+1 -1
View File
@@ -108,7 +108,7 @@ func findManifest() (*model.Manifest, error) {
if err != nil {
return nil, errors.Wrapf(err, "failed to open %s", manifestFilePath)
}
defer manifestFile.Close()
defer func() { _ = manifestFile.Close() }()
// Re-decode the manifest, disallowing unknown fields. When we write the manifest back out,
// we don't want to accidentally clobber anything we won't preserve.
+1 -1
View File
@@ -125,7 +125,7 @@ func deploy(ctx context.Context, client *model.Client4, pluginID, bundlePath str
if err != nil {
return fmt.Errorf("failed to open %s: %w", bundlePath, err)
}
defer pluginBundle.Close()
defer func() { _ = pluginBundle.Close() }()
log.Print("Uploading plugin via API.")
_, _, err = client.UploadPluginForced(ctx, pluginBundle)