name: Build

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.23.3'
        check-latest: true

    - name: Install controller-gen
      run: |
        go install sigs.k8s.io/controller-tools/cmd/controller-gen@latest

    - name: Build Multi-arch
      run: make build-multiarch

    - name: Upload artifacts
      uses: actions/upload-artifact@v3
      with:
        name: binaries
        path: |
          bin/karpenter-clusterapi-controller-linux-amd64
          bin/karpenter-clusterapi-controller-linux-arm64

  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.23.3'
        check-latest: true

    - name: Run tests
      run: make test

  lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.23.3'
        check-latest: true

    - name: golangci-lint
      uses: golangci/golangci-lint-action@v3
      with:
        version: latest
