MCPcopy
hub / github.com/keploy/keploy / Update

Method Update

pkg/service/tools/tools.go:64–132  ·  view source on GitHub ↗

Update initiates the tools process for the Keploy binary file.

(ctx context.Context)

Source from the content-addressed store, hash-verified

62
63// Update initiates the tools process for the Keploy binary file.
64func (t *Tools) Update(ctx context.Context) error {
65 currentVersion := "v" + utils.Version
66 isKeployInDocker := len(os.Getenv("KEPLOY_INDOCKER")) > 0
67 if isKeployInDocker {
68 fmt.Println("As you are using docker version of keploy, please pull the latest Docker image of keploy to update keploy")
69 return nil
70 }
71 if strings.HasSuffix(currentVersion, "-dev") {
72 fmt.Println("you are using a development version of Keploy. Skipping update")
73 return nil
74 }
75
76 releaseInfo, err := utils.GetLatestGitHubRelease(ctx, t.logger)
77 if err != nil {
78 if errors.Is(err, ErrGitHubAPIUnresponsive) {
79 return errors.New("gitHub API is unresponsive. Update process cannot continue")
80 }
81 return fmt.Errorf("failed to fetch latest GitHub release version: %v", err)
82 }
83
84 latestVersion := releaseInfo.TagName
85 changelog := releaseInfo.Body
86
87 if currentVersion == latestVersion {
88 fmt.Println("✅You are already on the latest version of Keploy: " + latestVersion)
89 return nil
90 }
91
92 t.logger.Info("Updating to Version: " + latestVersion)
93 downloadURL := ""
94
95 if runtime.GOOS == "linux" {
96 if runtime.GOARCH == "amd64" {
97 downloadURL = "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz"
98 } else {
99 downloadURL = "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz"
100 }
101 }
102
103 if runtime.GOOS == "darwin" {
104 downloadURL = "https://github.com/keploy/keploy/releases/latest/download/keploy_darwin_all.tar.gz"
105 }
106
107 err = t.downloadAndUpdate(ctx, t.logger, downloadURL)
108 if err != nil {
109 return err
110 }
111
112 t.logger.Info("Update Successful!")
113
114 changelog = "\n" + string(changelog)
115 var renderer *glamour.TermRenderer
116
117 var termRendererOpts []glamour.TermRendererOption
118 termRendererOpts = append(termRendererOpts, glamour.WithEnvironmentConfig(), glamour.WithWordWrap(0))
119
120 renderer, err = glamour.NewTermRenderer(termRendererOpts...)
121 if err != nil {

Callers

nothing calls this directly

Calls 5

downloadAndUpdateMethod · 0.95
GetLatestGitHubReleaseFunction · 0.92
LogErrorFunction · 0.92
NewMethod · 0.65
RenderMethod · 0.45

Tested by

no test coverage detected