name: go-server # Compila el backend Go (con app/dist embebido en el binario) y lo publica como # asset de la prerelease "go-latest" (el CT 226 tiene 512MB y no tiene Go; el # updater descarga el binario exacto de su commit: # netpulse-server--linux-.tar.gz). # Sin filtro de rutas (#471): si un push a main no toca server-go/ ni app/ # no se publica asset de ese SHA, y el updater del CT se queda ofreciendo una # actualización imposible (cae al asset más viejo y current != latest para # siempre). Con este trigger, CADA SHA de main tiene su binario en go-latest. on: push: branches: [main] workflow_dispatch: jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: node-version: 24 cache: npm cache-dependency-path: app/package-lock.json - name: ESLint (app) working-directory: app run: npm ci --no-audit --no-fund && npm run lint build: runs-on: ubuntu-latest permissions: contents: write # publicar assets en la prerelease go-latest strategy: matrix: arch: [amd64, arm64] steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: fetch-depth: 0 # tags necesarias para git describe (httpapi.Version) # Versión del agente embebido: fuente única de verdad en agent/VERSION # (#790), leída en cada build. Se inyecta igual en el binario del agente # (main.Version) y en el servidor (agentbin.EmbeddedAgentVersion): el # campo updateAvailable de GET /api/agents compara la versión reportada # del agente contra esa versión. Solo sube cuando cambia agent/ de verdad. - name: Resuelve AGENT_VERSION desde agent/VERSION run: | set -e AGENT_VERSION=$(tr -d '[:space:]' < agent/VERSION) if [ -z "$AGENT_VERSION" ]; then echo "::error::agent/VERSION está vacío" exit 1 fi echo "AGENT_VERSION=$AGENT_VERSION" >> "$GITHUB_ENV" - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: node-version: 24 cache: npm cache-dependency-path: app/package-lock.json - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 with: go-version: '1.26' cache-dependency-path: server-go/go.sum - name: Build frontend working-directory: app run: npm ci --no-audit --no-fund && npm run build - name: Copia dist al embed del binario run: rm -rf server-go/internal/staticspa/dist && cp -r app/dist server-go/internal/staticspa/dist # Antes de los tests: TestOpenArmVariants abre los binarios embebidos # y además go:embed los necesita presentes para compilar el servidor. # OJO los nombres: Open() resuelve "agents/netpulse-agent-" + normalizeArch(arch) # y normalizeArch mapea armv7/armv7l/armhf -> arm, así que el fichero se # llama netpulse-agent-arm (con GOARM=7), NO netpulse-agent-armv7 (#458). # upx: agentes empaquetados (#1890); el script falla si upx no está. - name: Instala upx run: sudo apt-get update && sudo apt-get install -y upx-ucl - name: Build agent binaries para embed (todas las arquitecturas) run: scripts/build-agents.sh "$AGENT_VERSION" - name: Tests Go working-directory: server-go run: go test ./... - name: Build binario (linux/${{ matrix.arch }}) working-directory: server-go env: CGO_ENABLED: 0 GOOS: linux GOARCH: ${{ matrix.arch }} # -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. # -X agentbin.EmbeddedAgentVersion: la versión del agente embebido; # alimenta el campo updateAvailable de GET /api/agents. # -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: | # --match 'v[0-9]*': sin filtro, git describe pilla el tag del AGENTE # (agent/vX.Y.Z) y lo inyecta como versión del server (#869). VER=$(git describe --tags --abbrev=0 --match 'v[0-9]*' || 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 - name: Publica en prerelease go-latest uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2 with: tag_name: go-latest name: go-latest prerelease: true files: netpulse-server-${{ github.sha }}-linux-${{ matrix.arch }}.tar.gz # El cleanup va en un job aparte TRAS la matrix (#290): dentro del job build # cada arco listaba y borraba los mismos assets en paralelo y todos menos el # primero recibían 404. Aquí corre una sola vez, cuando ya no hay escritores # concurrentes. cleanup-go-latest: needs: build runs-on: ubuntu-latest permissions: contents: write # borrar assets antiguos de la prerelease go-latest steps: - name: Limpia assets antiguos (conserva los 10 más recientes por fecha) env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh api repos/${{ github.repository }}/releases/tags/go-latest \ --jq '.assets | sort_by(.created_at) | reverse | .[10:] | .[].name' \ | while read -r a; do gh release delete-asset -R "${{ github.repository }}" go-latest "$a" -y \ || echo "warn: no se pudo borrar '$a' (¿ya borrado?); se continúa" done