-
Notifications
You must be signed in to change notification settings - Fork 9
feat: notify user their version of dbc is out of date #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zeroshade
wants to merge
21
commits into
main
Choose a base branch
from
dbc-version-out-of-date
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7b072ea
feat: notify user their version of dbc is out of date
zeroshade 2fa5633
Update cmd/dbc/main.go
zeroshade 5c767fa
add build tag
zeroshade b93b954
updates from feedback
zeroshade 50273ff
Add docs for update notifications
amoeba 152bee8
Update installation.md
amoeba a12e7a0
Set up notify/no-notify in goreleaser
amoeba 4ec8bea
builds -> ids
amoeba a007b82
fix formatting, config path
zeroshade c367112
don't use build tags, use exe path
zeroshade 30f8604
trim trailing whitespace
zeroshade 54389ca
fix path
zeroshade d8f8a71
fix macos config path
zeroshade b04dd37
check the brew prefix for comparison
zeroshade 91b6219
Update cmd/dbc/latest.go
zeroshade 490f173
Update cmd/dbc/latest.go
zeroshade ac29758
updates from comments
zeroshade 6142e98
put comment back
zeroshade 7bb90e8
fix trailing whitespace
zeroshade 88159f8
add macos check
zeroshade d37a094
fix logic
zeroshade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // Copyright 2026 Columnar Technologies Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "charm.land/lipgloss/v2" | ||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/cli/safeexec" | ||
| "github.com/columnar-tech/dbc" | ||
| "github.com/columnar-tech/dbc/internal" | ||
| ) | ||
|
|
||
| func isUnderHomebrew(bin string) bool { | ||
| brewExe, err := safeexec.LookPath("brew") | ||
| if err != nil { | ||
| return false | ||
| } | ||
|
|
||
| brewPrefixBytes, err := exec.Command(brewExe, "--prefix").Output() | ||
| if err != nil { | ||
| return false | ||
| } | ||
|
|
||
| brewBinPrefix := filepath.Join(strings.TrimSpace( | ||
| string(brewPrefixBytes)), "bin") + string(filepath.Separator) | ||
| return strings.HasPrefix(bin, brewBinPrefix) | ||
| } | ||
|
|
||
| func isPkgMgrInstall() bool { | ||
| exe, err := os.Executable() | ||
| if err != nil { | ||
| return false | ||
| } | ||
|
|
||
| if isUnderHomebrew(exe) { | ||
| return true | ||
| } | ||
|
|
||
| exe, err = filepath.EvalSymlinks(exe) | ||
| if err != nil { | ||
| return false | ||
| } | ||
|
|
||
| if isManaged(exe) { | ||
| return true | ||
| } | ||
|
|
||
| if strings.Contains(exe, "conda") || strings.Contains(exe, "venv") || strings.Contains(exe, "miniforge") { | ||
| // likely a conda or virtual environment install | ||
| return true | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| func writeLastUpdateCheck(configDir string) { | ||
| // file doesn't exist, create it with current timestamp and skip update check | ||
| _ = os.MkdirAll(configDir, 0o700) | ||
| _ = os.WriteFile(filepath.Join(configDir, ".last-update-check"), []byte(time.Now().Format(time.DateOnly)), 0o600) | ||
| } | ||
|
|
||
| func notifyLatest() { | ||
| configDir, err := internal.GetUserConfigPath() | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| // skip notifying if $dbc_config_home/.no-update exists | ||
| _, err = os.Stat(filepath.Join(configDir, ".no-update")) | ||
| if err == nil { | ||
| return // file exists, skip update check | ||
| } | ||
|
|
||
| lastUpdate, err := os.ReadFile(filepath.Join(configDir, ".last-update-check")) | ||
| if errors.Is(err, os.ErrNotExist) { | ||
| writeLastUpdateCheck(configDir) | ||
| } else if err == nil { | ||
| lastCheckTime, err := time.Parse(time.DateOnly, string(lastUpdate)) | ||
| if err != nil { | ||
| // if the file is corrupted, reset it | ||
| _ = os.WriteFile(filepath.Join(configDir, ".last-update-check"), []byte(time.Now().Format(time.DateOnly)), 0o600) | ||
| } else if time.Since(lastCheckTime) > 24*time.Hour { | ||
| writeLastUpdateCheck(configDir) | ||
| } else { | ||
| return // last check was within 24 hours, skip update check | ||
| } | ||
| } | ||
|
|
||
| if isPkgMgrInstall() { | ||
| // skip notifying if installed via package manager, | ||
| // since they likely have their own update mechanism | ||
| return | ||
| } | ||
|
|
||
| latestVer, err := dbc.GetLatestDbcVersion() | ||
| if dbc.Version != "(devel)" && err == nil { | ||
| if semver.MustParse(dbc.Version).LessThan(latestVer) { | ||
| lipgloss.Fprintf(os.Stderr, descStyle.Render("Update available: A new version of dbc is available. You're running v%s and v%s is available. Please upgrade.\nChangelog: %s. Docs: %s"), | ||
| dbc.Version, latestVer, "https://github.com/columnar-tech/dbc/releases/tag/v"+latestVer.String(), "https://docs.columnar.tech/dbc/getting_started/installation/") | ||
| lipgloss.Fprintln(os.Stderr) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright 2026 Columnar Technologies Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import "path/filepath" | ||
|
|
||
| func isManaged(exe string) bool { | ||
| if filepath.Dir(exe) == "/usr/local/bin" { | ||
| // system-wide pip install | ||
| return true | ||
| } | ||
|
|
||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright 2026 Columnar Technologies Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "os/exec" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| func isManaged(exe string) bool { | ||
| // check if we're a deb install | ||
| dpkgExe, err := exec.LookPath("dpkg") | ||
| if err == nil { | ||
| if err = exec.Command(dpkgExe, "-S", exe).Run(); err == nil { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| // check if we're an rpm install | ||
| rpmExe, err := exec.LookPath("rpm") | ||
| if err == nil { | ||
| if err = exec.Command(rpmExe, "-qf", exe).Run(); err == nil { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| if filepath.Dir(exe) == "/usr/local/bin" { | ||
| // pip installs here on linux | ||
| return true | ||
| } | ||
|
|
||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright 2026 Columnar Technologies Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "golang.org/x/sys/windows/registry" | ||
| ) | ||
|
|
||
| func isManaged(exe string) bool { | ||
| const packedUpgradeCode = `F0742CB3EE450F7479C37A9886B49FE5` | ||
| const registryPath = `SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes\` + packedUpgradeCode | ||
|
|
||
| k, err := registry.OpenKey(registry.LOCAL_MACHINE, registryPath, registry.QUERY_VALUE) | ||
| if err == nil { | ||
| // If we can open the key, check if our executable is listed as an installed product under this upgrade code | ||
| // this means dbc is installed via MSI. | ||
| defer k.Close() | ||
|
|
||
| // so check if we're running from the location where dbc.msi installs to | ||
| return strings.Contains(exe, `AppData\Roaming\Columnar\dbc`) | ||
| } | ||
|
|
||
| if strings.HasSuffix(filepath.Dir(exe), "\\Scripts") { | ||
| // likely a pip install | ||
| return true | ||
| } | ||
|
|
||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.