Skip to content

Commit

Permalink
feat(pkg): improve xgenny dry run (#4001)
Browse files Browse the repository at this point in the history
* run all dry runners before the we runners for the xgenny pkg

* add changelog

* Improve `xgenny` dry run

* replace the last wet runners

* create RunAndApply runner function

* remove unused parameters from scaffold functions and fix wrong path for scaffold chain

* run go mod tidy before go fmt

* bump buf build

* fix golden files for apps tests

* create the runner target path if not exist

* update go.mod

* fix lint issue

* fix doctor absolute path

* re-organize xgenny pkg

* fix lint warning

---------

Co-authored-by: Pantani <Pantani>
  • Loading branch information
Pantani authored and julienrbrt committed May 29, 2024
1 parent f6ef94c commit 6a499af
Show file tree
Hide file tree
Showing 28 changed files with 416 additions and 430 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [#3707](https://github.com/ignite/cli/pull/3707) Add collections support.
- [#3977](https://github.com/ignite/cli/pull/3977) Add `chain lint` command to lint the chain's codebase using `golangci-lint`
- [#3770](https://github.com/ignite/cli/pull/3770) Add `scaffold configs` and `scaffold params` commands
- [#4001](https://github.com/ignite/cli/pull/4001) Improve `xgenny` dry run
- [#3967](https://github.com/ignite/cli/issues/3967) Add HD wallet parameters `address index` and `account number` to the chain account config
- [#4004](https://github.com/ignite/cli/pull/4004) Remove all import placeholders using the `xast` pkg

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
github.com/go-delve/delve v1.21.0
github.com/go-git/go-git/v5 v5.11.0
github.com/gobuffalo/genny/v2 v2.1.0
github.com/gobuffalo/logger v1.0.7
github.com/gobuffalo/packd v1.0.2
github.com/gobuffalo/plush/v4 v4.1.19
github.com/goccy/go-yaml v1.11.2
Expand Down Expand Up @@ -243,6 +242,7 @@ require (
github.com/gobuffalo/flect v0.3.0 // indirect
github.com/gobuffalo/github_flavored_markdown v1.1.4 // indirect
github.com/gobuffalo/helpers v0.6.7 // indirect
github.com/gobuffalo/logger v1.0.7 // indirect
github.com/gobuffalo/tags/v3 v3.1.4 // indirect
github.com/gobuffalo/validate/v3 v3.3.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
Expand Down
4 changes: 3 additions & 1 deletion ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ignite/cli/v29/ignite/pkg/goanalysis"
"github.com/ignite/cli/v29/ignite/pkg/gomodulepath"
"github.com/ignite/cli/v29/ignite/pkg/xast"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/services/chain"
"github.com/ignite/cli/v29/ignite/services/doctor"
)
Expand Down Expand Up @@ -201,7 +202,8 @@ func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPa
}
}

sm, err := chain.BoxBufFiles(appPath)
runner := xgenny.NewRunner(cmd.Context(), appPath)
sm, err := chain.BoxBufFiles(runner, appPath)
if err != nil {
return err
}
Expand Down
12 changes: 7 additions & 5 deletions ignite/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/ignite/cli/v29/ignite/pkg/cosmosver"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/gomodulepath"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/pkg/xgit"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
"github.com/ignite/cli/v29/ignite/version"
Expand Down Expand Up @@ -208,7 +206,7 @@ func scaffoldType(
session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
defer session.End()

sc, err := scaffolder.New(appPath)
sc, err := scaffolder.New(cmd.Context(), appPath)
if err != nil {
return err
}
Expand All @@ -218,16 +216,20 @@ func scaffoldType(
return err
}

sm, err := sc.AddType(cmd.Context(), cacheStorage, typeName, placeholder.New(), kind, options...)
err = sc.AddType(cmd.Context(), typeName, kind, options...)
if err != nil {
return err
}

modificationsStr, err := xgenny.SourceModificationToString(sm)
modificationsStr, err := sc.ApplyModifications()
if err != nil {
return err
}

if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}

session.Println(modificationsStr)
session.Printf("\n🎉 %s added. \n\n", typeName)

Expand Down
26 changes: 20 additions & 6 deletions ignite/cmd/scaffold_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/pkg/xfilepath"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/pkg/xgit"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
)

Expand Down Expand Up @@ -123,16 +124,14 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error {
return err
}

appDir, err := scaffolder.Init(
runner := xgenny.NewRunner(cmd.Context(), appPath)
appDir, goModule, err := scaffolder.Init(
cmd.Context(),
cacheStorage,
placeholder.New(),
runner,
appPath,
name,
addressPrefix,
noDefaultModule,
skipGit,
skipProto,
minimal,
isConsumer,
params,
Expand All @@ -147,5 +146,20 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error {
return err
}

if _, err := runner.ApplyModifications(); err != nil {
return err
}

if err := scaffolder.PostScaffold(cmd.Context(), cacheStorage, appDir, goModule, skipProto); err != nil {
return err
}

if !skipGit {
// Initialize git repository and perform the first commit
if err := xgit.InitAndCommit(path); err != nil {
return err
}
}

return session.Printf(tplScaffoldChainSuccess, path)
}
12 changes: 7 additions & 5 deletions ignite/cmd/scaffold_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
)

Expand Down Expand Up @@ -58,21 +56,25 @@ func scaffoldConfigsHandler(cmd *cobra.Command, args []string) error {
return err
}

sc, err := scaffolder.New(appPath)
sc, err := scaffolder.New(cmd.Context(), appPath)
if err != nil {
return err
}

sm, err := sc.CreateConfigs(cmd.Context(), cacheStorage, placeholder.New(), moduleName, configs...)
err = sc.CreateConfigs(moduleName, configs...)
if err != nil {
return err
}

modificationsStr, err := xgenny.SourceModificationToString(sm)
modificationsStr, err := sc.ApplyModifications()
if err != nil {
return err
}

if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}

session.Println(modificationsStr)
session.Printf("\n🎉 New configs added to the module:\n\n- %s\n\n", strings.Join(configs, "\n- "))

Expand Down
12 changes: 7 additions & 5 deletions ignite/cmd/scaffold_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
)

Expand Down Expand Up @@ -115,21 +113,25 @@ func messageHandler(cmd *cobra.Command, args []string) error {
options = append(options, scaffolder.WithoutSimulation())
}

sc, err := scaffolder.New(appPath)
sc, err := scaffolder.New(cmd.Context(), appPath)
if err != nil {
return err
}

sm, err := sc.AddMessage(cmd.Context(), cacheStorage, placeholder.New(), module, args[0], args[1:], resFields, options...)
err = sc.AddMessage(cmd.Context(), module, args[0], args[1:], resFields, options...)
if err != nil {
return err
}

modificationsStr, err := xgenny.SourceModificationToString(sm)
modificationsStr, err := sc.ApplyModifications()
if err != nil {
return err
}

if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}

session.Println(modificationsStr)
session.Printf("\n🎉 Created a message `%[1]v`.\n\n", args[0])

Expand Down
39 changes: 10 additions & 29 deletions ignite/cmd/scaffold_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/pkg/validation"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
modulecreate "github.com/ignite/cli/v29/ignite/templates/module/create"
)
Expand All @@ -29,14 +27,6 @@ const (
flagModuleConfigs = "module-configs"
flagIBCOrdering = "ordering"
flagRequireRegistration = "require-registration"

govDependencyWarning = `⚠️ If your app has been scaffolded with Ignite CLI 0.16.x or below
Please make sure that your module keeper definition is defined after gov module keeper definition in app/app.go:
app.GovKeeper = ...
...
[your module keeper definition]
`
)

// NewScaffoldModule returns the command to scaffold a Cosmos SDK module.
Expand Down Expand Up @@ -181,39 +171,30 @@ func scaffoldModuleHandler(cmd *cobra.Command, args []string) error {
var msg bytes.Buffer
fmt.Fprintf(&msg, "\n🎉 Module created %s.\n\n", name)

sc, err := scaffolder.New(appPath)
sc, err := scaffolder.New(cmd.Context(), appPath)
if err != nil {
return err
}

sm, err := sc.CreateModule(cmd.Context(), cacheStorage, placeholder.New(), name, options...)
if err != nil {
if err := sc.CreateModule(name, options...); err != nil {
var validationErr validation.Error
if !requireRegistration && errors.As(err, &validationErr) {
fmt.Fprintf(&msg, "Can't register module '%s'.\n", name)
fmt.Fprintln(&msg, validationErr.ValidationInfo())
} else {
return err
}
} else {
modificationsStr, err := xgenny.SourceModificationToString(sm)
if err != nil {
return err
}

session.Println(modificationsStr)
}
modificationsStr, err := sc.ApplyModifications()
if err != nil {
return err
}

// in previously scaffolded apps gov keeper is defined below the scaffolded module keeper definition
// therefore we must warn the user to manually move the definition if it's the case
// https://github.com/ignite/cli/issues/818#issuecomment-865736052
for _, name := range dependencies {
if name == "Gov" {
session.Print(govDependencyWarning)

break
}
if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}

session.Println(modificationsStr)

return session.Print(msg.String())
}
12 changes: 7 additions & 5 deletions ignite/cmd/scaffold_package.go → ignite/cmd/scaffold_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
)

Expand Down Expand Up @@ -68,21 +66,25 @@ func createPacketHandler(cmd *cobra.Command, args []string) error {
options = append(options, scaffolder.PacketWithSigner(signer))
}

sc, err := scaffolder.New(appPath)
sc, err := scaffolder.New(cmd.Context(), appPath)
if err != nil {
return err
}

sm, err := sc.AddPacket(cmd.Context(), cacheStorage, placeholder.New(), module, packet, packetFields, ackFields, options...)
err = sc.AddPacket(cmd.Context(), module, packet, packetFields, ackFields, options...)
if err != nil {
return err
}

modificationsStr, err := xgenny.SourceModificationToString(sm)
modificationsStr, err := sc.ApplyModifications()
if err != nil {
return err
}

if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}

session.Println(modificationsStr)
session.Printf("\n🎉 Created a packet `%[1]v`.\n\n", args[0])

Expand Down
12 changes: 7 additions & 5 deletions ignite/cmd/scaffold_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
)

Expand Down Expand Up @@ -60,21 +58,25 @@ func scaffoldParamsHandler(cmd *cobra.Command, args []string) error {
return err
}

sc, err := scaffolder.New(appPath)
sc, err := scaffolder.New(cmd.Context(), appPath)
if err != nil {
return err
}

sm, err := sc.CreateParams(cmd.Context(), cacheStorage, placeholder.New(), moduleName, params...)
err = sc.CreateParams(moduleName, params...)
if err != nil {
return err
}

modificationsStr, err := xgenny.SourceModificationToString(sm)
modificationsStr, err := sc.ApplyModifications()
if err != nil {
return err
}

if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}

session.Println(modificationsStr)
session.Printf("\n🎉 New parameters added to the module:\n\n- %s\n\n", strings.Join(params, "\n- "))

Expand Down
12 changes: 7 additions & 5 deletions ignite/cmd/scaffold_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/spf13/cobra"

"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/placeholder"
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
"github.com/ignite/cli/v29/ignite/services/scaffolder"
)

Expand Down Expand Up @@ -66,21 +64,25 @@ func queryHandler(cmd *cobra.Command, args []string) error {
return err
}

sc, err := scaffolder.New(appPath)
sc, err := scaffolder.New(cmd.Context(), appPath)
if err != nil {
return err
}

sm, err := sc.AddQuery(cmd.Context(), cacheStorage, placeholder.New(), module, args[0], desc, args[1:], resFields, paginated)
err = sc.AddQuery(cmd.Context(), module, args[0], desc, args[1:], resFields, paginated)
if err != nil {
return err
}

modificationsStr, err := xgenny.SourceModificationToString(sm)
modificationsStr, err := sc.ApplyModifications()
if err != nil {
return err
}

if err := sc.PostScaffold(cmd.Context(), cacheStorage, false); err != nil {
return err
}

session.Println(modificationsStr)
session.Printf("\n🎉 Created a query `%[1]v`.\n\n", args[0])

Expand Down
Loading

0 comments on commit 6a499af

Please sign in to comment.