@@ -22,28 +22,59 @@ print_error() { echo -e "${RED}✗ $1${NC}"; }
2222print_info () { echo -e " ${BLUE} ℹ $1 ${NC} " ; }
2323
2424get_version () {
25- # Try to get version from git
26- if git describe --tags --abbrev=0 2> /dev/null; then
25+ # Try to get a proper semantic version from git
26+ local version
27+
28+ # First try to get exact tag on current commit
29+ if version=$( git describe --tags --exact-match HEAD 2> /dev/null) ; then
30+ echo " $version "
2731 return 0
28- elif git rev-parse --short HEAD 2> /dev/null; then
32+ fi
33+
34+ # Get the latest tag and add commit info if we're ahead
35+ if version=$( git describe --tags --abbrev=0 2> /dev/null) ; then
36+ local commit_count=$( git rev-list --count " $version " ..HEAD 2> /dev/null || echo " 0" )
37+ if [[ " $commit_count " -gt 0 ]]; then
38+ local short_commit=$( git rev-parse --short HEAD 2> /dev/null || echo " unknown" )
39+ echo " ${version} -dev.${commit_count} +${short_commit} "
40+ else
41+ echo " $version "
42+ fi
2943 return 0
30- else
31- echo " dev"
44+ fi
45+
46+ # No tags found, use commit-based version
47+ if version=$( git rev-parse --short HEAD 2> /dev/null) ; then
48+ echo " v0.0.0-dev+${version} "
3249 return 0
3350 fi
51+
52+ # Fallback for non-git environments
53+ echo " dev"
54+ return 0
55+ }
56+
57+ get_commit () {
58+ git rev-parse --short HEAD 2> /dev/null || echo " unknown"
59+ }
60+
61+ get_build_time () {
62+ date -u +" %Y-%m-%dT%H:%M:%SZ"
3463}
3564
3665build_binary () {
3766 local output_name=" ${1:- matlas} "
38- local version
67+ local version commit build_time
3968 version=$( get_version)
69+ commit=$( get_commit)
70+ build_time=$( get_build_time)
4071
4172 print_info " Building $output_name (version: $version )..."
4273
4374 cd " $PROJECT_ROOT "
4475
45- # Build flags
46- local ldflags=" -X main.version=$version -X main.buildDate= $( date -u +%Y-%m-%dT%H:%M:%SZ ) "
76+ # Build flags - match what release.yml uses
77+ local ldflags=" -s -w - X main.version=$version -X main.commit= $commit -X main.buildTime= $build_time "
4778
4879 if go build -ldflags " $ldflags " -o " $output_name " ; then
4980 print_success " Build completed: $output_name "
@@ -67,8 +98,10 @@ build_binary() {
6798}
6899
69100cross_compile () {
70- local version
101+ local version commit build_time
71102 version=$( get_version)
103+ commit=$( get_commit)
104+ build_time=$( get_build_time)
72105
73106 print_info " Cross-compiling for multiple platforms..."
74107
@@ -93,7 +126,8 @@ cross_compile() {
93126
94127 print_info " Building for $os /$arch ..."
95128
96- local ldflags=" -X main.version=$version -X main.buildDate=$( date -u +%Y-%m-%dT%H:%M:%SZ) "
129+ # Build flags - match what release.yml uses
130+ local ldflags=" -s -w -X main.version=$version -X main.commit=$commit -X main.buildTime=$build_time "
97131
98132 if GOOS=" $os " GOARCH=" $arch " go build -ldflags " $ldflags " -o " $output " ; then
99133 print_success " Built: $output "
0 commit comments