Browse Source

ci: report the release version in the server health endpoint

httpapi.Version was a hardcoded const (2.11.0), so the v2.11.1 release
still reported 2.11.0 in /api/health and the updater compared against the
wrong version. Make it a var and inject it via goreleaser ({{.Version}})
and in go.yml (last tag, since the rolling build has no semver of its own).
gnacho 3 months ago
parent
commit
f4300f27f2
3 changed files with 12 additions and 3 deletions
  1. 5 1
      .github/workflows/go.yml
  2. 3 0
      .goreleaser.yaml
  3. 4 2
      server-go/internal/httpapi/server.go

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

@@ -91,7 +91,11 @@ jobs:
         # available" permanente aunque el binario sea el de main HEAD.
         # -X agentbin.EmbeddedAgentVersion: la versión del agente embebido;
         # alimenta el campo updateAvailable de GET /api/agents.
-        run: go build -trimpath -ldflags "-s -w -X github.com/gnacho/netpulse/server-go/internal/updater.BuildCommit=${GITHUB_SHA::7} -X github.com/gnacho/netpulse/server-go/internal/agentbin.EmbeddedAgentVersion=${AGENT_VERSION}" -o netpulse ./cmd/netpulse
+        # -X httpapi.Version: la versión semver del último tag (rolling por
+        # commit no tiene versión propia; reporta la del release más reciente).
+        run: |
+          VER=$(git describe --tags --abbrev=0 || echo "0.0.0")
+          go build -trimpath -ldflags "-s -w -X github.com/gnacho/netpulse/server-go/internal/updater.BuildCommit=${GITHUB_SHA::7} -X github.com/gnacho/netpulse/server-go/internal/agentbin.EmbeddedAgentVersion=${AGENT_VERSION} -X github.com/gnacho/netpulse/server-go/internal/httpapi.Version=${VER}" -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

+ 3 - 0
.goreleaser.yaml

@@ -27,6 +27,9 @@ builds:
       - -w
       - "-X github.com/gnacho/netpulse/server-go/internal/updater.BuildCommit={{.ShortCommit}}"
       - "-X github.com/gnacho/netpulse/server-go/internal/agentbin.EmbeddedAgentVersion={{ .Env.AGENT_VERSION }}"
+      # -X httpapi.Version: sin esto el health reporta el fallback local
+      # (httpapi.go declara var Version) en vez de la versión del tag.
+      - "-X github.com/gnacho/netpulse/server-go/internal/httpapi.Version={{.Version}}"
 
   - id: netpulse-collector
     dir: collector

+ 4 - 2
server-go/internal/httpapi/server.go

@@ -32,8 +32,10 @@ import (
 	"github.com/gnacho/netpulse/server-go/internal/updater"
 )
 
-// Version es la versión del backend (app.js:18).
-const Version = "2.11.0"
+// Version es la versión del backend (app.js:18). Es una var (no const) para
+// que goreleaser la inyecte con -X httpapi.Version={{.Version}} y el health
+// reporte la versión del tag; los builds locales caen al fallback.
+var Version = "2.11.0"
 
 // Deps son las dependencias del servidor API (como createApp de app.js).
 type Deps struct {