refactor: Replace ldflags version injection with debug.BuildInfo

- Use debug.ReadBuildInfo() for version information (Go 1.18+ best practice)
- Extract version from module info and VCS settings (vcs.revision, vcs.time)
- Remove complex ldflags setup from Makefile and GitHub workflows
- Simplify build process while maintaining all version information
- Cleaner approach recommended by Go community

Thanks to Gopher Slack feedback for this improvement!
This commit is contained in:
Tobias Gesellchen
2026-01-11 17:27:07 +01:00
parent ab21c5aef9
commit 1ed562f45e
5 changed files with 82 additions and 44 deletions
+2 -2
View File
@@ -154,9 +154,9 @@ jobs:
rm -f "$OUTPUT_NAME" "$OUTPUT_NAME.sha256" "$OUTPUT_NAME.sha512"
go clean -cache
# Build with optimizations and version info
# Build with optimizations (using debug.BuildInfo for version info)
if ! go build \
-ldflags="-s -w -X main.version=v${{ needs.validate.outputs.version }} -X main.commit=${{ github.sha }} -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-ldflags="-s -w" \
-o "$OUTPUT_NAME" \
./cmd/soundtouch-cli; then
echo "❌ Build failed"