Skip to content

Commit 253aacf

Browse files
authored
[version update] use LAUNCHER_PATH in triggerUpdate function (#975)
## Summary For trigger update to work, we need to invoke the "launcher" and not the "devbox CLI binary". To do so, we can use the `LAUNCHER_PATH` env-var. And fallback to "devbox" if in PATH, or finally as a fail-safe to the prior `os.Executable`. ## How was it tested? :eyes: carefully pair-programmed with @mikeland86. We'll test after building the pre-release in `0.4.9-dev`.
1 parent 7ba3661 commit 253aacf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

internal/vercheck/vercheck.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/fatih/color"
1717
"github.com/pkg/errors"
1818
"go.jetpack.io/devbox/internal/build"
19+
"go.jetpack.io/devbox/internal/ux"
1920
"golang.org/x/mod/semver"
2021

2122
"go.jetpack.io/devbox/internal/boxcli/usererr"
@@ -88,15 +89,16 @@ func selfUpdateLauncher(stdOut, stdErr io.Writer) error {
8889
return err
8990
}
9091

91-
// Fetch the new launcher.
92+
// Fetch the new launcher. And installs the new devbox CLI binary.
9293
cmd := exec.Command("sh", "-c", installScript)
9394
cmd.Stdout = stdOut
9495
cmd.Stderr = stdErr
9596
if err := cmd.Run(); err != nil {
9697
return errors.WithStack(err)
9798
}
9899

99-
// Invoke a devbox command to trigger an update of the devbox CLI binary.
100+
// Previously, we have already updated the binary. So, we call triggerUpdate
101+
// just to get the new version information.
100102
updated, err := triggerUpdate(stdErr)
101103
if err != nil {
102104
return errors.WithStack(err)
@@ -136,12 +138,14 @@ type updatedVersions struct {
136138
// devbox versions.
137139
func triggerUpdate(stdErr io.Writer) (*updatedVersions, error) {
138140

139-
exe, err := os.Executable()
140-
if err != nil {
141-
return nil, errors.WithStack(err)
141+
exePath := os.Getenv("LAUNCHER_PATH")
142+
if exePath == "" {
143+
ux.Fwarning(stdErr, "expected LAUNCHER_PATH to be set. Defaulting to \"devbox\".")
144+
exePath = "devbox"
142145
}
146+
143147
// TODO savil. Add a --json flag to devbox version and parse the output as JSON
144-
cmd := exec.Command(exe, "version", "-v")
148+
cmd := exec.Command(exePath, "version", "-v")
145149

146150
buf := new(bytes.Buffer)
147151
cmd.Stdout = io.MultiWriter(stdErr, buf)

0 commit comments

Comments
 (0)