name: ci

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

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

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build images
        run: |
          cp -n .env.example .env || true
          docker compose build simulator dev

      - name: Critical lint (syntax / undefined names)
        run: docker compose run --rm --no-deps dev ruff check app tests --select E9,F63,F7,F82

      - name: Offline unit + contract tests
        run: make test

      - name: Helm template
        run: |
          curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
          make helm-template

  integration:
    runs-on: ubuntu-latest
    needs: offline
    steps:
      - uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Start stack
        run: |
          cp -n .env.example .env || true
          make up
          make seed

      - name: Smoke
        run: make smoke

      - name: Contract pack activate
        run: |
          curl -sf -X POST http://127.0.0.1:5000/ui/api/ovirt/contracts/activate \
            -H 'Content-Type: application/json' \
            -d '{"series":"3.6"}'
          curl -sf -X POST http://127.0.0.1:5000/ui/api/ovirt/contracts/activate \
            -H 'Content-Type: application/json' \
            -d '{"series":"4.5"}'

      - name: Integration tests
        run: make test-integration
