Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add buf.build version to ignite version command #4326

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [#4113](https://github.com/ignite/cli/pull/4113) Generate chain config documentation automatically
- [#4131](https://github.com/ignite/cli/pull/4131) Support `bytes` as data type in the `scaffold` commands
- [#4300](https://github.com/ignite/cli/pull/4300) Only panics the module in the most top function level
- [#4326](https://github.com/ignite/cli/pull/4326) fAdd `buf.build` version to `ignite version` command

### Changes

Expand Down
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
Loading