Skip to content

Commit f6598d7

Browse files
fix: versioning and install (#6)
Co-authored-by: Danny Teller <danny.teller@tipalti.com>
1 parent 864163d commit f6598d7

6 files changed

Lines changed: 81 additions & 21 deletions

File tree

.github/workflows/release.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,26 @@ jobs:
187187
GOARCH: ${{ matrix.goarch }}
188188
CGO_ENABLED: 0
189189
run: |
190-
VERSION=${GITHUB_REF_NAME:-dev}
190+
# Use Git-based version detection like our build script
191+
if VERSION=$(git describe --tags --exact-match HEAD 2>/dev/null); then
192+
echo "On exact tag: $VERSION"
193+
elif LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null); then
194+
COMMIT_COUNT=$(git rev-list --count "$LATEST_TAG"..HEAD 2>/dev/null || echo "0")
195+
SHORT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
196+
if [[ "$COMMIT_COUNT" -gt 0 ]]; then
197+
VERSION="${LATEST_TAG}-dev.${COMMIT_COUNT}+${SHORT_COMMIT}"
198+
else
199+
VERSION="$LATEST_TAG"
200+
fi
201+
echo "Based on tag: $VERSION"
202+
elif SHORT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null); then
203+
VERSION="v0.0.0-dev+${SHORT_COMMIT}"
204+
echo "No tags found, using commit: $VERSION"
205+
else
206+
VERSION="dev"
207+
echo "Fallback version: $VERSION"
208+
fi
209+
191210
COMMIT=$(git rev-parse --short HEAD)
192211
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
193212

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## [Unreleased]
22

3+
### Fixed
4+
- Fixed version command to display proper semantic versions instead of 'dev' or branch names
5+
- Fixed build process to use Git-based version detection that works locally and in CI/CD
6+
- Fixed installation script URL generation bug where info messages were captured in version string causing malformed download URLs
7+
- Fixed installation script artifact naming to use underscores (matlas_darwin_arm64.tar.gz) instead of hyphens to match actual release artifacts
8+
- Fixed installation script cleanup trap to handle unbound variables with set -u option
9+
310
### Added
411
- **Comprehensive Backup Features**: Complete backup and Point-in-Time Recovery implementation
512
- Point-in-Time Recovery (PIT) support with proper validation workflow

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build:
88

99
$(BINARY):
1010
@mkdir -p $(BIN_DIR)
11-
go build -o $(BINARY) .
11+
./scripts/build/build.sh build -o $(BINARY)
1212

1313
test:
1414
./scripts/test.sh unit

install.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ function Download-Binary {
144144
# Remove 'v' prefix if present
145145
$cleanVersion = $Version -replace '^v', ''
146146

147-
$platform = "windows-$(Get-Architecture)"
148-
$archiveName = "$BINARY_NAME-$platform.zip"
147+
$platform = "windows_$(Get-Architecture)"
148+
$archiveName = "$BINARY_NAME`_$platform.zip"
149149
$downloadUrl = "https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/v$cleanVersion/$archiveName"
150150

151151
Write-Info "Downloading $archiveName..."
@@ -176,7 +176,7 @@ function Download-Binary {
176176
$binaryPath = $null
177177
$possiblePaths = @(
178178
(Join-Path $tempDir "$BINARY_NAME.exe"),
179-
(Join-Path $tempDir "$BINARY_NAME-$platform.exe")
179+
(Join-Path $tempDir "$BINARY_NAME`_$platform.exe")
180180
)
181181

182182
foreach ($path in $possiblePaths) {

install.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ detect_platform() {
4747
exit 1 ;;
4848
esac
4949

50-
echo "${os}-${arch}"
50+
echo "${os}_${arch}"
5151
}
5252

5353
# Check if running as root (for install dir permissions)
@@ -73,7 +73,7 @@ prepare_install_dir() {
7373

7474
# Get the latest release version from GitHub
7575
get_latest_version() {
76-
print_info "Fetching latest release information..."
76+
print_info "Fetching latest release information..." >&2
7777

7878
if command -v curl >/dev/null 2>&1; then
7979
curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest" | \
@@ -96,12 +96,12 @@ download_binary() {
9696
local temp_dir
9797

9898
temp_dir=$(mktemp -d)
99-
trap 'rm -rf "$temp_dir"' EXIT
99+
trap 'if [[ -n "${temp_dir:-}" ]] && [[ -d "${temp_dir:-}" ]]; then rm -rf "$temp_dir"; fi' EXIT
100100

101101
# Remove 'v' prefix if present
102102
version="${version#v}"
103103

104-
local archive_name="${BINARY_NAME}-${platform}.tar.gz"
104+
local archive_name="${BINARY_NAME}_${platform}.tar.gz"
105105
local download_url="https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/v${version}/${archive_name}"
106106

107107
print_info "Downloading $archive_name..."
@@ -125,8 +125,8 @@ download_binary() {
125125
local binary_path
126126
if [[ -f "$temp_dir/$BINARY_NAME" ]]; then
127127
binary_path="$temp_dir/$BINARY_NAME"
128-
elif [[ -f "$temp_dir/${BINARY_NAME}-${platform}" ]]; then
129-
binary_path="$temp_dir/${BINARY_NAME}-${platform}"
128+
elif [[ -f "$temp_dir/${BINARY_NAME}_${platform}" ]]; then
129+
binary_path="$temp_dir/${BINARY_NAME}_${platform}"
130130
else
131131
# Try to find any executable file
132132
binary_path=$(find "$temp_dir" -type f -executable | head -1)

scripts/build/build.sh

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,59 @@ print_error() { echo -e "${RED}✗ $1${NC}"; }
2222
print_info() { echo -e "${BLUE}$1${NC}"; }
2323

2424
get_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

3665
build_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

69100
cross_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

Comments
 (0)