Skip to content

Commit 7be5846

Browse files
authored
Merge pull request #14 from nathfavour/master
🚀 Finalize Robust Versioning & Installer
2 parents 03c1aab + 3b4370f commit 7be5846

5 files changed

Lines changed: 65 additions & 9 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ jobs:
6363
fi
6464
6565
VERSION=${{ github.ref_name == 'release' && 'latest' || github.ref_name }}
66-
echo "Building for $GOOS/$GOARCH (version $VERSION)..."
67-
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w -X main.Version=$VERSION" -trimpath -o "dist/$output_name" ./cmd/vibeaura
66+
COMMIT=${{ github.sha }}
67+
echo "Building for $GOOS/$GOARCH (version $VERSION, commit $COMMIT)..."
68+
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w -X main.Version=$VERSION -X main.Commit=$COMMIT" -trimpath -o "dist/$output_name" ./cmd/vibeaura
6869
done
6970
7071
- name: Create Release

cmd/vibeaura/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
var (
1313
Version = "dev"
14+
Commit = "none"
1415
)
1516

1617
var rootCmd = &cobra.Command{

cmd/vibeaura/update.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
const repo = "nathfavour/vibeauracle"
1717

1818
type releaseInfo struct {
19-
TagName string `json:"tag_name"`
20-
Assets []struct {
19+
TagName string `json:"tag_name"`
20+
TargetCommitish string `json:"target_commitish"`
21+
Assets []struct {
2122
Name string `json:"name"`
2223
BrowserDownloadURL string `json:"browser_download_url"`
2324
} `json:"assets"`
@@ -43,15 +44,40 @@ func getLatestRelease() (*releaseInfo, error) {
4344
return &releases[0], nil
4445
}
4546

47+
func isUpdateAvailable(latest *releaseInfo) bool {
48+
if Version == "dev" {
49+
return true // Always allow update from dev
50+
}
51+
52+
// If tags match, check the commit SHA
53+
if latest.TagName == Version {
54+
// If both are 'latest', compare the SHAs
55+
if Version == "latest" {
56+
return latest.TargetCommitish != Commit
57+
}
58+
return false
59+
}
60+
61+
return true
62+
}
63+
4664
// checkUpdateSilent checks for updates and prints a message if one is available
4765
func checkUpdateSilent() {
4866
latest, err := getLatestRelease()
4967
if err != nil {
5068
return // Fail silently for background checks
5169
}
5270

53-
if latest.TagName != Version {
54-
fmt.Printf("\n✨ A new version of vibeaura is available: %s (current: %s)\n", latest.TagName, Version)
71+
if isUpdateAvailable(latest) {
72+
fmt.Printf("\n✨ A new version of vibeaura is available: %s", latest.TagName)
73+
if Version == "latest" && latest.TargetCommitish != "" {
74+
fmt.Printf(" (%s)", latest.TargetCommitish[:7])
75+
}
76+
fmt.Printf(" (current: %s", Version)
77+
if Commit != "none" {
78+
fmt.Printf("-%s", Commit[:7])
79+
}
80+
fmt.Println(")")
5581
fmt.Println("👉 Run 'vibeaura update' to install it instantly.\n")
5682
}
5783
}
@@ -60,20 +86,24 @@ var updateCmd = &cobra.Command{
6086
Use: "update",
6187
Short: "Update vibeaura to the latest version",
6288
RunE: func(cmd *cobra.Command, args []string) error {
63-
fmt.Printf("Current version: %s\n", Version)
89+
fmt.Printf("Current version: %s (commit: %s)\n", Version, Commit)
6490
fmt.Println("Checking for updates...")
6591

6692
latest, err := getLatestRelease()
6793
if err != nil {
6894
return fmt.Errorf("checking for updates: %w", err)
6995
}
7096

71-
if latest.TagName == Version && Version != "dev" {
97+
if !isUpdateAvailable(latest) {
7298
fmt.Println("vibeaura is already up to date!")
7399
return nil
74100
}
75101

76-
fmt.Printf("New version available: %s\n", latest.TagName)
102+
fmt.Printf("New version available: %s", latest.TagName)
103+
if latest.TagName == "latest" {
104+
fmt.Printf(" (commit: %s)", latest.TargetCommitish)
105+
}
106+
fmt.Println()
77107

78108
// Determine target asset name
79109
goos := runtime.GOOS

cmd/vibeaura/version.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var versionCmd = &cobra.Command{
10+
Use: "version",
11+
Short: "Print the version number of vibeaura",
12+
Run: func(cmd *cobra.Command, args []string) {
13+
fmt.Printf("vibeaura version %s\n", Version)
14+
if Commit != "none" {
15+
fmt.Printf("commit: %s\n", Commit)
16+
}
17+
},
18+
}
19+
20+
func init() {
21+
rootCmd.AddCommand(versionCmd)
22+
}
23+

install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ if [ "$OS" = "android" ]; then
6666
INSTALL_DIR="$HOME/bin"
6767
mkdir -p "$INSTALL_DIR"
6868
mv vibeaura "$INSTALL_DIR/vibeaura"
69+
chmod +x "$INSTALL_DIR/vibeaura"
6970
echo "Successfully installed vibeauracle to $INSTALL_DIR/vibeaura"
7071

7172
# Auto-add to PATH

0 commit comments

Comments
 (0)