Skip to content

Commit

Permalink
add more information to the version command (#415)
Browse files Browse the repository at this point in the history
* add more information to the version

* update deps and vendor

* fix tests

* Apply suggestions from code review

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>

* fix

Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
  • Loading branch information
Carlos Tadeu Panato Junior and isacikgoz committed Dec 7, 2021
1 parent 39ba825 commit 3661107
Show file tree
Hide file tree
Showing 496 changed files with 72,307 additions and 21,719 deletions.
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
GO_PACKAGES=$(shell go list ./...)
GO ?= $(shell command -v go 2> /dev/null)
BUILD_HASH ?= $(shell git rev-parse HEAD)
BUILD_VERSION ?= $(shell git ls-remote --tags --refs git://github.com/mattermost/mmctl | tail -n1 | sed 's/.*\///')
GIT_HASH ?= $(shell git rev-parse HEAD)
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ'
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
endif
GIT_TREESTATE = "clean"
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
ifeq ($(DIFF), 1)
GIT_TREESTATE = "dirty"
endif
# Needed to avoid install shadow in brew which is not permitted
ADVANCED_VET ?= TRUE
ENTERPRISE_DIR ?= ${MM_SERVER_PATH}/../enterprise
VENDOR_MM_SERVER_DIR ?= vendor/github.com/mattermost/mattermost-server/v6
ENTERPRISE_HASH ?= $(shell cat enterprise_hash)
TESTFLAGS = -mod=vendor -timeout 30m -race -v
LDFLAGS += -X "github.com/mattermost/mmctl/commands.BuildHash=$(BUILD_HASH)"


PKG=github.com/mattermost/mmctl/commands
LDFLAGS= -X $(PKG).gitCommit=$(GIT_HASH) -X $(PKG).gitTreeState=$(GIT_TREESTATE) -X $(PKG).buildDate=$(BUILD_DATE)
BUILD_TAGS =

.PHONY: all
Expand All @@ -26,7 +40,7 @@ ifneq ($(wildcard ${ENTERPRISE_DIR}/.*),)
IGNORE:=$(shell cp -R $(ENTERPRISE_DIR) $(VENDOR_MM_SERVER_DIR))
IGNORE:=$(shell git -C $(VENDOR_MM_SERVER_DIR)/enterprise checkout $(ENTERPRISE_HASH) --quiet)
IGNORE:=$(shell rm -f $(VENDOR_MM_SERVER_DIR)/imports/imports.go)
IGNORE:=$(shell mkdir $(VENDOR_MM_SERVER_DIR)/imports)
IGNORE:=$(shell mkdir -p $(VENDOR_MM_SERVER_DIR)/imports)
IGNORE:=$(shell cp $(VENDOR_MM_SERVER_DIR)/enterprise/imports/imports.go $(VENDOR_MM_SERVER_DIR)/imports/)
endif

Expand Down
22 changes: 11 additions & 11 deletions commands/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (s *MmctlE2ETestSuite) TestPluginAddCmd() {

// teardown
pInfo := plugins.Inactive[0]
appErr = s.th.App.RemovePlugin(pInfo.Id)
s.Require().Nil(appErr)
err = pluginDeleteCmdF(c, &cobra.Command{}, []string{pInfo.Id})
s.Require().Nil(err)
})

s.RunForSystemAdminAndLocal("add an already installed plugin with force", func(c client.Client) {
Expand Down Expand Up @@ -98,8 +98,8 @@ func (s *MmctlE2ETestSuite) TestPluginAddCmd() {

// teardown
pInfo := plugins.Inactive[0]
appErr = s.th.App.RemovePlugin(pInfo.Id)
s.Require().Nil(appErr)
err = pluginDeleteCmdF(c, &cobra.Command{}, []string{pInfo.Id})
s.Require().Nil(err)
})

s.RunForSystemAdminAndLocal("admin and local can't add plugins if the config doesn't allow it", func(c client.Client) {
Expand Down Expand Up @@ -136,8 +136,8 @@ func (s *MmctlE2ETestSuite) TestPluginAddCmd() {

// teardown
pInfo := res.Inactive[0]
appErr = s.th.App.RemovePlugin(pInfo.Id)
s.Require().Nil(appErr)
err = pluginDeleteCmdF(c, &cobra.Command{}, []string{pInfo.Id})
s.Require().Nil(err)
})

s.Run("normal user can't add plugin", func() {
Expand Down Expand Up @@ -176,8 +176,8 @@ func (s *MmctlE2ETestSuite) TestPluginInstallURLCmd() {

s.RunForSystemAdminAndLocal("install new plugins", func(c client.Client) {
printer.Clean()
defer removePluginIfInstalled(s, jiraPluginID)
defer removePluginIfInstalled(s, githubPluginID)
defer removePluginIfInstalled(c, s, jiraPluginID)
defer removePluginIfInstalled(c, s, githubPluginID)

err := pluginInstallURLCmdF(c, &cobra.Command{}, []string{jiraURL, githubURL})
s.Require().Nil(err)
Expand All @@ -194,7 +194,7 @@ func (s *MmctlE2ETestSuite) TestPluginInstallURLCmd() {

s.Run("install a plugin without permissions", func() {
printer.Clean()
defer removePluginIfInstalled(s, jiraPluginID)
defer removePluginIfInstalled(s.th.Client, s, jiraPluginID)

err := pluginInstallURLCmdF(s.th.Client, &cobra.Command{}, []string{jiraURL})
s.Require().Nil(err)
Expand Down Expand Up @@ -229,7 +229,7 @@ func (s *MmctlE2ETestSuite) TestPluginInstallURLCmd() {

s.RunForSystemAdminAndLocal("install an already installed plugin without force", func(c client.Client) {
printer.Clean()
defer removePluginIfInstalled(s, jiraPluginID)
defer removePluginIfInstalled(c, s, jiraPluginID)

err := pluginInstallURLCmdF(c, &cobra.Command{}, []string{jiraURL})
s.Require().Nil(err)
Expand All @@ -252,7 +252,7 @@ func (s *MmctlE2ETestSuite) TestPluginInstallURLCmd() {

s.RunForSystemAdminAndLocal("install an already installed plugin with force", func(c client.Client) {
printer.Clean()
defer removePluginIfInstalled(s, jiraPluginID)
defer removePluginIfInstalled(c, s, jiraPluginID)

err := pluginInstallURLCmdF(c, &cobra.Command{}, []string{jiraURL})
s.Require().Nil(err)
Expand Down
14 changes: 7 additions & 7 deletions commands/plugin_marketplace_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *MmctlE2ETestSuite) TestPluginMarketplaceInstallCmd() {
pluginID := plugin.Manifest.Id
pluginVersion := plugin.Manifest.Version

defer removePluginIfInstalled(s, pluginID)
defer removePluginIfInstalled(c, s, pluginID)

err := pluginMarketplaceInstallCmdF(c, &cobra.Command{}, []string{pluginID, pluginVersion})
s.Require().Nil(err)
Expand All @@ -58,7 +58,7 @@ func (s *MmctlE2ETestSuite) TestPluginMarketplaceInstallCmd() {
pluginVersion = "3.0.0"
)

defer removePluginIfInstalled(s, pluginID)
defer removePluginIfInstalled(s.th.Client, s, pluginID)

err := pluginMarketplaceInstallCmdF(s.th.Client, &cobra.Command{}, []string{pluginID, pluginVersion})
s.Require().NotNil(err)
Expand All @@ -79,7 +79,7 @@ func (s *MmctlE2ETestSuite) TestPluginMarketplaceInstallCmd() {
pluginID = "jira"
)

defer removePluginIfInstalled(s, pluginID)
defer removePluginIfInstalled(c, s, pluginID)

err := pluginMarketplaceInstallCmdF(c, &cobra.Command{}, []string{pluginID})
s.Require().Nil(err)
Expand All @@ -106,7 +106,7 @@ func (s *MmctlE2ETestSuite) TestPluginMarketplaceInstallCmd() {
pluginVersion = "invalid-version"
)

defer removePluginIfInstalled(s, pluginID)
defer removePluginIfInstalled(c, s, pluginID)

err := pluginMarketplaceInstallCmdF(c, &cobra.Command{}, []string{pluginID, pluginVersion})
s.Require().NotNil(err)
Expand All @@ -127,7 +127,7 @@ func (s *MmctlE2ETestSuite) TestPluginMarketplaceInstallCmd() {
pluginID = "a-nonexistent-plugin"
)

defer removePluginIfInstalled(s, pluginID)
defer removePluginIfInstalled(c, s, pluginID)

err := pluginMarketplaceInstallCmdF(c, &cobra.Command{}, []string{pluginID})
s.Require().NotNil(err)
Expand All @@ -142,8 +142,8 @@ func (s *MmctlE2ETestSuite) TestPluginMarketplaceInstallCmd() {
})
}

func removePluginIfInstalled(s *MmctlE2ETestSuite, pluginID string) {
appErr := s.th.App.RemovePlugin(pluginID)
func removePluginIfInstalled(c client.Client, s *MmctlE2ETestSuite, pluginID string) {
appErr := pluginDeleteCmdF(c, &cobra.Command{}, []string{pluginID})
if appErr != nil {
s.Require().Contains(appErr.Error(), "Plugin is not installed.")
}
Expand Down
45 changes: 39 additions & 6 deletions commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,60 @@
package commands

import (
"fmt"
"runtime"

"github.com/mattermost/mmctl/printer"

"github.com/spf13/cobra"
)

var (
BuildHash = "dev mode"
Version = "6.1.0"
Version = "6.2.0"
// SHA1 from git, output of $(git rev-parse HEAD)
gitCommit = "dev mode"
// State of git tree, either "clean" or "dirty"
gitTreeState = "unknown"
// Build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
buildDate = "unknown"
)

var VersionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version of mmctl.",
Args: cobra.NoArgs,
Run: versionCmdF,
RunE: versionCmdF,
}

func init() {
RootCmd.AddCommand(VersionCmd)
}

func versionCmdF(cmd *cobra.Command, args []string) {
printer.Print("mmctl v" + Version + " -- " + BuildHash)
func versionCmdF(cmd *cobra.Command, args []string) error {
v := getVersionInfo()
printer.PrintT("mmctl:\nVersion:\t{{.Version}}\nGitCommit:\t{{.GitCommit}}"+
"\nGitTreeState:\t{{.GitTreeState}}\nBuildDate:\t{{.BuildDate}}\nGoVersion:\t{{.GoVersion}}"+
"\nCompiler:\t{{.Compiler}}\nPlatform:\t{{.Platform}}", v)
return nil
}

type Info struct {
Version string
GitCommit string
GitTreeState string
BuildDate string
GoVersion string
Compiler string
Platform string
}

func getVersionInfo() Info {
return Info{
Version: Version,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ require (
github.com/gorilla/handlers v1.5.1
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/memberlist v0.2.4
github.com/hashicorp/memberlist v0.3.0
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/isacikgoz/prompt v0.1.0
github.com/magefile/mage v1.11.0
github.com/mattermost/gosaml2 v0.3.3
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d
github.com/mattermost/mattermost-server/v6 v6.1.0
github.com/mattermost/mattermost-server/v6 v6.0.0-20211125140117-009d02c57a92
github.com/mattermost/rsc v0.0.0-20160330161541-bbaefb05eaa0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
Expand Down
Loading

0 comments on commit 3661107

Please sign in to comment.