4
0

go.yml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 binario (linux/${{ matrix.arch }})
  42. working-directory: server-go
  43. env:
  44. CGO_ENABLED: 0
  45. GOOS: linux
  46. GOARCH: ${{ matrix.arch }}
  47. run: go build -trimpath -ldflags "-s -w" -o netpulse ./cmd/netpulse
  48. - name: Empaqueta binario + despliegue
  49. run: tar czf netpulse-server-${{ github.sha }}-linux-${{ matrix.arch }}.tar.gz -C server-go netpulse .env.example -C .. deploy
  50. - name: Publica en prerelease go-latest
  51. uses: softprops/action-gh-release@v2
  52. with:
  53. tag_name: go-latest
  54. name: go-latest
  55. prerelease: true
  56. files: netpulse-server-${{ github.sha }}-linux-${{ matrix.arch }}.tar.gz
  57. - name: Limpia assets antiguos (conserva los 10 más recientes por fecha)
  58. env:
  59. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  60. run: |
  61. gh api repos/${{ github.repository }}/releases/tags/go-latest \
  62. --jq '.assets | sort_by(.created_at) | reverse | .[10:] | .[].name' \
  63. | while read -r a; do gh release delete-asset go-latest "$a" -y; done