name: Test Rust Model Generation
on:
push:
branches: [main]
paths:
- nomy_data_models/**/*.py
- scripts/generate_rust.py
- scripts/templates/**
pull_request:
branches: [main]
paths:
- nomy_data_models/**/*.py
- scripts/generate_rust.py
- scripts/templates/**
workflow_dispatch:
permissions:
contents: read
jobs:
test-py-to-rust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Run py_to_rust tests
run: |
# Run all tests to ensure 100% coverage
poetry run pytest tests/python -v --cov=nomy_data_models --cov-report=term --cov-report=xml --cov-fail-under=100
test-rust-model-generation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Install git hooks
run: |
chmod +x ./scripts/install-hooks.sh
./scripts/install-hooks.sh
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Generate and verify Rust models
run: |
poetry run python scripts/generate_rust.py --verify
- name: Check if all models were generated
run: |
# Get the number of Python models
PYTHON_MODELS=$(poetry run python -c "from nomy_data_models.py_to_rust import get_all_models; print(len(get_all_models()))")
# Get the number of generated Rust models (excluding mod.rs and enum files)
RUST_MODELS=$(find src/models -name "*.rs" -not -name "mod.rs" -not -name "datastate.rs" -not -name "market_type.rs" -not -name "position_direction.rs" -not -name "position_status.rs" -not -name "position_type.rs" -not -name "service_state.rs" -not -name "sync_state.rs" | wc -l)
echo "Python models: $PYTHON_MODELS"
echo "Rust models: $RUST_MODELS"
if [ "$RUST_MODELS" -lt "$PYTHON_MODELS" ]; then
echo "Error: Not all models were generated. Expected at least $PYTHON_MODELS, got $RUST_MODELS."
exit 1
fi