From 6df0418e5a2fe8a7b5375bbc76acc8086907a213 Mon Sep 17 00:00:00 2001 From: Lukasz <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 27 May 2024 16:02:43 +0200 Subject: [PATCH] Add `get-latest-ethereum-client-version` command to CTF Utils CMD Tool (#964) * Add `get-latest-ethereum-client-version` command to CTF Utils CMD Tool * fix --- .../internal/get_latest_version_commands.go | 30 +++++++++++++++++ utils/cmd/main.go | 33 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 utils/cmd/internal/get_latest_version_commands.go create mode 100644 utils/cmd/main.go diff --git a/utils/cmd/internal/get_latest_version_commands.go b/utils/cmd/internal/get_latest_version_commands.go new file mode 100644 index 000000000..25a958f6b --- /dev/null +++ b/utils/cmd/internal/get_latest_version_commands.go @@ -0,0 +1,30 @@ +package internal + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + + "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" +) + +var GetLatestEthereumClientVersionCmd = &cobra.Command{ + Use: "get-latest-ethereum-client-version", + Short: "Get the latest Ethereum client release version from Github", + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) != 1 { + return fmt.Errorf("please provide the repository in the format 'org/repo:tag'") + } + + repo := args[0] + + latest, err := test_env.FetchLatestEthereumClientDockerImageVersionIfNeed(repo) + if err != nil { + return fmt.Errorf("error fetching release information: %v", err) + } + + fmt.Println(strings.Split(latest, ":")[1]) + return nil + }, +} diff --git a/utils/cmd/main.go b/utils/cmd/main.go new file mode 100644 index 000000000..aa7ea066b --- /dev/null +++ b/utils/cmd/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "log" + "os" + "time" + + "github.com/spf13/cobra" + "golang.org/x/net/context" + + "github.com/smartcontractkit/chainlink-testing-framework/utils/cmd/internal" +) + +var rootCmd = &cobra.Command{ + Use: "ctf-utils", + Short: "CTF Utils Tool", +} + +func init() { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute*1) + defer cancel() + + internal.GetLatestEthereumClientVersionCmd.SetContext(ctx) + + rootCmd.AddCommand(internal.GetLatestEthereumClientVersionCmd) +} + +func main() { + if err := rootCmd.Execute(); err != nil { + log.Println(err) + os.Exit(1) + } +}