release.yml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. name: release
  2. # Release estable por tag v*: goreleaser construye netpulse (con el frontend
  3. # embebido) y netpulse-collector para linux/amd64|arm64|armv7 + checksums.txt.
  4. # install.sh / install-collector.sh consumen estos assets.
  5. # Distinto de go.yml: aquello publica binarios rolling del commit en la
  6. # prerelease go-latest (para el updater del CT 226); esto publica versiones.
  7. on:
  8. push:
  9. tags: ['v*']
  10. workflow_dispatch: # sin tag = snapshot de prueba (no publica release)
  11. permissions:
  12. contents: write
  13. jobs:
  14. release:
  15. runs-on: ubuntu-latest
  16. steps:
  17. - uses: actions/checkout@v4
  18. with:
  19. fetch-depth: 0 # tags e historia: el gate de agent/VERSION difiere contra el tag anterior
  20. - uses: actions/setup-node@v4
  21. with:
  22. node-version: 24
  23. cache: npm
  24. cache-dependency-path: app/package-lock.json
  25. - uses: actions/setup-go@v5
  26. with:
  27. go-version: '1.26'
  28. cache-dependency-path: |
  29. server-go/go.sum
  30. collector/go.sum
  31. # Versión del agente: fuente única de verdad en agent/VERSION (#790),
  32. # desacoplada del tag del server. Se inyecta igual en el binario del
  33. # agente (main.Version) y en el servidor (agentbin.EmbeddedAgentVersion
  34. # vía .goreleaser.yaml): alimenta el campo updateAvailable de
  35. # GET /api/agents, así que solo debe subir cuando el código de agent/
  36. # cambia de verdad. Gate de consistencia: si agent/ cambió desde el tag
  37. # anterior y agent/VERSION no subió, la release falla (obliga al bump).
  38. - name: Resuelve AGENT_VERSION desde agent/VERSION
  39. id: version
  40. run: |
  41. set -e
  42. AGENT_VERSION=$(tr -d '[:space:]' < agent/VERSION)
  43. if [ -z "$AGENT_VERSION" ]; then
  44. echo "::error::agent/VERSION está vacío"
  45. exit 1
  46. fi
  47. echo "agent=$AGENT_VERSION" >> "$GITHUB_OUTPUT"
  48. PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || true)
  49. if [ -n "$PREV_TAG" ]; then
  50. if ! git diff --quiet "$PREV_TAG"..HEAD -- agent/; then
  51. PREV_AGENT=$(git show "$PREV_TAG:agent/VERSION" 2>/dev/null | tr -d '[:space:]' || true)
  52. if [ -n "$PREV_AGENT" ] && [ "$PREV_AGENT" = "$AGENT_VERSION" ]; then
  53. echo "::error::agent/ cambió desde $PREV_TAG pero agent/VERSION sigue en $AGENT_VERSION. Sube la versión del agente antes de taguear."
  54. exit 1
  55. fi
  56. fi
  57. fi
  58. - name: Build frontend + copia dist al embed (necesario para go:embed y tests)
  59. run: |
  60. npm ci --no-audit --no-fund --prefix app
  61. npm run build --prefix app
  62. rm -rf server-go/internal/staticspa/dist && cp -r app/dist server-go/internal/staticspa/dist
  63. # Antes de los tests: TestOpenArmVariants abre los binarios embebidos
  64. # (mismo orden que go.yml desde #459; aquí faltó aplicarlo y las
  65. # releases v2.25.0+ se quedaron sin assets). OJO los nombres: Open()
  66. # resuelve "agents/netpulse-agent-" + normalizeArch(arch) y esta mapea
  67. # armv7/armv7l/armhf -> arm, asi que el fichero se llama
  68. # netpulse-agent-arm (con GOARM=7), NO netpulse-agent-armv7 (#458).
  69. - name: Build agent binaries para embed (todas las arquitecturas)
  70. env:
  71. CGO_ENABLED: 0
  72. GOOS: linux
  73. run: |
  74. set -e
  75. # amd64
  76. (cd agent && GOARCH=amd64 go build -trimpath -ldflags "-s -w -X main.Version=${{ steps.version.outputs.agent }}" -o ../server-go/internal/agentbin/agents/netpulse-agent-amd64 ./cmd/netpulse-agent)
  77. # arm64
  78. (cd agent && GOARCH=arm64 go build -trimpath -ldflags "-s -w -X main.Version=${{ steps.version.outputs.agent }}" -o ../server-go/internal/agentbin/agents/netpulse-agent-arm64 ./cmd/netpulse-agent)
  79. # armv7 (fichero "arm": el nombre que busca normalizeArch)
  80. (cd agent && GOARCH=arm GOARM=7 go build -trimpath -ldflags "-s -w -X main.Version=${{ steps.version.outputs.agent }}" -o ../server-go/internal/agentbin/agents/netpulse-agent-arm ./cmd/netpulse-agent)
  81. # mipsle/mips softfloat (#488): MIPS sin FPU, ambos endianness
  82. (cd agent && GOARCH=mipsle GOMIPS=softfloat go build -trimpath -ldflags "-s -w -X main.Version=${{ steps.version.outputs.agent }}" -o ../server-go/internal/agentbin/agents/netpulse-agent-mipsle ./cmd/netpulse-agent)
  83. (cd agent && GOARCH=mips GOMIPS=softfloat go build -trimpath -ldflags "-s -w -X main.Version=${{ steps.version.outputs.agent }}" -o ../server-go/internal/agentbin/agents/netpulse-agent-mips ./cmd/netpulse-agent)
  84. - name: Tests Go (ambos módulos)
  85. run: |
  86. (cd server-go && go test ./...)
  87. (cd collector && go test ./...)
  88. - name: Valida config goreleaser
  89. uses: goreleaser/goreleaser-action@v6
  90. with:
  91. version: '~> v2'
  92. args: check
  93. - name: Release (tag v* — publica)
  94. if: github.ref_type == 'tag'
  95. uses: goreleaser/goreleaser-action@v6
  96. with:
  97. version: '~> v2'
  98. args: release --clean
  99. env:
  100. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  101. AGENT_VERSION: ${{ steps.version.outputs.agent }}
  102. - name: Release (workflow_dispatch — snapshot sin publicar)
  103. if: github.ref_type != 'tag'
  104. uses: goreleaser/goreleaser-action@v6
  105. with:
  106. version: '~> v2'
  107. args: release --clean --snapshot
  108. env:
  109. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  110. AGENT_VERSION: ${{ steps.version.outputs.agent }}