Skip to content
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 @@ -5,6 +5,7 @@
### Features

- [#4509](https://github.com/ignite/cli/pull/4509) Upgrade to Go 1.24. Running `ignite doctor` migrates the scaffolded `tools.go` to the tool directive in the go.mod
- [#4588](https://github.com/ignite/cli/pull/4588) Run `buf format after scaffold proto files.

### Changes

Expand Down
17 changes: 16 additions & 1 deletion ignite/pkg/cosmosbuf/buf.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
)

const (
binaryName = "buf"
flagTemplate = "template"
flagOutput = "output"
flagErrorFormat = "error-format"
Expand All @@ -28,13 +27,15 @@ const (
flagBufGenYaml = "buf-gen-yaml"
flagIncludeImports = "include-imports"
flagIncludeWellKnownTypes = "include-wkt"
flagWrite = "write"
flagPath = "path"
fmtJSON = "json"
bufGenPrefix = "buf.gen."

// CMDGenerate generate command.
CMDGenerate Command = "generate"
CMDExport Command = "export"
CMDFormat Command = "format"
CMDConfig Command = "config"
CMDDep Command = "dep"

Expand All @@ -45,6 +46,7 @@ var (
commands = map[Command]struct{}{
CMDGenerate: {},
CMDExport: {},
CMDFormat: {},
CMDConfig: {},
CMDDep: {},
}
Expand Down Expand Up @@ -211,6 +213,19 @@ func (b Buf) Export(ctx context.Context, protoDir, output string) error {
return b.runCommand(ctx, cmd...)
}

// Format runs the buf Format command for the files in the provided path.
func (b Buf) Format(ctx context.Context, path string) error {
flags := map[string]string{
flagWrite: "true",
}
cmd, err := b.command(CMDFormat, flags, path)
if err != nil {
return err
}

return b.runCommand(ctx, cmd...)
}

// Generate runs the buf Generate command for each file into the proto directory.
func (b Buf) Generate(
ctx context.Context,
Expand Down
4 changes: 2 additions & 2 deletions ignite/pkg/cosmosgen/cosmosgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ func (g *generator) cleanup() {
// Generate generates code from protoDir of an SDK app residing at appPath with given options.
// protoDir must be relative to the projectPath.
func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir, goModPath string, options ...Option) error {
b, err := cosmosbuf.New(cacheStorage, goModPath)
buf, err := cosmosbuf.New(cacheStorage, goModPath)
if err != nil {
return err
}

g := &generator{
buf: b,
buf: buf,
appPath: appPath,
protoDir: protoDir,
goModPath: goModPath,
Expand Down
19 changes: 15 additions & 4 deletions ignite/services/scaffolder/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
chainconfig "github.com/ignite/cli/v29/ignite/config/chain"
"github.com/ignite/cli/v29/ignite/pkg/cache"
"github.com/ignite/cli/v29/ignite/pkg/cosmosanalysis"
"github.com/ignite/cli/v29/ignite/pkg/cosmosbuf"
"github.com/ignite/cli/v29/ignite/pkg/cosmosgen"
"github.com/ignite/cli/v29/ignite/pkg/cosmosver"
"github.com/ignite/cli/v29/ignite/pkg/errors"
Expand Down Expand Up @@ -93,7 +94,7 @@ func (s Scaffolder) PostScaffold(ctx context.Context, cacheStorage cache.Storage
return PostScaffold(ctx, cacheStorage, s.appPath, s.protoDir, s.modpath.RawPath, skipProto)
}

func PostScaffold(ctx context.Context, cacheStorage cache.Storage, path, protoDir, gomodPath string, skipProto bool) error {
func PostScaffold(ctx context.Context, cacheStorage cache.Storage, path, protoDir, goModPath string, skipProto bool) error {
wd, err := os.Getwd()
if err != nil {
return errors.Errorf("failed to get current working directory: %w", err)
Expand All @@ -105,11 +106,12 @@ func PostScaffold(ctx context.Context, cacheStorage cache.Storage, path, protoDi
}

if !skipProto {
// go mod tidy prior and after the proto generation is required.
if err := gocmd.ModTidy(ctx, path); err != nil {
return err
}

if err := protoc(ctx, cacheStorage, path, protoDir, gomodPath); err != nil {
if err := protoc(ctx, cacheStorage, path, protoDir, goModPath); err != nil {
return err
}
}
Expand All @@ -134,7 +136,7 @@ func PostScaffold(ctx context.Context, cacheStorage cache.Storage, path, protoDi
return nil
}

func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, protoDir, gomodPath string) error {
func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, protoDir, goModPath string) error {
confpath, err := chainconfig.LocateDefault(projectPath)
if err != nil {
return err
Expand Down Expand Up @@ -174,5 +176,14 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, protoD
options = append(options, cosmosgen.WithOpenAPIGeneration(openAPIPath))
}

return cosmosgen.Generate(ctx, cacheStorage, projectPath, protoDir, gomodPath, options...)
if err := cosmosgen.Generate(ctx, cacheStorage, projectPath, protoDir, goModPath, options...); err != nil {
return err
}

buf, err := cosmosbuf.New(cacheStorage, goModPath)
if err != nil {
return err
}

return buf.Format(ctx, projectPath)
}
Loading