name: Build Crossplane Provider

on:
  push:
    branches: [ main, develop ]
    paths:
      - 'crossplane-provider-proxmox/**'
  pull_request:
    branches: [ main, develop ]
    paths:
      - 'crossplane-provider-proxmox/**'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      
      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.21'
      
      - name: Cache Go modules
        uses: actions/cache@v3
        with:
          path: ~/go/pkg/mod
          key: \${{ runner.os }}-go-\${{ hashFiles('**/go.sum') }}
          restore-keys: |
            \${{ runner.os }}-go-
      
      - name: Install dependencies
        working-directory: ./crossplane-provider-proxmox
        run: go mod download
      
      - name: Run tests
        working-directory: ./crossplane-provider-proxmox
        run: make test
      
      - name: Build provider
        working-directory: ./crossplane-provider-proxmox
        run: make build
      
      - name: Generate CRDs
        working-directory: ./crossplane-provider-proxmox
        run: make manifests
      
      - name: Check for build artifacts
        working-directory: ./crossplane-provider-proxmox
        run: |
          if [ -f bin/provider ]; then
            echo "✓ Provider binary built successfully"
            ls -lh bin/
          else
            echo "✗ Provider binary not found"
            exit 1
          fi

