name: CI

on:
  push:
    branches: [ main, master, develop, feature/** ]
  pull_request:
    # Trigger on all pull requests regardless of target branch
  workflow_dispatch:

jobs:
  lint:
    name: Lint with ruff
    runs-on: ubuntu-latest
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.11'
        
    - name: Install ruff
      run: |
        python -m pip install --upgrade pip
        pip install ruff>=0.1.0
        
    - name: Run ruff check
      run: |
        ruff check nanobot/
        
    - name: Run ruff format check
      run: |
        ruff format --check nanobot/

  test:
    name: Test Python ${{ matrix.python-version }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.11', '3.12']
        
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        # Install nanobot with all dependencies and dev dependencies
        pip install -e ".[dev]"
        # Verify key dependencies are installed
        pip list | grep -E "(pytest|ruff|pydantic|typer|litellm)"
        
    - name: Run tests
      run: |
        pytest tests/ -v --tb=short
        
    - name: Check package can be imported
      run: |
        python -c "import nanobot; print(f'nanobot version check passed')"

  build:
    name: Build package
    runs-on: ubuntu-latest
    needs: [lint, test]
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.11'
        
    - name: Install build dependencies
      run: |
        python -m pip install --upgrade pip
        pip install build hatchling
        
    - name: Build package
      run: |
        python -m build
        
    - name: Check build artifacts
      run: |
        ls -lh dist/
        
    - name: Upload build artifacts
      uses: actions/upload-artifact@v4
      with:
        name: dist-packages
        path: dist/
        retention-days: 7

