From 1ae9431642cefee3e2b8523681ac73fa71a28d53 Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 9 Jan 2024 16:33:14 -0500 Subject: [PATCH] No need to the update checker because we do autoupdate on `state` invocation. --- cmd/state/autoupdate.go | 2 +- internal/runbits/checker/checker.go | 34 --------------------------- internal/runners/activate/activate.go | 3 --- internal/runners/checkout/checkout.go | 3 --- internal/runners/run/run.go | 2 -- internal/runners/state/state.go | 2 -- internal/runners/use/use.go | 3 --- test/integration/update_int_test.go | 7 +++++- 8 files changed, 7 insertions(+), 49 deletions(-) diff --git a/cmd/state/autoupdate.go b/cmd/state/autoupdate.go index c0a8a328d0..1f88d6b64b 100644 --- a/cmd/state/autoupdate.go +++ b/cmd/state/autoupdate.go @@ -60,7 +60,7 @@ func autoUpdate(svc *model.SvcModel, args []string, cfg *config.Instance, an ana if !isEnabled(cfg) { logging.Debug("Not performing autoupdates because user turned off autoupdates.") an.EventWithLabel(anaConst.CatUpdates, anaConst.ActShouldUpdate, anaConst.UpdateLabelDisabledConfig) - out.Notice(output.Title(locale.Tl("update_available_header", "Auto Update"))) + out.Notice(output.Title(locale.T("update_available_header"))) out.Notice(locale.Tr("update_available", constants.Version, avUpdate.Version)) return false, nil } diff --git a/internal/runbits/checker/checker.go b/internal/runbits/checker/checker.go index 193180112a..3e2314933e 100644 --- a/internal/runbits/checker/checker.go +++ b/internal/runbits/checker/checker.go @@ -1,22 +1,14 @@ package checker import ( - "context" "errors" - "net" "strconv" - "time" - "github.com/ActiveState/cli/internal/analytics" - "github.com/ActiveState/cli/internal/constants" "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" - "github.com/ActiveState/cli/internal/multilog" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/internal/profile" "github.com/ActiveState/cli/internal/runbits/commitmediator" - "github.com/ActiveState/cli/internal/updater" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" ) @@ -63,29 +55,3 @@ func CommitsBehind(p *project.Project) (int, error) { return model.CommitsBehind(*latestCommitID, commitID) } - -func RunUpdateNotifier(an analytics.Dispatcher, svc *model.SvcModel, out output.Outputer) { - defer profile.Measure("RunUpdateNotifier", time.Now()) - - ctx, cancel := context.WithTimeout(context.Background(), model.SvcTimeoutMinimal) - defer cancel() - - upd, err := svc.CheckUpdate(ctx, constants.ChannelName, "") - if err != nil { - var timeoutErr net.Error - if errors.As(err, &timeoutErr) && timeoutErr.Timeout() { - logging.Debug("CheckUpdate timed out") - return - } - multilog.Error("Could not check for update when running update notifier, error: %v", errs.JoinMessage(err)) - return - } - - update := updater.NewUpdateInstaller(an, updater.NewAvailableUpdateFromGraph(upd)) - if !update.ShouldInstall() { - return - } - - out.Notice(output.Title(locale.Tr("update_available_header"))) - out.Notice(locale.Tr("update_available", constants.Version, update.AvailableUpdate.Version)) -} diff --git a/internal/runners/activate/activate.go b/internal/runners/activate/activate.go index a5de8efbb2..b39aea5306 100644 --- a/internal/runners/activate/activate.go +++ b/internal/runners/activate/activate.go @@ -22,7 +22,6 @@ import ( "github.com/ActiveState/cli/internal/process" "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits/activation" - "github.com/ActiveState/cli/internal/runbits/checker" "github.com/ActiveState/cli/internal/runbits/checkout" "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/runbits/findproject" @@ -83,8 +82,6 @@ func NewActivate(prime primeable) *Activate { func (r *Activate) Run(params *ActivateParams) (rerr error) { logging.Debug("Activate %v, %v", params.Namespace, params.PreferredPath) - checker.RunUpdateNotifier(r.analytics, r.svcModel, r.out) - r.out.Notice(output.Title(locale.T("info_activating_state"))) proj, err := findproject.FromInputByPriority(params.PreferredPath, params.Namespace, r.config, r.prompt) diff --git a/internal/runners/checkout/checkout.go b/internal/runners/checkout/checkout.go index 7d9f8c3514..b3c05f222f 100644 --- a/internal/runners/checkout/checkout.go +++ b/internal/runners/checkout/checkout.go @@ -16,7 +16,6 @@ import ( "github.com/ActiveState/cli/internal/osutils" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" - "github.com/ActiveState/cli/internal/runbits/checker" "github.com/ActiveState/cli/internal/runbits/checkout" "github.com/ActiveState/cli/internal/runbits/git" "github.com/ActiveState/cli/internal/runbits/runtime" @@ -74,8 +73,6 @@ func NewCheckout(prime primeable) *Checkout { func (u *Checkout) Run(params *Params) (rerr error) { logging.Debug("Checkout %v", params.Namespace) - checker.RunUpdateNotifier(u.analytics, u.svcModel, u.out) - logging.Debug("Checking out %s to %s", params.Namespace.String(), params.PreferredPath) var err error projectDir, err := u.checkout.Run(params.Namespace, params.Branch, params.RuntimePath, params.PreferredPath, params.NoClone) diff --git a/internal/runners/run/run.go b/internal/runners/run/run.go index a6608839a7..8169ad2844 100644 --- a/internal/runners/run/run.go +++ b/internal/runners/run/run.go @@ -60,8 +60,6 @@ func (r *Run) Run(name string, args []string) error { return locale.NewInputError("err_no_project") } - checker.RunUpdateNotifier(r.analytics, r.svcModel, r.out) - r.out.Notice(locale.Tr("operating_message", r.proj.NamespaceString(), r.proj.Dir())) if name == "" { diff --git a/internal/runners/state/state.go b/internal/runners/state/state.go index 08e2e73f89..9dfe612d62 100644 --- a/internal/runners/state/state.go +++ b/internal/runners/state/state.go @@ -11,7 +11,6 @@ import ( "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/profile" - "github.com/ActiveState/cli/internal/runbits/checker" "github.com/ActiveState/cli/pkg/platform/model" ) @@ -54,7 +53,6 @@ func (s *State) Run(usageFunc func() error) error { defer profile.Measure("runners:state:run", time.Now()) if s.opts.Version { - checker.RunUpdateNotifier(s.an, s.svcMdl, s.out) vd := installation.VersionData{ "CLI", constants.LibraryLicense, diff --git a/internal/runners/use/use.go b/internal/runners/use/use.go index f18d1c74aa..b5e33614b5 100644 --- a/internal/runners/use/use.go +++ b/internal/runners/use/use.go @@ -12,7 +12,6 @@ import ( "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/prompt" - "github.com/ActiveState/cli/internal/runbits/checker" "github.com/ActiveState/cli/internal/runbits/checkout" "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/runbits/findproject" @@ -67,8 +66,6 @@ func NewUse(prime primeable) *Use { func (u *Use) Run(params *Params) error { logging.Debug("Use %v", params.Namespace) - checker.RunUpdateNotifier(u.analytics, u.svcModel, u.out) - proj, err := findproject.FromNamespaceLocal(params.Namespace, u.config, u.prompt) if err != nil { if !findproject.IsLocalProjectDoesNotExistError(err) { diff --git a/test/integration/update_int_test.go b/test/integration/update_int_test.go index 3ba18ead5c..c84e879734 100644 --- a/test/integration/update_int_test.go +++ b/test/integration/update_int_test.go @@ -57,6 +57,7 @@ func (suite *UpdateIntegrationTestSuite) env(disableUpdates, forceUpdate bool) [ } if forceUpdate { + env = append(env, constants.TestAutoUpdateEnvVarName+"=true") env = append(env, constants.ForceUpdateEnvVarName+"=true") } @@ -103,6 +104,11 @@ func (suite *UpdateIntegrationTestSuite) TestUpdateAvailable() { ts := e2e.New(suite.T(), false) defer ts.Close() + cfg, err := config.NewCustom(ts.Dirs.Config, singlethread.New(), true) + suite.Require().NoError(err) + defer cfg.Close() + cfg.Set(constants.AutoUpdateConfigKey, "false") + search, found := "Update Available", false for i := 0; i < 4; i++ { if i > 0 { @@ -296,7 +302,6 @@ func (suite *UpdateIntegrationTestSuite) testAutoUpdate(ts *e2e.Session, baseDir e2e.OptArgs("--version"), e2e.OptAppendEnv(suite.env(false, true)...), e2e.OptAppendEnv(fmt.Sprintf("HOME=%s", fakeHome)), - e2e.OptAppendEnv(constants.TestAutoUpdateEnvVarName + "=true"), } if opts != nil { spawnOpts = append(spawnOpts, opts...)