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: use buf.build binary to generate the proto files #3476

Merged
merged 72 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
6ec0fc8
build buf pkg
Pantani Mar 30, 2023
71ccd6c
fix go.mod
Pantani Mar 30, 2023
89ca5ae
Merge branch 'main' into feat/buf-build
Pantani Apr 6, 2023
bfcf049
Merge remote-tracking branch 'origin/main' into feat/buf-build
Pantani Apr 18, 2023
1119fd3
comment xbug pkg and bump buf versions
Pantani Apr 19, 2023
b06c098
generate proto from buf and remove protoc and plugins
Pantani Apr 20, 2023
de84c72
add proto ts and api generation
Pantani Apr 25, 2023
7f0a56e
Merge branch 'main' into feat/buf-build
Pantani Apr 25, 2023
f71b889
add changelog
Pantani Apr 25, 2023
453546c
fix proto and template path
Pantani Apr 25, 2023
f71d077
fix wrong template for ts generation
Pantani Apr 25, 2023
f95a8cf
fix api out path
Pantani Apr 25, 2023
fc68882
fix ts out path and remove unused log
Pantani Apr 25, 2023
49d1a25
fix go.mod ident and sort
Pantani Apr 25, 2023
6a32471
remove unused method
Pantani Apr 25, 2023
24b84c9
fix lint
Pantani Apr 25, 2023
069eae6
fix wrong lint comment
Pantani Apr 25, 2023
610d616
remove unused tools
Pantani Apr 25, 2023
d32f7b9
fix doctor for tools pkg
Pantani Apr 25, 2023
65feeb4
add missing tool dependency
Pantani Apr 25, 2023
69b9f8d
add missing import
Pantani Apr 25, 2023
d3fbdfa
add global protoanalysis.NewCache to buf structure
Pantani Apr 25, 2023
69d9371
fix proto module name
Pantani Apr 27, 2023
72d8e12
Merge remote-tracking branch 'origin/main' into feat/buf-build
Pantani May 5, 2023
507ed36
update go.mod
Pantani May 5, 2023
4bd764b
Update ignite/pkg/cosmosgen/generate_go.go method name
Pantani May 8, 2023
e603a26
Update ignite/pkg/buf/buf.go remove unused ctx
Pantani May 8, 2023
d6d5be0
Merge remote-tracking branch 'origin/main' into feat/buf-build
Pantani May 8, 2023
12632b0
fix wrong method call
Pantani May 8, 2023
e8d1a9a
fix deep tools
Pantani May 8, 2023
a7edd4e
fix ignite doctor
Pantani May 8, 2023
a4287f0
fix buf.gen files
Pantani May 8, 2023
279fed1
fix proto gen files
Pantani May 8, 2023
b4a432c
remove 3thrparty mod
Pantani May 12, 2023
dc1f53a
thr modules openapi
Pantani May 14, 2023
6c9f881
add xos copy commands
Pantani May 18, 2023
c70cfb3
fix wrong proto tmp path
Pantani May 19, 2023
ce4f415
remove unused method
Pantani May 19, 2023
f966825
update tools for the doctor command
Pantani May 19, 2023
e300187
Merge branch 'main' into feat/buf-build
Pantani May 19, 2023
1609b2e
unhlanded error
Pantani May 19, 2023
bd41879
check if the buf files exists
Pantani May 19, 2023
ba56501
remove unused ctx
Pantani May 19, 2023
c72b9e1
Merge branch 'main' into feat/buf-build
Pantani May 22, 2023
808d18f
Merge branch 'main' into feat/buf-build
Pantani May 22, 2023
cd0c4ce
Merge branch 'main' into feat/buf-build
Pantani May 23, 2023
80d60cb
Merge remote-tracking branch 'origin/main' into feat/buf-build
Pantani May 23, 2023
dce042f
fix changelog merge
Pantani May 23, 2023
7a1021b
fix unit tests and make more dynamic
Pantani May 25, 2023
ca27109
Merge branch 'main' into feat/buf-build
Pantani May 25, 2023
da28a09
Merge branch 'main' into feat/buf-build
Pantani May 25, 2023
6c10015
Update changelog
Pantani Jun 1, 2023
fc7cb19
Merge branch 'main' into feat/buf-build
Pantani Jun 5, 2023
8442b5a
Merge remote-tracking branch 'origin/main' into feat/buf-build
Pantani Jun 5, 2023
2c34095
fix ts script generation and remove pulsar buf files
Pantani Jun 7, 2023
b7c6794
Merge branch 'main' into feat/buf-build
Pantani Jun 13, 2023
23779aa
Merge branch 'main' into feat/buf-build
Pantani Jun 13, 2023
bbb41a7
fix changelog
Pantani Jun 13, 2023
020baea
Merge remote-tracking branch 'origin/main' into feat/buf-build
Pantani Jun 21, 2023
47e0877
fix changelog
Pantani Jun 21, 2023
d95e9b7
add migration for scaffold and generate commands
Pantani Jun 23, 2023
fedfd47
fix pre handler
Jun 25, 2023
3cc098c
fix rance condition
Jun 25, 2023
e7f4627
fix wrong app path for tools migrations
Jun 26, 2023
775f417
fix lint
Jun 26, 2023
f28699d
rollback draft changes
Jun 26, 2023
660cc28
fix ineffassign lint
Jun 26, 2023
7722c4e
fix wrong path
Jun 26, 2023
7fe7cba
Merge branch 'main' into feat/buf-build
Pantani Jun 28, 2023
9a9f2c8
Merge branch 'main' into feat/buf-build
Pantani Jun 29, 2023
383a07c
move buf pkg to cosmosbuf
Jun 29, 2023
6d6c00f
increase test timeout
Jun 29, 2023
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
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Changelog

## [`v0.27.1`](https://github.com/ignite/cli/releases/tag/v0.27.1)
## Unreleased

### Features

- [#3476](https://github.com/ignite/cli/pull/3476) Use `buf.build` binary to code generate from proto files

## [`v0.27.0`](https://github.com/ignite/cli/releases/tag/v0.27.0)

### Features
-
- [#3505](https://github.com/ignite/cli/pull/3505) Auto migrate dependency tools
- [#3538](https://github.com/ignite/cli/pull/3538) bump sdk to `v0.47.3` and ibc to `v7.1.0`
- [#2736](https://github.com/ignite/cli/issues/2736) Add `--skip-git` flag to skip git repository initialization.
Expand Down
45 changes: 39 additions & 6 deletions ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ import (
"github.com/ignite/cli/ignite/pkg/cliui/icons"
"github.com/ignite/cli/ignite/pkg/cosmosgen"
"github.com/ignite/cli/ignite/pkg/goanalysis"
"github.com/ignite/cli/ignite/pkg/gomodulepath"
"github.com/ignite/cli/ignite/pkg/xast"
"github.com/ignite/cli/ignite/services/chain"
"github.com/ignite/cli/ignite/services/doctor"
)

const (
msgMigration = "Migrating blockchain config file from v%d to v%d..."
msgMigrationPrefix = "Your blockchain config version is v%d and the latest is v%d."
msgMigrationPrompt = "Would you like to upgrade your config file to v%d"
msgMigration = "Migrating blockchain config file from v%d to v%d..."
msgMigrationPrefix = "Your blockchain config version is v%d and the latest is v%d."
msgMigrationPrompt = "Would you like to upgrade your config file to v%d"
msgMigrationBuf = "Now ignite supports the `buf.build` (https://buf.build) registry to manage the protobuf dependencies. The embed protoc binary was deprecated and, your blockchain is still using it. Would you like to upgrade and add the `buf.build` config files to `proto/` folder"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccomben can you please help improving this text?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?

Suggested change
msgMigrationBuf = "Now ignite supports the `buf.build` (https://buf.build) registry to manage the protobuf dependencies. The embed protoc binary was deprecated and, your blockchain is still using it. Would you like to upgrade and add the `buf.build` config files to `proto/` folder"
msgMigrationBuf = "Buf (https://buf.build) is required for proto code generation. Would you like to enable it?"

Users would get the following message if n is selected:

code generation using protoc is only supported by Ignite CLI v0.26.1 or older

A change for this message is proposed in another comment.

msgMigrationAddTools = "Some required imports are missing in %s file: %s. Would you like to add them"
msgMigrationRemoveTools = "File %s contains deprecated imports: %s. Would you like to remove them"
)

// NewChain returns a command that groups sub commands related to compiling, serving
Expand Down Expand Up @@ -109,13 +114,19 @@ func preRunHandler(cmd *cobra.Command, _ []string) error {
if err := configMigrationPreRunHandler(cmd, session); err != nil {
return err
}
return toolsMigrationPreRunHandler(cmd, session)

if err := toolsMigrationPreRunHandler(cmd, session); err != nil {
return err
}

return bufMigrationPreRunHandler(cmd, session)
}

func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) (err error) {
session.StartSpinner("Checking missing tools...")

appPath := flagGetPath(cmd)
_, appPath, err = gomodulepath.Find(appPath)
toolsFilename := filepath.Join(appPath, doctor.ToolsFile)
if _, err := os.Stat(toolsFilename); os.IsNotExist(err) {
return errors.New("the dependency tools file is missing, run `ignite doctor` and try again")
Expand All @@ -132,7 +143,7 @@ func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) (er
session.StopSpinner()
if len(missing) > 0 {
question := fmt.Sprintf(
"Some required imports are missing in %s file: %s. Would you like to add them",
msgMigrationAddTools,
toolsFilename,
strings.Join(missing, ", "),
)
Expand All @@ -143,7 +154,7 @@ func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) (er

if len(unused) > 0 {
question := fmt.Sprintf(
"File %s contains deprecated imports: %s. Would you like to remove them",
msgMigrationRemoveTools,
toolsFilename,
strings.Join(unused, ", "),
)
Expand All @@ -164,6 +175,28 @@ func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) (er
return os.WriteFile(toolsFilename, buf.Bytes(), 0o644)
}

func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) error {
appPath := flagGetPath(cmd)
hasFiles := chain.CheckBufFiles(appPath)
if hasFiles {
return nil
}
if err := session.AskConfirm(msgMigrationBuf); err != nil {
return fmt.Errorf("build the protobuf files with the protoc binary is only supported on version " +
"`v0.26.1` or below. Please downgrade your Ignite version")
Pantani marked this conversation as resolved.
Show resolved Hide resolved
}

sm, err := chain.BoxBufFiles(appPath)
if err != nil {
return err
}

session.Print("\n🎉 buf.build files added: \n\n")
session.Printf("%s\n\n", strings.Join(sm.CreatedFiles(), "\n"))

return nil
}

func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) (err error) {
appPath := flagGetPath(cmd)
configPath := getConfig(cmd)
Expand Down
11 changes: 1 addition & 10 deletions ignite/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package ignitecmd

import (
"github.com/spf13/cobra"

"github.com/ignite/cli/ignite/pkg/cliui"
)

// NewGenerate returns a command that groups code generation related sub commands.
Expand All @@ -21,7 +19,7 @@ meant to be edited by hand.
`,
Aliases: []string{"g"},
Args: cobra.ExactArgs(1),
PersistentPreRunE: generatePreRunHandler,
PersistentPreRunE: migrationPreRunHandler,
}

flagSetPath(c)
Expand All @@ -35,10 +33,3 @@ meant to be edited by hand.

return c
}

func generatePreRunHandler(cmd *cobra.Command, _ []string) error {
session := cliui.New()
defer session.End()

return toolsMigrationPreRunHandler(cmd, session)
}
7 changes: 3 additions & 4 deletions ignite/cmd/generate_composables.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (

func NewGenerateComposables() *cobra.Command {
c := &cobra.Command{
Use: "composables",
Short: "TypeScript frontend client and Vue 3 composables",
PreRunE: gitChangesConfirmPreRunHandler,
RunE: generateComposablesHandler,
Use: "composables",
Short: "TypeScript frontend client and Vue 3 composables",
RunE: generateComposablesHandler,
}

c.Flags().AddFlagSet(flagSetYes())
Expand Down
7 changes: 3 additions & 4 deletions ignite/cmd/generate_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (

func NewGenerateGo() *cobra.Command {
c := &cobra.Command{
Use: "proto-go",
Short: "Compile protocol buffer files to Go source code required by Cosmos SDK",
PreRunE: gitChangesConfirmPreRunHandler,
RunE: generateGoHandler,
Use: "proto-go",
Short: "Compile protocol buffer files to Go source code required by Cosmos SDK",
RunE: generateGoHandler,
}

c.Flags().AddFlagSet(flagSetYes())
Expand Down
7 changes: 3 additions & 4 deletions ignite/cmd/generate_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (

func NewGenerateHooks() *cobra.Command {
c := &cobra.Command{
Use: "hooks",
Short: "TypeScript frontend client and React hooks",
PreRunE: gitChangesConfirmPreRunHandler,
RunE: generateHooksHandler,
Use: "hooks",
Short: "TypeScript frontend client and React hooks",
RunE: generateHooksHandler,
}

c.Flags().AddFlagSet(flagSetYes())
Expand Down
7 changes: 3 additions & 4 deletions ignite/cmd/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (

func NewGenerateOpenAPI() *cobra.Command {
c := &cobra.Command{
Use: "openapi",
Short: "OpenAPI spec for your chain",
PreRunE: gitChangesConfirmPreRunHandler,
RunE: generateOpenAPIHandler,
Use: "openapi",
Short: "OpenAPI spec for your chain",
RunE: generateOpenAPIHandler,
}

c.Flags().AddFlagSet(flagSetYes())
Expand Down
3 changes: 1 addition & 2 deletions ignite/cmd/generate_typescript_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ changes when the blockchain is started with a flag:

ignite chain serve --generate-clients
`,
PreRunE: gitChangesConfirmPreRunHandler,
RunE: generateTSClientHandler,
RunE: generateTSClientHandler,
}

c.Flags().AddFlagSet(flagSetYes())
Expand Down
7 changes: 3 additions & 4 deletions ignite/cmd/generate_vuex.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (

func NewGenerateVuex() *cobra.Command {
c := &cobra.Command{
Use: "vuex",
Short: "*DEPRECATED* TypeScript frontend client and Vuex stores",
PreRunE: gitChangesConfirmPreRunHandler,
RunE: generateVuexHandler,
Use: "vuex",
Short: "*DEPRECATED* TypeScript frontend client and Vuex stores",
RunE: generateVuexHandler,
}

c.Flags().AddFlagSet(flagSetYes())
Expand Down
15 changes: 15 additions & 0 deletions ignite/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ with an "--ibc" flag. Note that the default module is not IBC-enabled.
return c
}

func migrationPreRunHandler(cmd *cobra.Command, args []string) error {
if err := gitChangesConfirmPreRunHandler(cmd, args); err != nil {
return err
}

session := cliui.New()
defer session.End()

if err := toolsMigrationPreRunHandler(cmd, session); err != nil {
return err
}

return bufMigrationPreRunHandler(cmd, session)
}

func scaffoldType(
cmd *cobra.Command,
args []string,
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_band.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewScaffoldBandchain() *cobra.Command {
Short: "Scaffold an IBC BandChain query oracle to request real-time data",
Long: "Scaffold an IBC BandChain query oracle to request real-time data from BandChain scripts in a specific IBC-enabled Cosmos SDK module",
Args: cobra.MinimumNArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: createBandchainHandler,
Hidden: true,
}
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ The "creator" field is not generated if a list is scaffolded with the
"--no-message" flag.
`,
Args: cobra.MinimumNArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: scaffoldListHandler,
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ the "--no-message", "--module", "--signer" flags as well as the colon syntax for
custom types.
`,
Args: cobra.MinimumNArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: scaffoldMapHandler,
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ supports fields with standard and custom types. See "ignite scaffold list —hel
for details.
`,
Args: cobra.MinimumNArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: messageHandler,
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Refer to Cosmos SDK documentation to learn more about modules, dependencies and
params.
`,
Args: cobra.ExactArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: scaffoldModuleHandler,
}

Expand Down
11 changes: 6 additions & 5 deletions ignite/cmd/scaffold_mwasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (

func NewScaffoldWasm() *cobra.Command {
c := &cobra.Command{
Use: "wasm",
Short: "Import the wasm module to your app",
Long: "Add support for WebAssembly smart contracts to your blockchain",
Args: cobra.NoArgs,
RunE: scaffoldWasmHandler,
Use: "wasm",
Short: "Import the wasm module to your app",
Long: "Add support for WebAssembly smart contracts to your blockchain",
Args: cobra.NoArgs,
RunE: scaffoldWasmHandler,
PreRunE: migrationPreRunHandler,
}

flagSetPath(c)
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewScaffoldPacket() *cobra.Command {
Short: "Message for sending an IBC packet",
Long: "Scaffold an IBC packet in a specific IBC-enabled Cosmos SDK module",
Args: cobra.MinimumNArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: createPacketHandler,
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewScaffoldQuery() *cobra.Command {
Use: "query [name] [request_field1] [request_field2] ...",
Short: "Query for fetching data from a blockchain",
Args: cobra.MinimumNArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: queryHandler,
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_react.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewScaffoldReact() *cobra.Command {
Use: "react",
Short: "React web app template",
Args: cobra.NoArgs,
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: scaffoldReactHandler,
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_single.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewScaffoldSingle() *cobra.Command {
Use: "single NAME [field]...",
Short: "CRUD for data stored in a single location",
Args: cobra.MinimumNArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: scaffoldSingleHandler,
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewScaffoldType() *cobra.Command {
Use: "type NAME [field]...",
Short: "Type definition",
Args: cobra.MinimumNArgs(1),
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: scaffoldTypeHandler,
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_vue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewScaffoldVue() *cobra.Command {
Use: "vue",
Short: "Vue 3 web app template",
Args: cobra.NoArgs,
PreRunE: gitChangesConfirmPreRunHandler,
PreRunE: migrationPreRunHandler,
RunE: scaffoldVueHandler,
}

Expand Down
Loading