Skip to content

Commit

Permalink
add buf.build version
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Aug 28, 2024
1 parent 16a40f0 commit 388e980
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
26 changes: 24 additions & 2 deletions ignite/pkg/cosmosbuf/buf.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package cosmosbuf

import (
"bytes"
"context"
"fmt"
"path/filepath"
"strings"

"github.com/gobwas/glob"
"golang.org/x/sync/errgroup"

"github.com/ignite/cli/v29/ignite/pkg/cache"
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/exec"
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step"
"github.com/ignite/cli/v29/ignite/pkg/dircache"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/goenv"
Expand Down Expand Up @@ -124,7 +127,7 @@ func FileByFile() GenOption {

// New creates a new Buf based on the installed binary.
func New(cacheStorage cache.Storage, goModPath string) (Buf, error) {
path, err := xexec.ResolveAbsPath(filepath.Join(goenv.Bin(), binaryName))
p, err := path()
if err != nil {
return Buf{}, err
}
Expand All @@ -136,7 +139,7 @@ func New(cacheStorage cache.Storage, goModPath string) (Buf, error) {
}

return Buf{
path: path,
path: p,
cache: c,
}, nil
}
Expand Down Expand Up @@ -309,3 +312,22 @@ func (b Buf) command(
}
return command, nil
}

func path() (string, error) {
return xexec.ResolveAbsPath(filepath.Join(goenv.Bin(), binaryName))
}

// Version runs the buf Version command.
func Version(ctx context.Context) (string, error) {
p, err := path()
if err != nil {
return "", err
}

bufOut := &bytes.Buffer{}
if err := exec.Exec(ctx, []string{p, "--version"}, exec.StepOption(step.Stdout(bufOut))); err != nil {
return "", err
}

return strings.TrimSpace(bufOut.String()), nil
}
9 changes: 9 additions & 0 deletions ignite/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
chainconfig "github.com/ignite/cli/v29/ignite/config/chain"
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/exec"
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step"
"github.com/ignite/cli/v29/ignite/pkg/cosmosbuf"
"github.com/ignite/cli/v29/ignite/pkg/cosmosver"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/gitpod"
Expand All @@ -40,6 +41,7 @@ type Info struct {
CLIVersion string
GoVersion string
SDKVersion string
BufVersion string
BuildDate string
SourceHash string
ConfigVersion string
Expand Down Expand Up @@ -150,6 +152,7 @@ func Long(ctx context.Context) (string, error) {
write("Ignite CLI source hash", info.SourceHash)
write("Ignite CLI config version", info.ConfigVersion)
write("Cosmos SDK version", info.SDKVersion)
write("Buf.Build version", info.BufVersion)

write("Your OS", info.OS)
write("Your arch", info.Arch)
Expand Down Expand Up @@ -221,9 +224,15 @@ func GetInfo(ctx context.Context) (Info, error) {
uname = strings.TrimSpace(unameBuf.String())
}

bufVersion, err := cosmosbuf.Version(ctx)
if err != nil {
return info, err
}

info.Uname = uname
info.CLIVersion = resolveDevVersion(ctx)
info.BuildDate = date
info.BufVersion = bufVersion
info.SourceHash = head
info.ConfigVersion = fmt.Sprintf("v%d", chainconfig.LatestVersion)
info.SDKVersion = sdkVersion
Expand Down

0 comments on commit 388e980

Please sign in to comment.