Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
1eaf5e5
feat(update): tell system package installs about new releases, sooner
pjcdawkins Nov 16, 2026
ce19caa
fix(update): only suggest a package manager that uses the repository
pjcdawkins Nov 16, 2026
2bb9bb8
fix(update): ignore disabled package repository entries
pjcdawkins Nov 16, 2026
9442688
fix(update): recognize more ways to disable a package repository
pjcdawkins Nov 16, 2026
2c61a0a
fix(update): recognize apt's "without" as disabling a repository
pjcdawkins Nov 16, 2026
5e61f93
fix(update): honor DNF 5 repository overrides
pjcdawkins Nov 16, 2026
7580239
fix(update): mask DNF 5 override files of the same name
pjcdawkins Nov 16, 2026
71010e4
refactor(update): move update message and repository code to their ow…
pjcdawkins Nov 16, 2026
48c064f
test(update): cover the package ownership query
pjcdawkins Nov 17, 2026
7cb0a77
Merge branch 'main' into claude/cli-update-notification-frequency-6d413d
pjcdawkins Nov 18, 2026
c7042c0
docs(update): correct the StartUpdateCheck comment
pjcdawkins Nov 18, 2026
a2d5d09
Merge branch 'main' into claude/cli-update-notification-frequency-6d413d
pjcdawkins Nov 19, 2026
a942592
feat(update): ask the package manager whether a repository provides t…
pjcdawkins Nov 19, 2026
5064660
fix(update): require the package to be installed for apt and apk
pjcdawkins Nov 19, 2026
cc06b6d
docs(update): describe the dnf and yum repository check accurately
pjcdawkins Nov 19, 2026
3b2876f
fix(update): detect the install method during the background check
pjcdawkins Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ nfpms:
- src: completion/zsh/_platform
dst: /usr/local/share/zsh/site-functions/_platform
# Marks the install as managed by a system package manager, so the CLI
# suppresses its update message. See internal/install.go. The dst must stay
# suggests its upgrade command. See internal/install.go. The dst must stay
# at <prefix>/share/<slug>/install-source, where <prefix> is the parent of
# the binary's dir (default bindir /usr/bin -> prefix /usr); changing the
# nfpm bindir would silently break suppression.
# nfpm bindir would silently break detection.
- src: packaging/install-source
dst: /usr/share/platformsh-cli/install-source
file_info: { mode: 0644 }
Expand Down Expand Up @@ -320,10 +320,10 @@ nfpms:
- src: completion/zsh/_upsun
dst: /usr/local/share/zsh/site-functions/_upsun
# Marks the install as managed by a system package manager, so the CLI
# suppresses its update message. See internal/install.go. The dst must stay
# suggests its upgrade command. See internal/install.go. The dst must stay
# at <prefix>/share/<slug>/install-source, where <prefix> is the parent of
# the binary's dir (default bindir /usr/bin -> prefix /usr); changing the
# nfpm bindir would silently break suppression.
# nfpm bindir would silently break detection.
- src: packaging/install-source
dst: /usr/share/upsun/install-source
file_info: { mode: 0644 }
Expand Down
10 changes: 5 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ PHP version is still injected via ldflags:

### Update Checks

The CLI checks for updates from GitHub releases (when Wrapper.GitHubRepo is set in config). The network check runs in a background goroutine and caches the latest known version in `state.json`; the notice is shown before the command on a later run (see `internal/update.go`). When a check is running, the CLI waits up to 1 second for it before exiting.
The CLI checks for updates from GitHub releases (when Wrapper.GitHubRepo is set in config). The network check runs in a background goroutine and caches the latest known version in `state.json` (see `internal/update.go`). The notice is printed by `commands/update_message.go`. When a check is running, the CLI waits up to 1 second for it before exiting: if it found a new release, the notice is shown then (the check also detects the install method, so that this wait is the only delay). Otherwise the notice is shown before the command on a later run.

Install-method detection (`internal/install.go`) tailors or suppresses the notice:
- System package managers (apt, yum/dnf, apk) are detected via a marker file installed by the nfpm packages (`packaging/install-source` → `/usr/share/<slug>/install-source`). Before printing a notice, older package installs without the marker are also detected by querying dpkg/rpm/apk. The notice is suppressed because the OS handles updates.
- Homebrew, Scoop, npm, winget, and the bash installer get a tailored upgrade command, built from config fields (`Wrapper.HomebrewTap`, `Wrapper.NpmPackage`, `Wrapper.WingetPackage`, `Wrapper.InstallerURL`, `Application.Executable`).
Install-method detection (`internal/install.go`, and `internal/package_repo.go` for package repositories) tailors the notice:
- System packages are detected via a marker file installed by the nfpm packages (`packaging/install-source` → `/usr/share/<slug>/install-source`), or in a standard bin directory without one. Before printing a notice, the package manager (apt, dnf or yum, apk) is found by asking dpkg, rpm and apk which owns the executable. The upgrade command uses `Wrapper.PackageName`, with `sudo` (or `doas`) unless running as root. If the package manager does not report that the package is installed and comes from an enabled repository (for apt and apk, `apt-cache policy` or `apk --no-network policy` lists a repository; for dnf and yum, dnf's `from_repo` or yum's `From repo` is still enabled; e.g. not for a downloaded package installed with `dpkg -i`), the method is `package`, which gets the generic link. The package repositories are updated by the release workflow straight after the GitHub release.
- Homebrew, Scoop, npm, winget, and the bash installer also get a tailored upgrade command, built from config fields (`Wrapper.HomebrewTap`, `Wrapper.NpmPackage`, `Wrapper.WingetPackage`, `Wrapper.InstallerURL`, `Application.Executable`).
- winget installs are detected by their path (`\WinGet\Packages\`). A release reaches winget only after Microsoft merges its manifest PR in `microsoft/winget-pkgs`, so for winget installs the background check reads the newest version there (from the GitHub API) instead of the latest GitHub release.
- The notice is throttled to once a week (`LastNotified` in state) and only shown in an interactive terminal.
- The notice is only shown in an interactive terminal, and at most once a week for the same version (`LastNotified` and `NotifiedVersion` in state): a newer version is announced without waiting.
- `<PREFIX>INSTALL_METHOD` forces the method; `<PREFIX>UPDATES_CHECK=0` disables checks entirely.
- With `CLI_CONFIG_FILE` (e.g. a `config:install` shim), the `wrapper.*` keys and the application name, executable and slug come from the embedded config (`Config.Embedded()`), as the binary is the same. The notice is only shown if there is an upgrade command for the install method, as the binary may be a private copy.

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ Regular system package updates (e.g. `sudo apt update && sudo apt upgrade`) also
### Update notifications

When a newer release is available, the CLI prints the upgrade command for your
install method, at most once a week, in an interactive terminal. It prints
nothing for system packages, as the OS updates them.
install method, in an interactive terminal. A release is announced once, then
at most once a week.

- `UPSUN_CLI_UPDATES_CHECK=0` disables update checks.
- `UPSUN_CLI_INSTALL_METHOD=<method>` overrides the detected install method:
`homebrew`, `scoop`, `npm`, `winget`, `package`, or `script`.
`homebrew`, `scoop`, `npm`, `winget`, `apt`, `dnf`, `yum`, `apk`, `package`
(a system package, with an unknown package manager), or `script`.

## Configuration

Expand Down
115 changes: 10 additions & 105 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"slices"
"strings"
"syscall"
"time"

"github.com/fatih/color"
"github.com/spf13/cobra"
Expand All @@ -38,13 +37,13 @@ func Execute(cnf *config.Config) error {
err := cmd.ExecuteContext(ctx)
var ee *exitError
if errors.As(err, &ee) {
waitForUpdateCheck()
finishUpdateCheck()
os.Exit(ee.code)
}
if err != nil && !isQuiet() {
fmt.Fprintln(color.Error, "Error:", err)
}
waitForUpdateCheck()
finishUpdateCheck()
return err
}

Expand All @@ -53,17 +52,6 @@ func isQuiet() bool {
return viper.GetBool("quiet") && !viper.GetBool("debug") && !viper.GetBool("verbose")
}

// updateCheckWait is the maximum time to wait for a background update check before exiting.
const updateCheckWait = time.Second

// updateCheck is the background update check started by the root command, if any.
var updateCheck *internal.UpdateCheck

// waitForUpdateCheck gives a running update check a chance to save its result.
func waitForUpdateCheck() {
updateCheck.Wait(updateCheckWait)
}

func newRootCommand(cnf *config.Config) *cobra.Command {
versionCommand := newVersionCommand(cnf)
cmd := &cobra.Command{
Expand Down Expand Up @@ -96,26 +84,17 @@ func newRootCommand(cnf *config.Config) *cobra.Command {
if viper.GetBool("yes") {
viper.Set("no-interaction", true)
}
// The check runs in the background and caches its result for the
// next invocation. It is waited for briefly before exiting.
// The check runs in the background and caches its result. It is
// waited for briefly before exiting.
updateCheck = internal.StartUpdateCheck(cnf)
updateMessage = newUpdateNotifier(cnf, cmd.ErrOrStderr(), quiet)
if viper.GetBool("version") {
versionCommand.Run(cmd, []string{})
waitForUpdateCheck()
finishUpdateCheck()
os.Exit(0)
}
if cnf.Embedded().Wrapper.GitHubRepo != "" {
// Show any update found by a previous run, before the command's
// output. In quiet mode the notice would be discarded, so it is
// left for a later run.
if rel := internal.PendingNotification(cnf, config.Version); rel != nil && !quiet {
// Full detection can find package installs that lack the marker.
if method := internal.DetectInstallMethod(cnf); !method.AutoUpdating() {
printUpdateMessage(cmd.ErrOrStderr(), rel, cnf, method)
}
internal.MarkNotified(cnf)
}
}
// Show any update found by a previous run, before the command's output.
updateMessage.show(false)
if alt.ShouldUpdate(cnf) {
go func() {
if err := alt.Update(cmd.Context(), cnf, debugLogf); err != nil {
Expand Down Expand Up @@ -251,80 +230,6 @@ func checkShellConfigLeftovers(w io.Writer, cnf *config.Config) {
}
}

// printUpdateMessage describes the binary from its embedded config, as the
// binary and its upgrade command are the same with or without CLI_CONFIG_FILE.
// With CLI_CONFIG_FILE, it prints nothing if there is no upgrade command: the
// binary may be a private copy, which the generic instructions do not update.
func printUpdateMessage(w io.Writer, rel *internal.ReleaseInfo, cnf *config.Config, method internal.InstallMethod) {
if rel == nil {
return
}
bin := cnf.Embedded()
exe, _ := os.Executable()
upgradeCmd := upgradeCommandFor(bin, method, exe)
if upgradeCmd == "" && !cnf.IsEmbedded() {
return
}

fmt.Fprintf(w, "%s %s → %s\n",
color.YellowString(fmt.Sprintf("A new release of the %s is available:", bin.Application.Name)),
color.CyanString(config.Version),
color.CyanString(rel.Version),
)

if upgradeCmd != "" {
fmt.Fprintf(w, "To upgrade, run: %s\n", color.YellowString(upgradeCmd))
} else if bin.Wrapper.GitHubRepo != "" {
fmt.Fprintf(
w,
"To upgrade, follow the instructions at: https://github.com/%s#upgrade\n",
bin.Wrapper.GitHubRepo,
)
}

fmt.Fprintf(w, "%s\n\n", color.YellowString(rel.URL))
}

// upgradeCommandFor returns the upgrade command for the install method, or an
// empty string when there is no tailored command (the caller then falls back to
// a generic link).
func upgradeCommandFor(cnf *config.Config, method internal.InstallMethod, exe string) string {
switch method {
case internal.InstallHomebrew:
if cnf.Wrapper.HomebrewTap != "" {
return "brew update && brew upgrade " + cnf.Wrapper.HomebrewTap
}
case internal.InstallScoop:
return "scoop update " + cnf.Application.Executable
case internal.InstallNpm:
if cnf.Wrapper.NpmPackage != "" {
return "npm install -g " + cnf.Wrapper.NpmPackage + "@latest"
}
case internal.InstallWinget:
if cnf.Wrapper.WingetPackage != "" {
return "winget upgrade " + cnf.Wrapper.WingetPackage
}
case internal.InstallScript:
// The raw method replaces the binary in INSTALL_DIR; without it, the
// installer may choose a package manager instead (e.g. apt on Debian).
if cnf.Wrapper.InstallerURL != "" && exe != "" {
return "curl -fsSL " + cnf.Wrapper.InstallerURL +
" | INSTALL_METHOD=raw INSTALL_DIR=" + shellQuote(filepath.Dir(exe)) + " sh"
}
}
return ""
}

var shellSafe = regexp.MustCompile(`^[A-Za-z0-9_./-]+$`)

// shellQuote quotes s for a POSIX shell, if needed.
func shellQuote(s string) string {
if shellSafe.MatchString(s) {
return s
}
return "'" + strings.ReplaceAll(s, "'", `'\''`) + "'"
}

func debugLogf(format string, v ...any) {
if !viper.GetBool("debug") {
return
Expand All @@ -343,13 +248,13 @@ func exitWithError(err error) {
exitCode = 128 + int(ws.Signal())
}
debugLogf("%s", err)
waitForUpdateCheck()
finishUpdateCheck()
os.Exit(exitCode)
}
if !isQuiet() {
fmt.Fprintln(color.Error, color.RedString(err.Error()))
}
waitForUpdateCheck()
finishUpdateCheck()
os.Exit(1)
}

Expand Down
97 changes: 0 additions & 97 deletions commands/root_test.go

This file was deleted.

Loading
Loading