name: CI / Deploy to Hugging Face Spaces on: push: branches: [main] pull_request: branches: [main] jobs: # ── 1. Build check — runs on every push and every PR ────────────────────── # # Catches compilation and build errors before anything is deployed. # Both Go and the React frontend must build cleanly to pass. # ────────────────────────────────────────────────────────────────────────── build-check: name: Build check runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 # ── Go backend ── - name: Set up Go uses: actions/setup-go@v5 with: go-version: "1.23" cache-dependency-path: Apps/licensemanagerApp/backend/go.sum - name: Build Go backend working-directory: Apps/licensemanagerApp/backend run: go build ./... # ── React frontend ── - name: Set up Node uses: actions/setup-node@v4 with: node-version: "20" cache: npm cache-dependency-path: Apps/licensemanagerApp/frontend/package-lock.json - name: Install frontend dependencies working-directory: Apps/licensemanagerApp/frontend run: npm install - name: Build frontend working-directory: Apps/licensemanagerApp/frontend run: npm run build # ── 2. Deploy — only on push to main, only after build-check passes ──────── # # Pushes this repository to the Hugging Face Space's git remote. # HF Spaces detects the push, builds the Dockerfile, and redeploys. # # Required GitHub Secrets (Settings → Secrets → Actions): # HF_TOKEN — Hugging Face access token (write access) # # Required GitHub Variables (Settings → Variables → Actions): # HF_USERNAME — your Hugging Face username e.g. "futurealgos" # HF_SPACE_NAME — the Space name e.g. "licensemanager" # ────────────────────────────────────────────────────────────────────────── deploy: name: Deploy to HF Spaces runs-on: ubuntu-latest needs: build-check if: github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - name: Checkout (full history) uses: actions/checkout@v4 with: fetch-depth: 0 # full history so the push is not a shallow clone - name: Push to Hugging Face Spaces env: HF_TOKEN: ${{ secrets.HF_TOKEN }} HF_USERNAME: ${{ vars.HF_USERNAME }} HF_SPACE_NAME: ${{ vars.HF_SPACE_NAME }} run: | git config user.email "github-actions[bot]@users.noreply.github.com" git config user.name "github-actions[bot]" # Add the HF Space as a remote (token embedded in URL for auth) git remote add hf-space \ https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME} # Force-push so HF Space always matches the GitHub main branch exactly git push hf-space HEAD:main --force