Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6b09642
feat: magefile from demo plugin
fmartingr Feb 18, 2025
590eb03
feat: allow bulding other binaries
fmartingr Feb 19, 2025
805217d
refactor: better namespaces, split binaries into own target
fmartingr Feb 19, 2025
55dbf95
feat: add mage webapp:watch
fmartingr Feb 19, 2025
c2229e4
chore: make calls mage for migrated commands
fmartingr Feb 19, 2025
7a8f565
feat: make Logger public for custom targets
fmartingr Feb 19, 2025
c5556a2
feat: allow disable logging in cmd
fmartingr Feb 19, 2025
a1fe6d1
docs: added friendly error code for end users
fmartingr Feb 19, 2025
6a7059d
Added a README file
fmartingr Feb 19, 2025
8716c86
chore: fixes some log namespace names
fmartingr Feb 20, 2025
c15b04a
refactor: binaryname -> binarynameformat
fmartingr Feb 20, 2025
aa5b731
fix: also bundle on upload
fmartingr Feb 20, 2025
7a6b091
ci: updated to use mage
fmartingr Feb 20, 2025
5a65174
linted
fmartingr Feb 20, 2025
7021a92
fix: enhance plugin bundle deployment error handling
fmartingr Feb 24, 2025
ee252e9
fix: bug finder bugs
fmartingr Feb 24, 2025
4c75dca
refactor: use package for magefiles
fmartingr Feb 24, 2025
f421d97
docs: updated README
fmartingr Feb 24, 2025
6e02fbc
feat: include other assets in magefile plugin package
fmartingr Feb 25, 2025
b1cb565
fix: include .editorconfig in assets
fmartingr Mar 11, 2025
84e5a38
feat: assets
fmartingr Mar 24, 2025
56b9008
chore: removed verbose logger
fmartingr Mar 24, 2025
2eebd67
chore: removed aliases
fmartingr Mar 24, 2025
6514f3f
feat: specify mage version in ci
fmartingr Mar 24, 2025
312b451
fix: restore ci.yml but keep updating it from mage
fmartingr Mar 24, 2025
e99027e
fix: magefile in the correct folder
fmartingr Mar 24, 2025
1ccd244
fix: update gitignore to have ci.yml in the repo
fmartingr Mar 24, 2025
1bb4001
rename: plugin_magefile -> pluginmage
fmartingr Mar 24, 2025
5b54b63
Merge branch 'main' into feat/magefile
mattermost-build Mar 24, 2025
3593b70
chore: change default build platforms
fmartingr Mar 31, 2025
a398286
chore: remove fancy error urls
fmartingr Mar 31, 2025
7b395b3
fix: make deploy mage command
fmartingr Mar 31, 2025
2641008
Merge remote-tracking branch 'origin/main' into feat/magefile
fmartingr Apr 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ env:

jobs:
plugin-ci:
uses: mattermost/actions-workflows/.github/workflows/plugin-ci.yml@main
uses: mattermost/actions-workflows/.github/workflows/plugin-ci.yml@mage
secrets: inherit
with:
mage-version: v1.15.0
5 changes: 4 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ jobs:
go-version-file: mattermost-plugin-legal-hold/go.mod
cache: true

- name: ci/setup-node/for-plugin
- name: ci/install-mage
run: go install github.com/magefile/mage@latest

- name: ci/setup-node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version-file: "mattermost-plugin-legal-hold/.nvmrc"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/processor-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ jobs:
with:
go-version-file: go.mod

- name: Install Mage
run: go install github.com/magefile/mage@latest

- name: Build Processor
run: make processor
run: mage build:additionalBinaries

- name: Upload binaries to release
env:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ dist/
.idea/

processor/temp

# magefile included assets
/.golangci.yml
/.editorconfig
#/.github/workflows/ci.yml # Has to be committed to the repo for github to use it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just delete this line?

80 changes: 15 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,97 +67,47 @@ endif
## Builds the server, if it exists, for all supported architectures, unless MM_SERVICESETTINGS_ENABLEDEVELOPER is set.
.PHONY: server
server:
ifneq ($(HAS_SERVER),)
ifneq ($(MM_DEBUG),)
$(info DEBUG mode is on; to disable, unset MM_DEBUG)
endif
mkdir -p server/dist;
## Developer mode builds current architecture, CI builds only Linux AMD64, otherwise all unsupported architectures are built.
ifneq ($(MM_SERVICESETTINGS_ENABLEDEVELOPER),)
@echo Building plugin only for $(DEFAULT_GOOS)-$(DEFAULT_GOARCH) because MM_SERVICESETTINGS_ENABLEDEVELOPER is enabled
cd server && env CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-$(DEFAULT_GOOS)-$(DEFAULT_GOARCH);
else
cd server && env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-linux-amd64;
ifneq ($(IS_CI),true)
cd server && env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-linux-arm64;
cd server && env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-darwin-amd64;
cd server && env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-darwin-arm64;
cd server && env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o dist/plugin-windows-amd64.exe;
endif
endif
endif
mage build:server

## Builds the processor for all architectures.
.PHONY: processor
processor:
rm -rf $(PROCESSOR_DIR)/bin;
mkdir -p $(PROCESSOR_DIR)/bin;
cd $(PROCESSOR_DIR) && env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o bin/processor-v$(PLUGIN_VERSION)-linux-amd64;
cd $(PROCESSOR_DIR) && env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o bin/processor-v$(PLUGIN_VERSION)-linux-arm64;
cd $(PROCESSOR_DIR) && env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o bin/processor-v$(PLUGIN_VERSION)-darwin-amd64;
cd $(PROCESSOR_DIR) && env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o bin/processor-v$(PLUGIN_VERSION)-darwin-arm64;
cd $(PROCESSOR_DIR) && env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) $(GO_BUILD_GCFLAGS) -trimpath -o bin/processor-v$(PLUGIN_VERSION)-windows-amd64.exe;
mage build:additionalBinaries

## Ensures NPM dependencies are installed without having to run this all the time.
webapp/node_modules: $(wildcard webapp/package.json)
webapp/node_modules:
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) install
touch $@
mage webapp:dependencies
endif

## Builds the webapp, if it exists.
.PHONY: webapp
webapp: webapp/node_modules
webapp:
ifneq ($(HAS_WEBAPP),)
ifeq ($(MM_DEBUG),)
cd webapp && $(NPM) run build;
else
cd webapp && $(NPM) run debug;
endif
mage build:webapp
endif


## 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 ($(wildcard $(ASSETS_DIR)/.),)
cp -r $(ASSETS_DIR) dist/$(PLUGIN_ID)/
endif
ifneq ($(HAS_PUBLIC),)
cp -r public dist/$(PLUGIN_ID)/
endif
ifneq ($(HAS_SERVER),)
mkdir -p dist/$(PLUGIN_ID)/server
cp -r server/dist dist/$(PLUGIN_ID)/server/
endif
ifneq ($(HAS_WEBAPP),)
mkdir -p dist/$(PLUGIN_ID)/webapp
cp -r webapp/dist dist/$(PLUGIN_ID)/webapp/
endif
cd dist && tar -cvzf $(BUNDLE_NAME) $(PLUGIN_ID)
cp $(PROCESSOR_DIR)/bin/* dist/

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

## Builds and bundles the plugin.
.PHONY: dist
dist: server webapp processor bundle
dist:
mage build:all
mage build:bundle

## Builds and installs the plugin to a server.
.PHONY: deploy
deploy: dist
./build/bin/pluginctl deploy $(PLUGIN_ID) dist/$(BUNDLE_NAME)
deploy:
mage deploy:upload

## Builds and installs the plugin to a server, updating the webapp automatically when changed.
.PHONY: watch
watch: server bundle
ifeq ($(MM_DEBUG),)
cd webapp && $(NPM) run build:watch
else
cd webapp && $(NPM) run debug:watch
endif
watch:
mage webapp:watch

## Installs a previous built plugin with updated webpack assets to a server.
.PHONY: deploy-from-watch
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Masterminds/squirrel v1.5.4
github.com/gocarina/gocsv v0.0.0-20230616125104-99d496ca653d
github.com/jmoiron/sqlx v1.3.5
github.com/magefile/mage v1.15.0
github.com/mattermost/mattermost-plugin-api v0.1.4
github.com/mattermost/mattermost-server/v6 v6.0.0-20221012175353-8cb6718a9bcc
github.com/mattermost/mattermost/server/public v0.0.9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,8 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
Expand Down
14 changes: 14 additions & 0 deletions magefiles/binaries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import "github.com/mattermost/mattermost-plugin-legal-hold/pluginmage"

func init() {
// Register the processor binary
pluginmage.RegisterBinary(pluginmage.BinaryBuildConfig{
Name: "processor",
OutputPath: "./bin",
BinaryNameFormat: "processor-{{.Manifest.Version}}-{{.GOOS}}-{{.GOARCH}}",
WorkingDir: "./processor",
PackagePath: ".",
})
}
12 changes: 12 additions & 0 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build mage
// +build mage

// This file is maintained by the plugin sdk tooling.
// Please do not make changes to this file.

package main

import (
//mage:import
_ "github.com/mattermost/mattermost-plugin-legal-hold/pluginmage"
)
127 changes: 127 additions & 0 deletions pluginmage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Plugin Magefile Package

This package provides a comprehensive set of [Mage](https://magefile.org/) targets for building, developing, and deploying Mattermost plugins. It replaces the traditional Makefile-based build system with a more flexible and maintainable Go-based solution.

## Features

- 🔨 **Build System**
- Server binary compilation with multi-platform support
- Webapp (React/TypeScript) building and watching
- Plugin bundle creation
- Dependency management

- 🚀 **Development Tools**
- Hot-reload capability with `Watch` target
- Debug mode support via `MM_DEBUG`
- Custom logging with namespace support
- Local and remote deployment options

- 🛠️ **Deployment**
- Plugin upload via Mattermost API
- Enable/disable plugin management
- Support for both local socket and HTTP API connections

## Usage

### Basic Commands

```bash
# Show all available commands
mage
# Build everything (server, webapp, bundle)
mage build:all
# Watch webapp for changes (hot-reload)
mage webapp:watch
# Deploy to local Mattermost server
mage pluginctl:deploy
```

### Environment Variables

- `MM_DEBUG`: Enable debug mode for both Go and webapp builds
- `MM_SERVICESETTINGS_SITEURL`: Mattermost server URL for deployment
- `MM_ADMIN_TOKEN`: Admin access token for deployment
- `MM_ADMIN_USERNAME`/`MM_ADMIN_PASSWORD`: Alternative authentication for deployment
- `MM_LOCALSOCKETPATH`: Unix socket path for local mode deployment
- `GO_BUILD_FLAGS`: Additional Go build flags
- `ASSETS_DIR`: Custom assets directory path

### Development Workflow

1. Install dependencies:
```bash
mage webapp:dependencies
```

2. Start development mode:
```bash
mage webapp:watch
```

3. Deploy changes:
```bash
mage pluginctl:deploy
```

## Customizing

### Build more golang binaries

You can register additional binaries to build by calling `RegisterBinary` in a new file in the `magefiles` directory:

```go
// magefiles/binaries.go
func init() {
// Register additional binaries to build
plugin_magefile.RegisterBinary(plugin_magefile.BinaryBuildConfig{
BinaryName: "custom-tool",
PackagePath: "./tools/custom",
OutputPath: "./dist/tools",
Platforms: []plugin_magefile.BuildPlatform{
{GOOS: "linux", GOARCH: "amd64"},
},
})
}
```

## Architecture

### Package Structure

- `build.go`: Build configuration and binary building logic
- `webapp.go`: Webapp building and development tools
- `dist.go`: Bundle creation and packaging
- `pluginctl.go`: Deployment and plugin management
- `server.go`: Server binary compilation
- `cmd.go`: Command execution utilities
- `log.go`: Custom logging implementation
- `types.go`: Core types and configuration
- `init.go`: Package initialization and environment setup
- `assets/`: Embedded assets handling

### Logging

We include a custom logging output implementation that allows to easily spot the namespace and target of the log line by using the `namespace` and `target` as attributes:

```go
Logger.Info("Info",
"namespace", "my namespace",
"target", "my target")
```

### Running commands

We include a custom command runner that allows to run commands with the correct namespace and target:

```go
cmd := NewCmd("my namespace", "my target", map[string]string{
"ENV_VAR": "value",
})
if err := cmd.Run("npm", "run", "build"); err != nil {
return fmt.Errorf("failed to build webapp: %w", err)
}
```

# More information

- [Error codes](ERROR_CODES.md)
File renamed without changes.
23 changes: 23 additions & 0 deletions pluginmage/assets/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: ci
on:
schedule:
- cron: "0 0 * * *"
push:
branches:
- main
tags:
- "v*"
pull_request:

permissions:
contents: read

env:
IS_CI: true

jobs:
plugin-ci:
uses: mattermost/actions-workflows/.github/workflows/plugin-ci.yml@mage
secrets: inherit
with:
mage-version: v1.15.0
File renamed without changes.
6 changes: 6 additions & 0 deletions pluginmage/assets/assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package assets

import "embed"

//go:embed *.yml **/*/*.yml .editorconfig
var Assets embed.FS
12 changes: 12 additions & 0 deletions pluginmage/assets/magefiles/magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build mage
// +build mage

// This file is maintained by the plugin sdk tooling.
// Please do not make changes to this file.

package main

import (
//mage:import
_ "github.com/mattermost/mattermost-plugin-legal-hold/pluginmage"
)
Loading