go.yml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. name: go-server
  2. # Compila el backend Go (con app/dist embebido en el binario) y lo publica como
  3. # asset de la prerelease "go-latest" (el CT 226 tiene 512MB y no tiene Go; el
  4. # updater descarga el binario exacto de su commit:
  5. # netpulse-server-<sha>-linux-<arch>.tar.gz).
  6. on:
  7. push:
  8. branches: [main]
  9. paths:
  10. - 'server-go/**'
  11. - 'app/**' # el dist va embebido en el binario
  12. - '.github/workflows/go.yml'
  13. workflow_dispatch:
  14. jobs:
  15. build:
  16. runs-on: ubuntu-latest
  17. permissions:
  18. contents: write # publicar assets en la prerelease go-latest
  19. strategy:
  20. matrix:
  21. arch: [amd64, arm64]
  22. steps:
  23. - uses: actions/checkout@v4
  24. - uses: actions/setup-node@v4
  25. with:
  26. node-version: 22
  27. cache: npm
  28. cache-dependency-path: app/package-lock.json
  29. - uses: actions/setup-go@v5
  30. with:
  31. go-version: '1.26'
  32. cache-dependency-path: server-go/go.sum
  33. - name: Build frontend
  34. working-directory: app
  35. run: npm ci --no-audit --no-fund && npm run build
  36. - name: Copia dist al embed del binario
  37. run: rm -rf server-go/internal/staticspa/dist && cp -r app/dist server-go/internal/staticspa/dist
  38. - name: Tests Go
  39. working-directory: server-go
  40. run: go test ./...
  41. - name: Build agent binaries para embed (todas las arquitecturas)
  42. env:
  43. CGO_ENABLED: 0
  44. GOOS: linux
  45. run: |
  46. set -e
  47. # amd64
  48. (cd agent && GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o ../server-go/internal/agentbin/agents/netpulse-agent-amd64 ./cmd/netpulse-agent)
  49. # arm64
  50. (cd agent && GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o ../server-go/internal/agentbin/agents/netpulse-agent-arm64 ./cmd/netpulse-agent)
  51. # armv7
  52. (cd agent && GOARCH=arm GOARM=7 go build -trimpath -ldflags "-s -w" -o ../server-go/internal/agentbin/agents/netpulse-agent-armv7 ./cmd/netpulse-agent)
  53. - name: Build binario (linux/${{ matrix.arch }})
  54. working-directory: server-go
  55. env:
  56. CGO_ENABLED: 0
  57. GOOS: linux
  58. GOARCH: ${{ matrix.arch }}
  59. run: go build -trimpath -ldflags "-s -w" -o netpulse ./cmd/netpulse
  60. - name: Empaqueta binario + despliegue
  61. run: tar czf netpulse-server-${{ github.sha }}-linux-${{ matrix.arch }}.tar.gz -C server-go netpulse .env.example -C .. deploy
  62. - name: Publica en prerelease go-latest
  63. uses: softprops/action-gh-release@v2
  64. with:
  65. tag_name: go-latest
  66. name: go-latest
  67. prerelease: true
  68. files: netpulse-server-${{ github.sha }}-linux-${{ matrix.arch }}.tar.gz
  69. - name: Limpia assets antiguos (conserva los 10 más recientes por fecha)
  70. env:
  71. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  72. run: |
  73. gh api repos/${{ github.repository }}/releases/tags/go-latest \
  74. --jq '.assets | sort_by(.created_at) | reverse | .[10:] | .[].name' \
  75. | while read -r a; do gh release delete-asset go-latest "$a" -y; done