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

refactor(scaffold): refactor cosmosver and print the migration guide #1550

Merged
merged 35 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b862a02
print migration tests
Pantani Sep 7, 2021
89c6c28
convert entire folder from localfs
Pantani Sep 8, 2021
8b99888
Merge branch 'develop' into feat/print-migration
Pantani Sep 8, 2021
a2184b1
use sub instead create a new embed.FS
Pantani Sep 10, 2021
3740767
fix linter and migration dir
Pantani Sep 10, 2021
b064895
fix cmd
Pantani Sep 10, 2021
727eea0
add examples
Pantani Sep 10, 2021
787c945
improve template parse
Pantani Sep 10, 2021
124ecfb
Merge branch 'develop' into feat/print-migration
Pantani Sep 10, 2021
747db61
show a warning if cosmos SDK version is too old
Pantani Sep 11, 2021
9c35eab
Merge branch 'develop' into feat/print-migration
Pantani Sep 13, 2021
9da118b
Merge branch 'develop' into feat/print-migration
Pantani Sep 14, 2021
4a660f6
Merge branch 'develop' into feat/print-migration
Pantani Sep 14, 2021
f6aded3
Merge branch 'develop' into feat/print-migration
Pantani Sep 14, 2021
dd7d3b9
remove html from markdown generation
Pantani Sep 15, 2021
5dfb65f
Merge branch 'develop' into feat/print-migration
Pantani Sep 16, 2021
6a1cfe8
add version checker every time a user scaffolds something and there i…
Pantani Sep 16, 2021
3937c03
avoid read parse parse `go.mod` twice
Pantani Sep 17, 2021
fec5714
create newApp method to check the app version
Pantani Sep 20, 2021
87d5b32
Merge branch 'develop' into feat/print-migration
ilgooz Sep 20, 2021
ab31296
remove `GetVersion` method and `Export` version field
Pantani Sep 20, 2021
233b535
Merge branch 'develop' into feat/print-migration
Pantani Sep 21, 2021
cba7180
create versioning structure
Pantani Sep 21, 2021
0d473db
pass the spinner obj to the newApp method
Pantani Sep 21, 2021
08b22ae
fix warning msg condition
Pantani Sep 21, 2021
235b71d
Merge branch 'develop' into feat/print-migration
Pantani Sep 22, 2021
5dbc585
refactor(pkg/cosmosver): refactor (#1607)
ilgooz Sep 22, 2021
6cd413c
Update starport/pkg/cosmosver/cosmosver.go
ilgooz Sep 22, 2021
03b822d
Merge branch 'develop' into feat/print-migration
Pantani Sep 22, 2021
9c24c2b
fix ci lint
Pantani Sep 22, 2021
58fec22
Merge branch 'develop' into feat/print-migration
Pantani Sep 22, 2021
0d0d504
Merge branch 'develop' into feat/print-migration
Pantani Sep 23, 2021
48ee623
update warning message
Pantani Sep 23, 2021
a6c49e2
return error for version mismatch and remove 0.43.0
Pantani Sep 23, 2021
fb19fa1
run gofmt
Pantani Sep 23, 2021
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
20 changes: 20 additions & 0 deletions starport/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/tendermint/starport/starport/pkg/clispinner"
"github.com/tendermint/starport/starport/pkg/cosmosver"
"github.com/tendermint/starport/starport/pkg/placeholder"
"github.com/tendermint/starport/starport/services/scaffolder"
)
Expand Down Expand Up @@ -100,6 +101,7 @@ func scaffoldType(

fmt.Printf("\n🎉 %s added. \n\n", typeName)

checkVersion(appPath)
return nil
}

Expand All @@ -125,3 +127,21 @@ func flagGetSigner(cmd *cobra.Command) string {
signer, _ := cmd.Flags().GetString(flagSigner)
return signer
}

func checkVersion(path string) {
version, err := cosmosver.Detect(path)
if err != nil {
return
}

if !version.Is(cosmosver.StargateZeroFortyThreeAndAbove) {
fmt.Printf(`

⚠️ Your app has been scaffolded with an old Cosmos SDK version: %[1]v.
Please make sure that your chain is updated following the migration guidelines from this folder:

https://docs.starport.network/migration

`, version.String())
}
}
2 changes: 2 additions & 0 deletions starport/cmd/scaffold_band.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,7 @@ Make sure to update the keys.go file accordingly.
const Version = "bandchain-1"

`, oracle, module)

checkVersion(appPath)
return nil
}
2 changes: 2 additions & 0 deletions starport/cmd/scaffold_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,7 @@ func messageHandler(cmd *cobra.Command, args []string) error {
fmt.Println(modificationsStr)

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

checkVersion(appPath)
return nil
}
2 changes: 2 additions & 0 deletions starport/cmd/scaffold_mwasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ func scaffoldWasmHandler(cmd *cobra.Command, args []string) error {
fmt.Println(modificationsStr)

fmt.Printf("\n🎉 Imported wasm.\n\n")

checkVersion(appPath)
return nil
}
2 changes: 2 additions & 0 deletions starport/cmd/scaffold_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,7 @@ func createPacketHandler(cmd *cobra.Command, args []string) error {
fmt.Println(modificationsStr)

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

checkVersion(appPath)
return nil
}
2 changes: 2 additions & 0 deletions starport/cmd/scaffold_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ func queryHandler(cmd *cobra.Command, args []string) error {
fmt.Println(modificationsStr)

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

checkVersion(appPath)
return nil
}
4 changes: 2 additions & 2 deletions starport/pkg/chaincmd/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ func (c ChainCmd) GentxCommand(
commandGentx,
}

if c.sdkVersion.Is(cosmosver.StargateZeroFourtyAndAbove) {
if c.sdkVersion.Is(cosmosver.StargateZeroFortyToZeroFortyTwo) {
Pantani marked this conversation as resolved.
Show resolved Hide resolved
command = append(command,
validatorName,
selfDelegation,
)
}

if c.sdkVersion.Is(cosmosver.StargateBelowZeroFourty) {
if c.sdkVersion.Is(cosmosver.StargateBelowZeroForty) {
command = append(command,
validatorName,
optionAmount,
Expand Down
2 changes: 1 addition & 1 deletion starport/pkg/chaincmd/runner/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (r Runner) Status(ctx context.Context) (NodeStatus, error) {
}

switch r.chainCmd.SDKVersion() {
case cosmosver.StargateZeroFourtyAndAbove:
case cosmosver.StargateZeroFortyToZeroFortyTwo:
Pantani marked this conversation as resolved.
Show resolved Hide resolved
out := struct {
NodeInfo struct {
Network string `json:"network"`
Expand Down
24 changes: 15 additions & 9 deletions starport/pkg/cosmosver/cosmosver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const (
const (
LaunchpadAny Version = iota

StargateBelowZeroFourty
StargateBelowZeroForty

StargateZeroFourtyAndAbove
StargateZeroFortyToZeroFortyTwo

StargateZeroFortyThreeAndAbove
)

// MajorVersions are the list of supported Cosmos-SDK major versions.
Expand All @@ -30,8 +32,9 @@ var (

Versions = versions{
LaunchpadAny,
StargateBelowZeroFourty,
StargateZeroFourtyAndAbove,
StargateBelowZeroForty,
StargateZeroFortyToZeroFortyTwo,
StargateZeroFortyThreeAndAbove,
}
)

Expand All @@ -52,7 +55,7 @@ func (v Version) Is(comparedTo Version) bool {
// Major returns the MajorVersion of the version.
func (v Version) Major() MajorVersion {
switch v {
case StargateBelowZeroFourty, StargateZeroFourtyAndAbove:
case StargateBelowZeroForty, StargateZeroFortyToZeroFortyTwo, StargateZeroFortyThreeAndAbove:
Pantani marked this conversation as resolved.
Show resolved Hide resolved
return Stargate
default:
return Launchpad
Expand All @@ -61,11 +64,14 @@ func (v Version) Major() MajorVersion {

func (v Version) String() string {
switch v {
case StargateZeroFourtyAndAbove:
return "Stargate v0.40.0 (or later)"
case StargateZeroFortyToZeroFortyTwo:
return "Stargate v0.40.x - v0.42.x"

case StargateBelowZeroForty:
return "Stargate v0.39.9"
Pantani marked this conversation as resolved.
Show resolved Hide resolved

case StargateBelowZeroFourty:
return "Stargate v0.40.0 (pre-release)"
case StargateZeroFortyThreeAndAbove:
return "Stargate v0.43 (or later)"

default:
return "Launchpad"
Expand Down
16 changes: 10 additions & 6 deletions starport/pkg/cosmosver/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
)

const (
cosmosModulePath = "github.com/cosmos/cosmos-sdk"
cosmosModuleMaxLaunchpadTag = "v0.39.99"
cosmosModuleStargateTag = "v0.40.0"
cosmosModulePath = "github.com/cosmos/cosmos-sdk"
cosmosModuleMaxLaunchpadTag = "v0.39.99"
cosmosModuleStargateFortyTag = "v0.40.0"
cosmosModuleStargateFortyThreeTag = "v0.43.0"
Pantani marked this conversation as resolved.
Show resolved Hide resolved
)

// Detect detects major version of Cosmos.
Expand All @@ -21,14 +22,17 @@ func Detect(appPath string) (Version, error) {
v := r.Mod
if v.Path == cosmosModulePath {
switch {
case semver.Compare(v.Version, cosmosModuleStargateTag) >= 0:
return StargateZeroFourtyAndAbove, nil
case semver.Compare(v.Version, cosmosModuleStargateFortyThreeTag) >= 0:
return StargateZeroFortyThreeAndAbove, nil

case semver.Compare(v.Version, cosmosModuleStargateFortyTag) >= 0:
return StargateZeroFortyToZeroFortyTwo, nil

case semver.Compare(v.Version, cosmosModuleMaxLaunchpadTag) <= 0:
return LaunchpadAny, nil

default:
return StargateBelowZeroFourty, nil
return StargateBelowZeroForty, nil
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion starport/services/scaffolder/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func isWasmImported(appPath string) (bool, error) {

func (s Scaffolder) installWasm() error {
switch s.version {
case cosmosver.StargateZeroFourtyAndAbove:
case cosmosver.StargateZeroFortyToZeroFortyTwo, cosmosver.StargateZeroFortyThreeAndAbove:
return cmdrunner.
New().
Run(context.Background(),
Expand Down