Skip to content

Commit

Permalink
dist: build linux/darwin arm64 targets (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Tadeu Panato Junior authored Nov 24, 2021
1 parent bbed826 commit 3b92090
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 173 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
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
20 changes: 10 additions & 10 deletions build/deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"path/filepath"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mholt/archiver/v3"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -52,9 +52,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 +83,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
4 changes: 3 additions & 1 deletion build/manifest/main.go

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

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/mattermost/mattermost-plugin-gitlab
go 1.13

require (
github.com/golang/mock v1.4.4
github.com/mattermost/mattermost-plugin-api v0.0.16
github.com/mattermost/mattermost-server/v5 v5.38.0
github.com/golang/mock v1.6.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
github.com/stretchr/testify v1.7.0
github.com/xanzy/go-gitlab v0.48.0
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)
157 changes: 20 additions & 137 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"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
4 changes: 2 additions & 2 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strings"
"time"

"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"
"golang.org/x/oauth2"

"github.com/mattermost/mattermost-plugin-gitlab/server/gitlab"
Expand Down
4 changes: 2 additions & 2 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"

"github.com/mattermost/mattermost-plugin-api/experimental/command"
"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-gitlab/server/gitlab"
Expand Down
4 changes: 2 additions & 2 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin/plugintest"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin/plugintest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
gitLabAPI "github.com/xanzy/go-gitlab"
Expand Down
2 changes: 1 addition & 1 deletion server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"
"strings"

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

"github.com/mattermost/mattermost-plugin-gitlab/server/gitlab"
Expand Down
2 changes: 1 addition & 1 deletion server/gitlab/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gitlab

import (
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v6/model"
internGitlab "github.com/xanzy/go-gitlab"
"golang.org/x/oauth2"
)
Expand Down
2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
@@ -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.

12 changes: 8 additions & 4 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"strings"
"sync"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
pluginapi "github.com/mattermost/mattermost-plugin-api"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"
"github.com/pkg/errors"
"golang.org/x/oauth2"

Expand All @@ -40,6 +41,7 @@ var errEmptySiteURL = errors.New("siteURL is not set. Please set it and restart

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

BotUserID string
WebhookHandler webhook.Webhook
Expand All @@ -56,6 +58,8 @@ type Plugin struct {
}

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

config := p.getConfiguration()
if err := config.IsValid(); err != nil {
return err
Expand All @@ -80,7 +84,7 @@ func (p *Plugin) OnActivate() error {
return errors.Wrap(err, "failed to register command")
}

botID, err := p.Helpers.EnsureBot(&model.Bot{
botID, err := p.client.Bot.EnsureBot(&model.Bot{
Username: "gitlab",
DisplayName: "GitLab Plugin",
Description: "A bot account created by the plugin GitLab.",
Expand Down Expand Up @@ -293,7 +297,7 @@ func (p *Plugin) disconnectGitlabAccount(userID string) {

// registerChimeraURL fetches the Chimera URL from server settings or env var and sets it in the plugin object.
func (p *Plugin) registerChimeraURL() {
chimeraURLSetting := p.API.GetConfig().PluginSettings.ChimeraOAuthProxyUrl
chimeraURLSetting := p.API.GetConfig().PluginSettings.ChimeraOAuthProxyURL
if chimeraURLSetting != nil && *chimeraURLSetting != "" {
p.chimeraURL = *chimeraURLSetting
return
Expand Down
2 changes: 1 addition & 1 deletion server/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"testing"

"github.com/mattermost/mattermost-server/v5/plugin/plugintest"
"github.com/mattermost/mattermost-server/v6/plugin/plugintest"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion server/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/mattermost/mattermost-plugin-gitlab/server/subscription"
"github.com/mattermost/mattermost-plugin-gitlab/server/webhook"

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

type gitlabRetreiver struct {
Expand Down
6 changes: 3 additions & 3 deletions server/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net/http/httptest"
"testing"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin/plugintest"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin/plugintest"
"github.com/stretchr/testify/assert"
gitlabLib "github.com/xanzy/go-gitlab"

Expand Down Expand Up @@ -105,7 +105,7 @@ func TestHandleWebhookToChannel(t *testing.T) {
mock.On("PublishWebSocketEvent", WsEventRefresh, map[string]interface{}(nil), &model.WebsocketBroadcast{UserId: "1"}).Return(nil).Once()
mock.On("LogInfo", "new msg", "message", "hello", "from", "test").Return(nil)
mock.On("LogInfo", "userFrom", "from", "1").Return(nil)
mock.On("CreatePost", &model.Post{Id: "", CreateAt: 0, UpdateAt: 0, EditAt: 0, DeleteAt: 0, IsPinned: false, UserId: "", ChannelId: "town-square", RootId: "", ParentId: "", OriginalId: "", Message: "hello", MessageSource: "", Type: "", Hashtags: "", Filenames: model.StringArray(nil), FileIds: model.StringArray(nil), PendingPostId: "", HasReactions: false, Metadata: (*model.PostMetadata)(nil)}).Return(nil, nil)
mock.On("CreatePost", &model.Post{Id: "", CreateAt: 0, UpdateAt: 0, EditAt: 0, DeleteAt: 0, IsPinned: false, UserId: "", ChannelId: "town-square", RootId: "", OriginalId: "", Message: "hello", MessageSource: "", Type: "", Hashtags: "", Filenames: model.StringArray(nil), FileIds: model.StringArray(nil), PendingPostId: "", HasReactions: false, Metadata: (*model.PostMetadata)(nil)}).Return(nil, nil)
p.SetAPI(mock)

req := httptest.NewRequest("POST", "/", bytes.NewBufferString(`{"user": {"username":"test"}}`))
Expand Down
1 change: 1 addition & 0 deletions webapp/src/manifest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This file is automatically generated. Do not modify it manually.
// Code generated .* DO NOT EDIT.

export const id = 'com.github.manland.mattermost-plugin-gitlab';
export const version = '1.4.0';

0 comments on commit 3b92090

Please sign in to comment.