Skip to content

Commit

Permalink
No need to the update checker because we do autoupdate on state inv…
Browse files Browse the repository at this point in the history
…ocation.
  • Loading branch information
mitchell-as committed Jan 9, 2024
1 parent 50c4f72 commit 1ae9431
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cmd/state/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
34 changes: 0 additions & 34 deletions internal/runbits/checker/checker.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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))
}
3 changes: 0 additions & 3 deletions internal/runners/activate/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions internal/runners/checkout/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions internal/runners/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
2 changes: 0 additions & 2 deletions internal/runners/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions internal/runners/use/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion test/integration/update_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit 1ae9431

Please sign in to comment.