Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 23 additions & 21 deletions internal/updater/self_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ type Release struct {
} `json:"assets"`
}

// getBinaryName returns the expected binary name for the given OS and architecture
func getBinaryName(goos, goarch string) string {
target := fmt.Sprintf("journal-%s-%s", goos, goarch)
if goos == "windows" {
target += ".exe"
}
return target
}

// findAssetURL searches for a compatible binary in the release assets
func findAssetURL(release *Release, targetName, goos, goarch string) (string, error) {
for _, asset := range release.Assets {
if asset.Name == targetName {
return asset.BrowserDownloadURL, nil
}
}
return "", fmt.Errorf("no compatible binary found for %s/%s (looking for %s)", goos, goarch, targetName)
}

// Update handles the self-update process
func Update() error {
fmt.Println("🔍 Checking latest version...")
Expand Down Expand Up @@ -55,28 +74,11 @@ func Update() error {
}

// 2. Determine target binary name
// Naming convention assumed: journal-darwin-arm64, journal-linux-amd64, etc.
target := fmt.Sprintf(
"journal-%s-%s",
runtime.GOOS,
runtime.GOARCH,
)

// Windows binaries usually have .exe extension
if runtime.GOOS == "windows" {
target += ".exe"
}

var url string
for _, asset := range release.Assets {
if asset.Name == target {
url = asset.BrowserDownloadURL
break
}
}
target := getBinaryName(runtime.GOOS, runtime.GOARCH)

if url == "" {
return fmt.Errorf("no compatible binary found for %s/%s (looking for %s)", runtime.GOOS, runtime.GOARCH, target)
url, err := findAssetURL(&release, target, runtime.GOOS, runtime.GOARCH)
if err != nil {
return err
}

fmt.Printf("⬇️ Downloading %s (%s)...\n", release.TagName, target)
Expand Down
Loading