From dd7929dc1ca95232cedbe5e7c0adb59742a94fce Mon Sep 17 00:00:00 2001 From: Bastien Rigaud Date: Wed, 25 Sep 2024 19:17:29 +0200 Subject: [PATCH 1/7] feat(#21726): Add NewShowUpgradeInfoCmd command --- tools/cosmovisor/cmd/cosmovisor/root.go | 1 + .../cosmovisor/cmd/cosmovisor/show_upgrade.go | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tools/cosmovisor/cmd/cosmovisor/show_upgrade.go diff --git a/tools/cosmovisor/cmd/cosmovisor/root.go b/tools/cosmovisor/cmd/cosmovisor/root.go index d9f6094d593c..d8c351f4c143 100644 --- a/tools/cosmovisor/cmd/cosmovisor/root.go +++ b/tools/cosmovisor/cmd/cosmovisor/root.go @@ -19,6 +19,7 @@ func NewRootCmd() *cobra.Command { configCmd, NewVersionCmd(), NewAddUpgradeCmd(), + NewShowUpgradeInfoCmd(), ) rootCmd.PersistentFlags().StringP(cosmovisor.FlagCosmovisorConfig, "c", "", "path to cosmovisor config file") diff --git a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go new file mode 100644 index 000000000000..3a604afde5d5 --- /dev/null +++ b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +func NewShowUpgradeInfoCmd() *cobra.Command { + showUpgradeInfo := &cobra.Command{ + Use: "show-upgrade-info ", + Short: "Show upgrade-info.json into stdout.", + SilenceUsage: true, + RunE: showUpgradeInfoCmd, + } + + return showUpgradeInfo +} + +func showUpgradeInfoCmd(cmd *cobra.Command, path string) error { + data, err := os.ReadFile(path) + if err != nil { + return fmt.Errorf("failed to read upgrade-info.json: %w", err) + } + + fmt.Println(string(data)) + + return nil +} From d258cffbd79ffa3bfc785cd0702d8f2e8ff4743b Mon Sep 17 00:00:00 2001 From: Bastien Rigaud Date: Thu, 26 Sep 2024 15:24:50 +0200 Subject: [PATCH 2/7] fix: stdout --- tools/cosmovisor/cmd/cosmovisor/show_upgrade.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go index 3a604afde5d5..7cdd4e9a1fdc 100644 --- a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go +++ b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go @@ -12,14 +12,19 @@ func NewShowUpgradeInfoCmd() *cobra.Command { Use: "show-upgrade-info ", Short: "Show upgrade-info.json into stdout.", SilenceUsage: true, + Args: cobra.ExactArgs(1), RunE: showUpgradeInfoCmd, } return showUpgradeInfo } -func showUpgradeInfoCmd(cmd *cobra.Command, path string) error { - data, err := os.ReadFile(path) +func showUpgradeInfoCmd(cmd *cobra.Command, args []string) error { + if len(args) != 1 { + return fmt.Errorf("expected exactly one argument") + } + + data, err := os.ReadFile(args[0]) if err != nil { return fmt.Errorf("failed to read upgrade-info.json: %w", err) } From aa7f8b1172bd05ca4846b06440bd07c22ba17317 Mon Sep 17 00:00:00 2001 From: Bastien Rigaud Date: Thu, 26 Sep 2024 16:01:39 +0200 Subject: [PATCH 3/7] fix: feedbacks --- .../cosmovisor/cmd/cosmovisor/show_upgrade.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go index 7cdd4e9a1fdc..32db1c5742d2 100644 --- a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go +++ b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go @@ -9,27 +9,28 @@ import ( func NewShowUpgradeInfoCmd() *cobra.Command { showUpgradeInfo := &cobra.Command{ - Use: "show-upgrade-info ", + Use: "show-upgrade-info", Short: "Show upgrade-info.json into stdout.", SilenceUsage: true, - Args: cobra.ExactArgs(1), RunE: showUpgradeInfoCmd, } return showUpgradeInfo } -func showUpgradeInfoCmd(cmd *cobra.Command, args []string) error { - if len(args) != 1 { - return fmt.Errorf("expected exactly one argument") - } - - data, err := os.ReadFile(args[0]) +func showUpgradeInfoCmd(cmd *cobra.Command) error { + data, err := os.ReadFile(cfg.UpgradeInfoFilePath()) if err != nil { + if os.IsNotExist(err) { + return fmt.Errorf("upgrade-info.json not found at %s: %w", args[0], err) + } return fmt.Errorf("failed to read upgrade-info.json: %w", err) } - fmt.Println(string(data)) + _, err = fmt.Fprintln(cmd.OutOrStdout(), string(data)) + if err != nil { + return fmt.Errorf("failed to write output: %w", err) + } return nil } From 5c9aca00b4946d7592dd713e9b8a4ee0011d40b3 Mon Sep 17 00:00:00 2001 From: Bastien Rigaud Date: Thu, 26 Sep 2024 21:55:56 +0200 Subject: [PATCH 4/7] fix: feedbacks --- tools/cosmovisor/cmd/cosmovisor/show_upgrade.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go index 32db1c5742d2..55492b7fe02a 100644 --- a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go +++ b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "cosmossdk.io/tools/cosmovisor" "github.com/spf13/cobra" ) @@ -19,6 +20,16 @@ func NewShowUpgradeInfoCmd() *cobra.Command { } func showUpgradeInfoCmd(cmd *cobra.Command) error { + configPath, err := cmd.Flags().GetString(cosmovisor.FlagCosmovisorConfig) + if err != nil { + return fmt.Errorf("failed to get config flag: %w", err) + } + + cfg, err := cosmovisor.GetConfigFromFile(configPath) + if err != nil { + return err + } + data, err := os.ReadFile(cfg.UpgradeInfoFilePath()) if err != nil { if os.IsNotExist(err) { From 1e842c5d021433495665bfe2797cd428031cecf3 Mon Sep 17 00:00:00 2001 From: Bastien Rigaud Date: Thu, 26 Sep 2024 23:19:30 +0200 Subject: [PATCH 5/7] fix: feedbacks --- tools/cosmovisor/cmd/cosmovisor/show_upgrade.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go index 55492b7fe02a..f9c320084207 100644 --- a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go +++ b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go @@ -12,7 +12,8 @@ func NewShowUpgradeInfoCmd() *cobra.Command { showUpgradeInfo := &cobra.Command{ Use: "show-upgrade-info", Short: "Show upgrade-info.json into stdout.", - SilenceUsage: true, + SilenceUsage: false, + Args: cobra.cobra.NoArgs, RunE: showUpgradeInfoCmd, } From 6bbf2ac531f1a34365e47d1fdd29b1f91f95296d Mon Sep 17 00:00:00 2001 From: Bastien Rigaud Date: Fri, 27 Sep 2024 10:07:24 +0200 Subject: [PATCH 6/7] update changelog --- tools/cosmovisor/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/cosmovisor/CHANGELOG.md b/tools/cosmovisor/CHANGELOG.md index a4c78e469c45..d3960bda3fbf 100644 --- a/tools/cosmovisor/CHANGELOG.md +++ b/tools/cosmovisor/CHANGELOG.md @@ -67,6 +67,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#16550](https://github.com/cosmos/cosmos-sdk/pull/16550) Add COSMOVISOR_CUSTOM_PREUPGRADE to cosmovisor to execute custom pre-upgrade scripts (separate from daemon `pre-upgrade` command). * [#16963](https://github.com/cosmos/cosmos-sdk/pull/16963) Add DAEMON_SHUTDOWN_GRACE to send interrupt and wait before sending kill. * [#15361](https://github.com/cosmos/cosmos-sdk/pull/15361) Add `cosmovisor config` command to display the configuration used by cosmovisor. +* [#21932](https://github.com/cosmos/cosmos-sdk/pull/21932) Add `cosmovisor show-upgrade-info` command to display the upgrade-info.json into stdout. ## Improvements From b0eaf1ae8f38a396c7802555a146a7f0707dc660 Mon Sep 17 00:00:00 2001 From: "Bastien R." Date: Sat, 28 Sep 2024 07:42:47 +0000 Subject: [PATCH 7/7] fix: changelog and lint --- tools/cosmovisor/CHANGELOG.md | 5 ++++- tools/cosmovisor/cmd/cosmovisor/show_upgrade.go | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/cosmovisor/CHANGELOG.md b/tools/cosmovisor/CHANGELOG.md index d3960bda3fbf..ae0de6b86ffe 100644 --- a/tools/cosmovisor/CHANGELOG.md +++ b/tools/cosmovisor/CHANGELOG.md @@ -40,6 +40,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#21462](https://github.com/cosmos/cosmos-sdk/pull/21462) Pass `stdin` to binary. +### Features + +* [#21932](https://github.com/cosmos/cosmos-sdk/pull/21932) Add `cosmovisor show-upgrade-info` command to display the upgrade-info.json into stdout. + ## v1.6.0 - 2024-08-12 ## Improvements @@ -67,7 +71,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#16550](https://github.com/cosmos/cosmos-sdk/pull/16550) Add COSMOVISOR_CUSTOM_PREUPGRADE to cosmovisor to execute custom pre-upgrade scripts (separate from daemon `pre-upgrade` command). * [#16963](https://github.com/cosmos/cosmos-sdk/pull/16963) Add DAEMON_SHUTDOWN_GRACE to send interrupt and wait before sending kill. * [#15361](https://github.com/cosmos/cosmos-sdk/pull/15361) Add `cosmovisor config` command to display the configuration used by cosmovisor. -* [#21932](https://github.com/cosmos/cosmos-sdk/pull/21932) Add `cosmovisor show-upgrade-info` command to display the upgrade-info.json into stdout. ## Improvements diff --git a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go index f9c320084207..07da3e08894d 100644 --- a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go +++ b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go @@ -4,8 +4,9 @@ import ( "fmt" "os" - "cosmossdk.io/tools/cosmovisor" "github.com/spf13/cobra" + + "cosmossdk.io/tools/cosmovisor" ) func NewShowUpgradeInfoCmd() *cobra.Command { @@ -13,14 +14,14 @@ func NewShowUpgradeInfoCmd() *cobra.Command { Use: "show-upgrade-info", Short: "Show upgrade-info.json into stdout.", SilenceUsage: false, - Args: cobra.cobra.NoArgs, + Args: cobra.NoArgs, RunE: showUpgradeInfoCmd, } return showUpgradeInfo } -func showUpgradeInfoCmd(cmd *cobra.Command) error { +func showUpgradeInfoCmd(cmd *cobra.Command, args []string) error { configPath, err := cmd.Flags().GetString(cosmovisor.FlagCosmovisorConfig) if err != nil { return fmt.Errorf("failed to get config flag: %w", err)