diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 74cb2f1..aedb0a0 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,12 +1,20 @@ -name: NexusGuard CI +name: NexusGuard CI/CD + on: push: branches: [main] - tags: ['v*'] + tags: ['v*', 'dev-*'] pull_request: branches: [main] +env: + REGISTRY: git.datadunia.com + IMAGE_PREFIX: ${{ github.repository }} + jobs: + # ────────────────────────────────────────────── + # TEST — all 3 components in parallel + # ────────────────────────────────────────────── server-core-test: runs-on: ubuntu-latest defaults: @@ -14,10 +22,14 @@ jobs: working-directory: apps/server-core steps: - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 - uses: actions/setup-go@v5 with: go-version: '1.25' - - run: go test ./... -tags dev -cover + - name: Test + run: go test ./... -tags dev -cover device-agent-test: runs-on: ubuntu-latest @@ -26,10 +38,14 @@ jobs: working-directory: apps/device-agent steps: - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 - uses: actions/setup-go@v5 with: go-version: '1.25' - - run: go test ./... -cover + - name: Test + run: go test ./... -cover dashboard-ui-build: runs-on: ubuntu-latest @@ -38,8 +54,159 @@ jobs: working-directory: apps/dashboard-ui steps: - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: '24' - - run: npm ci - - run: npm run build + - name: Install + run: npm ci || npm install + - name: Type check & Build + run: npm run build + + # ────────────────────────────────────────────── + # BUILD GO BINARIES (server-core + device-agent) + # ────────────────────────────────────────────── + server-core-build: + runs-on: ubuntu-latest + needs: server-core-test + defaults: + run: + working-directory: apps/server-core + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-go@v5 + with: + go-version: '1.25' + - name: Build + run: go build -o bin/server-core . + - name: Upload binary + uses: actions/upload-artifact@v4 + with: + name: server-core-linux-amd64 + path: apps/server-core/bin/server-core + + device-agent-cross-build: + runs-on: ubuntu-latest + needs: device-agent-test + strategy: + matrix: + goos: [linux, windows] + goarch: [amd64, arm64] + exclude: + - goos: windows + goarch: arm64 + defaults: + run: + working-directory: apps/device-agent + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-go@v5 + with: + go-version: '1.25' + - name: Build + env: + CGO_ENABLED: 0 + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: | + EXT="" + if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi + go build -o bin/nexus-device-agent-${{ matrix.goos }}-${{ matrix.goarch }}${EXT} . + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: nexus-device-agent-${{ matrix.goos }}-${{ matrix.goarch }} + path: apps/device-agent/bin/nexus-device-agent-* + + # ────────────────────────────────────────────── + # DOCKER — build & push (main + tags only) + # ────────────────────────────────────────────── + docker-build-push: + runs-on: ubuntu-latest + needs: [server-core-build, dashboard-ui-build] + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/tags/dev-') + strategy: + matrix: + include: + - name: server-core + context: apps/server-core + image: nexusguard-server-core + - name: dashboard-ui + context: apps/dashboard-ui + image: nexusguard-dashboard-ui + build-args: | + VITE_API_BASE_URL=${{ vars.VITE_API_BASE_URL }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.image }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=tag + type=sha,prefix= + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: ${{ matrix.context }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + # ────────────────────────────────────────────── + # RELEASE — annotated tag + artifacts + # ────────────────────────────────────────────── + release: + runs-on: ubuntu-latest + needs: [docker-build-push, device-agent-cross-build] + if: startsWith(github.ref, 'refs/tags/v') + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts/ + + - name: Prepare release assets + run: | + mkdir -p release/ + cp artifacts/nexus-device-agent-*/nexus-device-agent-* release/ 2>/dev/null || true + cp artifacts/server-core-linux-amd64/server-core release/nexus-server-core-linux-amd64 || true + chmod +x release/nexus-server-core-linux-amd64 + cd release && sha256sum * > checksums-sha256.txt + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true + files: | + release/*