Skip to content

Commit

Permalink
feat: use buf.build binary to generate the proto files (#3476)
Browse files Browse the repository at this point in the history
* build buf pkg

* fix go.mod

* comment xbug pkg and bump buf versions

* generate proto from buf and remove protoc and plugins

* add proto ts and api generation

* add changelog

* fix proto and template path

* fix wrong template for ts generation

* fix api out path

* fix ts out path and remove unused log

* fix go.mod ident and sort

* remove unused method

* fix lint

* fix wrong lint comment

* remove unused tools

* fix doctor for tools pkg

* add missing tool dependency

* add missing import

* add global protoanalysis.NewCache to buf structure

* fix proto module name

* update go.mod

* Update ignite/pkg/cosmosgen/generate_go.go method name

Co-authored-by: Jerónimo Albi <[email protected]>

* Update ignite/pkg/buf/buf.go remove unused ctx

Co-authored-by: Jerónimo Albi <[email protected]>

* fix wrong method call

* fix deep tools

* fix ignite doctor

* fix buf.gen files

* fix proto gen files

* remove 3thrparty  mod

* thr modules openapi

* add xos copy commands

* fix wrong proto tmp path

* remove unused method

* update tools for the doctor command

* unhlanded error

* check if the buf files exists

* remove unused ctx

* fix changelog merge

* fix unit tests and make more dynamic

* Update changelog

Co-authored-by: İlker G. Öztürk <[email protected]>

* fix ts script generation and remove pulsar buf files

* fix changelog

* fix changelog

* add migration for scaffold and generate commands

* fix pre handler

* fix rance condition

* fix wrong app path for tools migrations

* fix lint

* rollback draft changes

* fix ineffassign lint

* fix wrong path

* move buf pkg to cosmosbuf

* increase test timeout

---------

Co-authored-by: Jerónimo Albi <[email protected]>
Co-authored-by: İlker G. Öztürk <[email protected]>
Co-authored-by: Danilo Pantani <[email protected]>
Co-authored-by: Pantani <Pantani>
  • Loading branch information
4 people authored Jul 3, 2023
1 parent 75d3338 commit f7acf08
Show file tree
Hide file tree
Showing 82 changed files with 1,076 additions and 3,809 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
go-version: 1.19
- name: Run Integration Tests
if: env.GIT_DIFF
run: GOSUMDB=off go test -v -timeout 80m ./integration/${{ matrix.test-path }}
run: GOSUMDB=off go test -v -timeout 120m ./integration/${{ matrix.test-path }}

status:
runs-on: ubuntu-latest
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@ on:
- main
jobs:
lint:
name: golangci-lint
name: Lint Go code
runs-on: ubuntu-latest
timeout-minutes: 6
steps:
- uses: actions/[email protected]

- uses: technote-space/[email protected]
with:
PATTERNS: |
**/*.go
go.mod
go.sum
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19

- uses: golangci/golangci-lint-action@v3
with:
version: v1.52.1
Expand Down
12 changes: 9 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

## Unreleased

- [#3559](https://github.com/ignite/cli/pull/3559) Bump network plugin version to `v0.1.1`
### Features

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

### Features
### Changes

- [#3559](https://github.com/ignite/cli/pull/3559) Bump network plugin version to `v0.1.1`

## [`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
59 changes: 51 additions & 8 deletions ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ 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"
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"
)

var ErrProtocUnsupported = errors.New("code generation using protoc is only supported by Ignite CLI v0.26.1 or older")

// NewChain returns a command that groups sub commands related to compiling, serving
// blockchains and so on.
func NewChain() *cobra.Command {
Expand Down Expand Up @@ -109,13 +116,28 @@ 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) {
func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) error {
session.StartSpinner("Checking missing tools...")

appPath := flagGetPath(cmd)
path := flagGetPath(cmd)
path, err := filepath.Abs(path)
if err != nil {
return err
}

_, appPath, err := gomodulepath.Find(path)
if err != nil {
return err
}

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 +154,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 +165,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 +186,27 @@ 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 ErrProtocUnsupported
}

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
Loading

0 comments on commit f7acf08

Please sign in to comment.