Skip to content

Commit

Permalink
fix: merge pull request #1404 from tendermint/hotfix/0.17.1
Browse files Browse the repository at this point in the history
fix: hotfix/0.17.1
  • Loading branch information
ilgooz authored Jul 27, 2021
2 parents 57f9982 + 81ecc77 commit b071eed
Show file tree
Hide file tree
Showing 20 changed files with 164 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ ports:
- port: 26657
- port: 8080
- port: 7575
visibility: public
- port: 4500
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
# Project variables.
PROJECT_NAME = starport
DATE := $(shell date '+%Y-%m-%dT%H:%M:%S')
VERSION = development
HEAD = $(shell git rev-parse HEAD)
LD_FLAGS = -X github.com/tendermint/starport/starport/internal/version.Version='$(VERSION)' \
-X github.com/tendermint/starport/starport/internal/version.Head='$(HEAD)' \
LD_FLAGS = -X github.com/tendermint/starport/starport/internal/version.Head='$(HEAD)' \
-X github.com/tendermint/starport/starport/internal/version.Date='$(DATE)'
BUILD_FLAGS = -mod=readonly -ldflags='$(LD_FLAGS)'
BUILD_FOLDER = ./dist
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.16
require (
github.com/AlecAivazis/survey/v2 v2.1.1
github.com/Microsoft/hcsshim v0.8.17 // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/briandowns/spinner v1.11.1
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/charmbracelet/glow v1.4.0
Expand All @@ -22,6 +23,7 @@ require (
github.com/gobuffalo/plush v3.8.3+incompatible
github.com/gobuffalo/plushgen v0.1.2
github.com/goccy/go-yaml v1.8.0
github.com/google/go-github/v37 v37.0.0
github.com/gookit/color v1.2.7
github.com/gorilla/mux v1.8.0
github.com/gorilla/rpc v1.2.0
Expand Down
8 changes: 7 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/briandowns/spinner v1.11.1 h1:OixPqDEcX3juo5AjQZAnFPbeUA0jvkp2qzB5gOZJ/L0=
Expand Down Expand Up @@ -595,8 +596,13 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github/v37 v37.0.0 h1:rCspN8/6kB1BAJWZfuafvHhyfIo5fkAulaP/3bOQ/tM=
github.com/google/go-github/v37 v37.0.0/go.mod h1:LM7in3NmXDrX58GbEHy7FtNLbI2JijX93RnMKvWG3m4=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down
2 changes: 1 addition & 1 deletion starport/cmd/chain_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func chainInitHandler(cmd *cobra.Command, args []string) error {
return err
}

if err := c.Init(cmd.Context()); err != nil {
if err := c.Init(cmd.Context(), true); err != nil {
return err
}

Expand Down
36 changes: 32 additions & 4 deletions starport/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package starportcmd

import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"time"

"github.com/fatih/color"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/tendermint/starport/starport/internal/version"
"github.com/tendermint/starport/starport/pkg/clispinner"
"github.com/tendermint/starport/starport/pkg/events"
"github.com/tendermint/starport/starport/pkg/goenv"
Expand All @@ -17,18 +21,19 @@ import (
"github.com/tendermint/starport/starport/services/networkbuilder"
)

const (
flagHome = "home"
)
const flagHome = "home"
const checkVersionTimeout = time.Millisecond * 600

var (
infoColor = color.New(color.FgYellow).SprintFunc()
)

// New creates a new root command for `starport` with its sub commands.
func New() *cobra.Command {
func New(ctx context.Context) *cobra.Command {
cobra.EnableCommandSorting = false

checkNewVersion(ctx)

c := &cobra.Command{
Use: "starport",
Short: "Starport offers everything you need to scaffold, test, build, and launch your blockchain",
Expand Down Expand Up @@ -162,3 +167,26 @@ func deprecated() []*cobra.Command {
},
}
}

func checkNewVersion(ctx context.Context) {
if os.Getenv("GITPOD_WORKSPACE_ID") != "" {
return
}

ctx, cancel := context.WithTimeout(ctx, checkVersionTimeout)
defer cancel()

isAvailable, next, err := version.CheckNext(ctx)
if err != nil || !isAvailable {
return
}

fmt.Printf(
· 🛸 Starport %q is available!
·
· If you're looking to upgrade check out the instructions: https://docs.starport.network/intro/install.html#upgrading-your-starport-installation
·
··
`, next)
}
2 changes: 1 addition & 1 deletion starport/cmd/starport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func main() {
ctx := clictx.From(context.Background())

err := starportcmd.New().ExecuteContext(ctx)
err := starportcmd.New(ctx).ExecuteContext(ctx)

if ctx.Err() == context.Canceled || err == context.Canceled {
fmt.Println("aborted")
Expand Down
3 changes: 2 additions & 1 deletion starport/internal/tools/gen-cli-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main
import (
"bufio"
"bytes"
"context"
"flag"
"fmt"
"io"
Expand Down Expand Up @@ -35,7 +36,7 @@ func main() {
outPath := flag.String("out", ".", ".md file path to place Starport CLI docs inside")
flag.Parse()

if err := generate(starportcmd.New(), *outPath); err != nil {
if err := generate(starportcmd.New(context.Background()), *outPath); err != nil {
log.Fatal(err)
}
}
Expand Down
44 changes: 43 additions & 1 deletion starport/internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package version

import (
"context"
"fmt"
"runtime"
"strings"

"github.com/blang/semver"
"github.com/google/go-github/v37/github"
)

const versionDev = "development"
const prefix = "v"

var (
// Version is the semantic version of Starport.
Version = ""
Version = versionDev

// Date is the build date of Starport.
Date = ""
Expand All @@ -16,6 +24,40 @@ var (
Head = ""
)

// CheckNext checks whether there is a new version of Starport.
func CheckNext(ctx context.Context) (isAvailable bool, version string, err error) {
if Version == versionDev {
return false, "", nil
}

latest, _, err := github.
NewClient(nil).
Repositories.
GetLatestRelease(ctx, "tendermint", "starport")

if err != nil {
return false, "", err
}

if latest.TagName == nil {
return false, "", nil
}

currentVersion, err := semver.Parse(strings.TrimPrefix(Version, prefix))
if err != nil {
return false, "", err
}

latestVersion, err := semver.Parse(strings.TrimPrefix(*latest.TagName, prefix))
if err != nil {
return false, "", err
}

isAvailable = latestVersion.GT(currentVersion)

return isAvailable, *latest.TagName, nil
}

// Long generates a detailed version info.
func Long() string {
output := fmt.Sprintf("starport version %s %s/%s -build date: %s",
Expand Down
5 changes: 5 additions & 0 deletions starport/pkg/gocmd/gocmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ func ParseTarget(t string) (goos, goarch string, err error) {

return parsed[0], parsed[1], nil
}

// PackageLiteral returns the string representation of package part of go get [package].
func PackageLiteral(path, version string) string {
return fmt.Sprintf("%s@%s", path, version)
}
7 changes: 5 additions & 2 deletions starport/services/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
)

// Init initializes the chain and applies all optional configurations.
func (c *Chain) Init(ctx context.Context) error {
func (c *Chain) Init(ctx context.Context, initAccounts bool) error {
conf, err := c.Config()
if err != nil {
return &CannotBuildAppError{err}
Expand All @@ -28,7 +28,10 @@ func (c *Chain) Init(ctx context.Context) error {
return err
}

return c.InitAccounts(ctx, conf)
if initAccounts {
return c.InitAccounts(ctx, conf)
}
return nil
}

// InitChain initializes the chain.
Expand Down
2 changes: 1 addition & 1 deletion starport/services/chain/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (c *Chain) serve(ctx context.Context, forceReset bool) error {
if !isInit || (appModified && !exportGenesisExists) {
fmt.Fprintln(c.stdLog().out, "💿 Initializing the app...")

if err := c.Init(ctx); err != nil {
if err := c.Init(ctx, true); err != nil {
return err
}
} else if appModified {
Expand Down
12 changes: 12 additions & 0 deletions starport/services/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package services

import (
"os"

"github.com/tendermint/starport/starport/pkg/xfilepath"
)

var (
// StarportConfPath returns the Starport Configuration directory
StarportConfPath = xfilepath.JoinFromHome(xfilepath.Path(".starport"))
)

// InitConfig creates config directory if it is not yet created
func InitConfig() error {
confPath, err := StarportConfPath()
if err != nil {
return err
}

return os.MkdirAll(confPath, 0755)
}
2 changes: 1 addition & 1 deletion starport/services/networkbuilder/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (b *Blockchain) init(
if _, err := chain.Build(ctx); err != nil {
return err
}
if err := chain.Init(ctx); err != nil {
if err := chain.Init(ctx, false); err != nil {
return err
}
b.builder.ev.Send(events.New(events.StatusDone, "Blockchain initialized"))
Expand Down
4 changes: 4 additions & 0 deletions starport/services/networkbuilder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func ConfigGet() (*Config, error) {

// ConfigSave saves the current state of Config.
func ConfigSave(c *Config) error {
if err := services.InitConfig(); err != nil {
return err
}

conf, err := confPath()
if err != nil {
return nil
Expand Down
6 changes: 2 additions & 4 deletions starport/services/networkbuilder/networkbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ func (b *Builder) Init(ctx context.Context, chainID string, source SourceOption,
}

// ensure the path for chain source exists
if err := os.MkdirAll(sourcePath, 0700); err != nil && !os.IsExist(err) {
if !os.IsExist(err) {
return nil, err
}
if err := os.MkdirAll(sourcePath, 0755); err != nil {
return nil, err
}

path = filepath.Join(sourcePath, chainID)
Expand Down
23 changes: 9 additions & 14 deletions starport/services/scaffolder/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import (
)

const (
wasmImport = "github.com/CosmWasm/wasmd"
appPkg = "app"
moduleDir = "x"
wasmVersion = "v0.16.0"
wasmImport = "github.com/CosmWasm/wasmd"
wasmVersion = "v0.16.0"
extrasImport = "github.com/tendermint/spm-extras"
extrasVersion = "v0.1.0"
appPkg = "app"
moduleDir = "x"
)

// moduleCreationOptions holds options for creating a new module
Expand Down Expand Up @@ -290,17 +292,10 @@ func (s *Scaffolder) installWasm() error {
switch s.version {
case cosmosver.StargateZeroFourtyAndAbove:
return cmdrunner.
New(
cmdrunner.DefaultStderr(os.Stderr),
).
New().
Run(context.Background(),
step.New(
step.Exec(
gocmd.Name(),
"get",
wasmImport+"@"+wasmVersion,
),
),
step.New(step.Exec(gocmd.Name(), "get", gocmd.PackageLiteral(wasmImport, wasmVersion))),
step.New(step.Exec(gocmd.Name(), "get", gocmd.PackageLiteral(extrasImport, extrasVersion))),
)
default:
return errors.New("version not supported")
Expand Down
2 changes: 1 addition & 1 deletion starport/templates/app/stargate/go.mod.plush
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/tendermint/spm v0.0.0-20210625155357-5a2c8d79013b
github.com/tendermint/spm v0.1.2
github.com/tendermint/tendermint v0.34.11
github.com/tendermint/tm-db v0.6.4
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced
Expand Down
Loading

0 comments on commit b071eed

Please sign in to comment.