Skip to content

Commit b03f0d2

Browse files
committed
[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 00d4182 commit b03f0d2

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
@@ -13,6 +13,7 @@ import (
1313
"github.com/fatih/color"
1414
"github.com/pkg/errors"
1515
"go.jetpack.io/devbox/internal/build"
16+
"go.jetpack.io/devbox/internal/ux"
1617
"golang.org/x/mod/semver"
1718

1819
"go.jetpack.io/devbox/internal/boxcli/usererr"
@@ -85,15 +86,16 @@ func selfUpdateLauncher(stdOut, stdErr io.Writer) error {
8586
return err
8687
}
8788

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

96-
// Invoke a devbox command to trigger an update of the devbox CLI binary.
97+
// Previously, we have already updated the binary. So, we call triggerUpdate
98+
// just to get the new version information.
9799
updated, err := triggerUpdate(stdErr)
98100
if err != nil {
99101
return errors.WithStack(err)
@@ -133,12 +135,14 @@ type updatedVersions struct {
133135
// devbox versions.
134136
func triggerUpdate(stdErr io.Writer) (*updatedVersions, error) {
135137

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

143147
buf := new(bytes.Buffer)
144148
cmd.Stdout = io.MultiWriter(stdErr, buf)

0 commit comments

Comments
 (0)