From ca22fb7f33d9644501459cdb87b6b275aa610157 Mon Sep 17 00:00:00 2001 From: tanlang Date: Wed, 21 Jun 2023 11:32:24 +0800 Subject: [PATCH 1/3] fix: repo compatibility for cli --- cli/cmd.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- main.go | 36 ++---------------------------------- 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/cli/cmd.go b/cli/cmd.go index 68a35df3..4853628a 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -2,6 +2,9 @@ package cli import ( "context" + "errors" + "fmt" + "os" "github.com/filecoin-project/go-jsonrpc" v1 "github.com/filecoin-project/venus/venus-shared/api/chain/v1" @@ -15,6 +18,11 @@ import ( "github.com/filecoin-project/venus/venus-shared/api/messager" ) +const ( + OldRepoPath = "~/.venus-messager" + DefRepoPath = "~/.sophon-messager" +) + func getAPI(ctx *cli.Context) (messager.IMessager, jsonrpc.ClientCloser, error) { repo, err := getRepo(ctx) if err != nil { @@ -61,7 +69,7 @@ func LoadBuiltinActors(ctx context.Context, nodeAPI v1.FullNode) error { } func getRepo(ctx *cli.Context) (filestore.FSRepo, error) { - repoPath, err := homedir.Expand(ctx.String("repo")) + repoPath, err := GetRepoPath(ctx) if err != nil { return nil, err } @@ -71,3 +79,44 @@ func getRepo(ctx *cli.Context) (filestore.FSRepo, error) { } return repo, nil } + +func GetRepoPath(cctx *cli.Context) (string, error) { + repoPath, err := homedir.Expand(cctx.String("repo")) + if err != nil { + return "", err + } + has, err := hasFSRepo(repoPath) + if err != nil { + return "", err + } + if !has { + // check old repo path + rPath, err := homedir.Expand(OldRepoPath) + if err != nil { + return "", err + } + has, err = hasFSRepo(rPath) + if err != nil { + return "", err + } + if has { + return rPath, nil + } + } + return repoPath, nil +} + +func hasFSRepo(repoPath string) (bool, error) { + fi, err := os.Stat(repoPath) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + return false, nil + } + return false, err + } + if !fi.IsDir() { + return false, fmt.Errorf("%s is not a folder", repoPath) + } + + return true, nil +} diff --git a/main.go b/main.go index e4d59683..ac36c431 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,6 @@ import ( "github.com/ipfs-force-community/sophon-messager/publisher" "github.com/ipfs-force-community/sophon-messager/publisher/pubsub" - "github.com/mitchellh/go-homedir" "github.com/filecoin-project/venus/fixtures/networks" v1 "github.com/filecoin-project/venus/venus-shared/api/chain/v1" @@ -38,11 +37,6 @@ import ( "github.com/ipfs-force-community/sophon-messager/version" ) -const ( - oldRepoPath = "~/.venus-messager" - defRepoPath = "~/.sophon-messager" -) - var log = logging.Logger("main") func main() { @@ -52,7 +46,7 @@ func main() { Flags: []cli.Flag{ &cli.StringFlag{ Name: "repo", - Value: defRepoPath, + Value: ccli.DefRepoPath, }, }, Commands: []*cli.Command{ @@ -142,7 +136,7 @@ func runAction(cctx *cli.Context) error { // Set the log level. The default log level is info utils.SetupLogLevels() - repoPath, err := getRepoPath(cctx) + repoPath, err := ccli.GetRepoPath(cctx) if err != nil { return err } @@ -442,29 +436,3 @@ func setEip155ChainID(networkName string) error { return nil } - -func getRepoPath(cctx *cli.Context) (string, error) { - repoPath, err := homedir.Expand(cctx.String("repo")) - if err != nil { - return "", err - } - has, err := hasFSRepo(repoPath) - if err != nil { - return "", err - } - if !has { - // check old repo path - rPath, err := homedir.Expand(oldRepoPath) - if err != nil { - return "", err - } - has, err = hasFSRepo(rPath) - if err != nil { - return "", err - } - if has { - return rPath, nil - } - } - return repoPath, nil -} From 857716ed44047a4420838590216508e6097ea52f Mon Sep 17 00:00:00 2001 From: tanlang Date: Wed, 21 Jun 2023 11:35:11 +0800 Subject: [PATCH 2/3] chore: push docker image by make --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index ad7bbb83..9c5eab66 100644 --- a/Makefile +++ b/Makefile @@ -44,4 +44,10 @@ ifdef PRIVATE_REGISTRY endif docker-push: docker +ifdef PRIVATE_REGISTRY docker push $(PRIVATE_REGISTRY)/filvenus/sophon-messager:$(TAG) +else + docker push filvenus/sophon-messager:$(TAG) + docker tag filvenus/sophon-messager:$(TAG) filvenus/sophon-messager:latest + docker push filvenus/sophon-messager:latest +endif From 6b20b103f355537a10c5fe93ca40c61cbfc112c7 Mon Sep 17 00:00:00 2001 From: tanlang Date: Wed, 21 Jun 2023 13:57:27 +0800 Subject: [PATCH 3/3] chore: bump version to v1.12.0-rc2 --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index 7086d002..4a9aca07 100644 --- a/version/version.go +++ b/version/version.go @@ -3,7 +3,7 @@ package version var ( CurrentCommit string - BuildVersion = "1.12.0-rc1" + BuildVersion = "1.12.0-rc2" Version = BuildVersion + CurrentCommit )