name: Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .
pip install pytest pytest-asyncio pytest-cov flake8 black mypy
- name: Run tests
env:
TRUENAS_URL: https://mock-truenas.local
TRUENAS_API_KEY: mock-api-key
TRUENAS_VERIFY_SSL: false
run: |
# Try importing the package
python -c "from truenas_mcp_server import TrueNASMCPServer; print('Import successful')"
# Run pytest if tests exist
if ls tests/test_*.py 1> /dev/null 2>&1; then
pytest tests/ || true
fi
- name: Check code formatting with Black
run: |
black --check --line-length=100 truenas_mcp_server/ tests/ examples/ || true
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 truenas_mcp_server/ --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings
flake8 truenas_mcp_server/ --count --exit-zero --max-complexity=10 --max-line-length=100 --statistics || true
build:
runs-on: ubuntu-latest
needs: test
steps:
- 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 twine
- name: Build package
run: |
python -m build
- name: Check package
run: |
twine check dist/* || true
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/