Skip to content

Commit 3e7f5fa

Browse files
ericfitzclaude
andcommitted
fix(version): use SOURCE_VERSION env var for Heroku deployments
When built without ldflags (e.g., Heroku Go buildpack), GitCommit defaults to "development". Now checks SOURCE_VERSION environment variable at startup as fallback, which Heroku sets to the git SHA during builds. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 24f7dad commit 3e7f5fa

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"major": 1,
33
"minor": 1,
4-
"patch": 2
4+
"patch": 3
55
}

api/version.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"os"
78
"strconv"
89
"strings"
910
"time"
@@ -12,6 +13,21 @@ import (
1213
"github.com/gin-gonic/gin"
1314
)
1415

16+
func init() {
17+
// If GitCommit wasn't set at build time via ldflags, try environment variables.
18+
// Heroku sets SOURCE_VERSION to the git commit SHA during builds.
19+
if GitCommit == "development" {
20+
if commit := os.Getenv("SOURCE_VERSION"); commit != "" {
21+
// Use short commit hash (7 chars) like git rev-parse --short
22+
if len(commit) > 7 {
23+
GitCommit = commit[:7]
24+
} else {
25+
GitCommit = commit
26+
}
27+
}
28+
}
29+
}
30+
1531
// Version contains versioning information for the API
1632
type Version struct {
1733
Major int `json:"major"`
@@ -29,7 +45,7 @@ var (
2945
// Minor version number
3046
VersionMinor = "1"
3147
// Patch version number
32-
VersionPatch = "2"
48+
VersionPatch = "3"
3349
// GitCommit is the git commit hash from build
3450
GitCommit = "development"
3551
// BuildDate is the build timestamp

0 commit comments

Comments
 (0)