Skip to content

Commit

Permalink
dist: build linux/darwin arm64 targets (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Tadeu Panato Junior committed Nov 23, 2021
1 parent 6434cf7 commit d3f93b6
Show file tree
Hide file tree
Showing 10 changed files with 699 additions and 302 deletions.
8 changes: 5 additions & 3 deletions Makefile
Expand Up @@ -55,9 +55,11 @@ golangci-lint:
server:
ifneq ($(HAS_SERVER),)
mkdir -p server/dist;
cd server && env GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -o dist/plugin-linux-amd64;
cd server && env GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -o dist/plugin-darwin-amd64;
cd server && env GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -o dist/plugin-windows-amd64.exe;
cd server && env GOOS=linux GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-amd64;
cd server && env GOOS=linux GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-linux-arm64;
cd server && env GOOS=darwin GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-amd64;
cd server && env GOOS=darwin GOARCH=arm64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-darwin-arm64;
cd server && env GOOS=windows GOARCH=amd64 $(GO) build $(GO_BUILD_FLAGS) -trimpath -o dist/plugin-windows-amd64.exe;
endif

## Ensures NPM dependencies are installed without having to run this all the time.
Expand Down
21 changes: 11 additions & 10 deletions build/deploy/main.go
Expand Up @@ -8,9 +8,10 @@ import (
"os"
"path/filepath"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mholt/archiver/v3"
"github.com/pkg/errors"

"github.com/mattermost/mattermost-server/v6/model"
)

func main() {
Expand Down Expand Up @@ -52,9 +53,9 @@ func deploy() error {
if adminUsername != "" && adminPassword != "" {
client := model.NewAPIv4Client(siteURL)
log.Printf("Authenticating as %s against %s.", adminUsername, siteURL)
_, resp := client.Login(adminUsername, adminPassword)
if resp.Error != nil {
return errors.Wrapf(resp.Error, "failed to login as %s", adminUsername)
_, _, err := client.Login(adminUsername, adminPassword)
if err != nil {
return errors.Wrapf(err, "failed to login as %s", adminUsername)
}

return uploadPlugin(client, pluginID, bundlePath)
Expand Down Expand Up @@ -83,15 +84,15 @@ func uploadPlugin(client *model.Client4, pluginID, bundlePath string) error {
defer pluginBundle.Close()

log.Print("Uploading plugin via API.")
_, resp := client.UploadPluginForced(pluginBundle)
if resp.Error != nil {
return errors.Wrap(resp.Error, "failed to upload plugin bundle")
_, _, err = client.UploadPluginForced(pluginBundle)
if err != nil {
return errors.Wrap(err, "failed to upload plugin bundle")
}

log.Print("Enabling plugin.")
_, resp = client.EnablePlugin(pluginID)
if resp.Error != nil {
return errors.Wrap(resp.Error, "Failed to enable plugin")
_, err = client.EnablePlugin(pluginID)
if err != nil {
return errors.Wrap(err, "Failed to enable plugin")
}

return nil
Expand Down
5 changes: 4 additions & 1 deletion build/manifest/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions go.mod
Expand Up @@ -3,8 +3,8 @@ module github.com/mattermost/mattermost-plugin-aws-SNS
go 1.12

require (
github.com/mattermost/mattermost-plugin-api v0.0.12
github.com/mattermost/mattermost-server/v5 v5.28.1
github.com/mholt/archiver/v3 v3.3.0
github.com/mattermost/mattermost-plugin-api v0.0.21
github.com/mattermost/mattermost-server/v6 v6.0.3
github.com/mholt/archiver/v3 v3.5.0
github.com/pkg/errors v0.9.1
)
921 changes: 652 additions & 269 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion plugin.json
Expand Up @@ -7,11 +7,13 @@
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-aws-SNS/releases/tag/v1.2.0",
"icon_path": "assets/icon.svg",
"version": "1.2.0",
"min_server_version": "5.2.0",
"min_server_version": "5.37.0",
"server": {
"executables": {
"linux-amd64": "server/dist/plugin-linux-amd64",
"linux-arm64": "server/dist/plugin-linux-arm64",
"darwin-amd64": "server/dist/plugin-darwin-amd64",
"darwin-arm64": "server/dist/plugin-darwin-arm64",
"windows-amd64": "server/dist/plugin-windows-amd64.exe"
},
"executable": ""
Expand Down
16 changes: 8 additions & 8 deletions server/command.go
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"strings"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"
"github.com/pkg/errors"

"github.com/mattermost/mattermost-plugin-api/experimental/command"
Expand Down Expand Up @@ -49,7 +49,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo

if cmd != awsSNSCmd {
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
ResponseType: model.CommandResponseTypeEphemeral,
Text: fmt.Sprintf("Unknown Command: " + cmd),
}, nil
}
Expand All @@ -59,7 +59,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
return p.listTopicsToChannel(), nil
default:
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
ResponseType: model.CommandResponseTypeEphemeral,
Text: fmt.Sprintf("Unknown Action: " + action),
}, nil
}
Expand All @@ -72,21 +72,21 @@ func (p *Plugin) listTopicsToChannel() *model.CommandResponse {
if err != nil {
p.API.LogError("Failed to Get from KV Store")
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
ResponseType: model.CommandResponseTypeEphemeral,
Text: err.Error(),
}
}
if val == nil {
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
ResponseType: model.CommandResponseTypeEphemeral,
Text: "No Topics are subscribed by the configured channel",
}
}
unMarshalErr := json.Unmarshal(val, &topics)
if unMarshalErr != nil {
p.API.LogError("Failed to Unmarshal")
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
ResponseType: model.CommandResponseTypeEphemeral,
Text: unMarshalErr.Error(),
}
}
Expand All @@ -95,7 +95,7 @@ func (p *Plugin) listTopicsToChannel() *model.CommandResponse {
resp = resp + "* " + topicName + "\n"
}
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
ResponseType: model.CommandResponseTypeInChannel,
Text: resp,
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/main.go
@@ -1,7 +1,7 @@
package main

import (
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v6/plugin"
)

func main() {
Expand Down
1 change: 1 addition & 0 deletions server/manifest.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions server/plugin.go
Expand Up @@ -10,13 +10,16 @@ import (
"strings"
"sync"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/pkg/errors"

pluginapi "github.com/mattermost/mattermost-plugin-api"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"
)

type Plugin struct {
plugin.MattermostPlugin
client *pluginapi.Client

// configurationLock synchronizes access to the configuration.
configurationLock sync.RWMutex
Expand All @@ -33,6 +36,8 @@ type Plugin struct {
const topicsListPrefix = "topicsInChannel_"

func (p *Plugin) OnActivate() error {
p.client = pluginapi.NewClient(p.API, p.Driver)

siteURL := p.API.GetConfig().ServiceSettings.SiteURL
if siteURL == nil || *siteURL == "" {
return errors.New("siteURL is not set. Please set a siteURL and restart the plugin")
Expand All @@ -57,12 +62,12 @@ func (p *Plugin) OnActivate() error {
}
p.TeamID = team.Id

botID, err := p.Helpers.EnsureBot(&model.Bot{
botID, err := p.client.Bot.EnsureBot(&model.Bot{
Username: "aws-sns",
DisplayName: "AWS SNS Plugin",
Description: "A bot account created by the plugin AWS SNS",
},
plugin.ProfileImagePath("assets/icon.png"),
pluginapi.ProfileImagePath("assets/icon.png"),
)
if err != nil {
return errors.Wrap(err, "can't ensure bot")
Expand All @@ -74,7 +79,7 @@ func (p *Plugin) OnActivate() error {
channelToCreate := &model.Channel{
Name: channelSplit,
DisplayName: channelSplit,
Type: model.CHANNEL_OPEN,
Type: model.ChannelTypeOpen,
TeamId: p.TeamID,
CreatorId: p.BotUserID,
}
Expand Down Expand Up @@ -280,7 +285,7 @@ func (p *Plugin) sendSubscribeConfirmationMessage(message string, subscriptionUR
siteURLPort := *config.ServiceSettings.SiteURL
action1 := &model.PostAction{
Name: "Confirm Subscription",
Type: model.POST_ACTION_TYPE_BUTTON,
Type: model.PostActionTypeButton,
Integration: &model.PostActionIntegration{
Context: map[string]interface{}{
"action": "confirm",
Expand Down

0 comments on commit d3f93b6

Please sign in to comment.