Browse Source

fix(ci): inject BuildCommit in go.yml so the updater reports the real SHA (#83)

go.yml built the server binary with plain '-ldflags "-s -w"' (no -X),
so updater.BuildCommit was always empty and gitShort fell back to
'git -C repoRoot rev-parse'. On the CT 226 that repo has dubious
ownership and a stale HEAD → the updater reported a commit from days
ago as 'current', producing a permanent false 'update available' even
when the binary was already at main HEAD.

Inject -X updater.BuildCommit=<short SHA> (same as goreleaser does for
releases) so the running binary knows its own commit. The short SHA
(GITHUB_SHA first 7 chars) matches the 7-char truncation that
fetchLatestCommit applies to the 'latest' field.

Co-authored-by: gnacho <hnacho@proton.me>
Nacho 4 months ago
parent
commit
586010f552
1 changed files with 4 additions and 1 deletions
  1. 4 1
      .github/workflows/go.yml

+ 4 - 1
.github/workflows/go.yml

@@ -79,7 +79,10 @@ jobs:
           CGO_ENABLED: 0
           GOOS: linux
           GOARCH: ${{ matrix.arch }}
-        run: go build -trimpath -ldflags "-s -w" -o netpulse ./cmd/netpulse
+        # -X updater.BuildCommit: sin esto el updater del CT cae a git rev-parse
+        # (repo stale dubious-ownership) y reporta un SHA viejo → falso "update
+        # available" permanente aunque el binario sea el de main HEAD.
+        run: go build -trimpath -ldflags "-s -w -X github.com/gnacho/netpulse/server-go/internal/updater.BuildCommit=${GITHUB_SHA::7}" -o netpulse ./cmd/netpulse
 
       - name: Empaqueta binario + despliegue
         run: tar czf netpulse-server-${{ github.sha }}-linux-${{ matrix.arch }}.tar.gz -C server-go netpulse .env.example -C .. deploy