Skip to content

Add GitHub Actions CI for unit tests #55

Add GitHub Actions CI for unit tests

Add GitHub Actions CI for unit tests #55

Workflow file for this run

name: ANTsPyNet Unit Tests
on:
push:
pull_request:
env:
USE_SOURCE_BUILD: false # Set to 'false' to use PyPI version of ANTsPy
jobs:
test:
name: Test on Python ${{ matrix.python-version }}
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.11]
steps:
- name: Checkout ANTsPyNet
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install build tools
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential git
- name: Install ANTsPy (source or PyPI)
run: |
if [ "$USE_SOURCE_BUILD" = "true" ]; then
echo "🔧 Installing ANTsPy from GitHub source..."
git clone https://github.com/ANTsX/ANTsPy.git
pip install scikit-build-core pybind11 nanobind # 🔑 install build backend dependencies
pip install ./ANTsPy --no-build-isolation --no-deps
else
echo "📦 Installing ANTsPy from PyPI..."
pip install antspyx
fi
- name: Cache ANTsXNet model/data downloads
uses: actions/cache@v4
with:
path: ~/.keras/ANTsXNet
key: antsxnet-${{ runner.os }}-${{ hashFiles('**/download_all_data.py') }}
restore-keys: |
antsxnet-${{ runner.os }}-
- name: Install ANTsPyNet and dependencies
run: |
pip install -e .
sed -i '/antspyx==/d' requirements.txt
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Pre-download ANTsXNet models and data
run: |
python download_all_data.py --strict
- name: Run tests (individually via pytest)
run: |
pip install pytest pytest-xdist pytest-forked psutil
for f in tests/test_*.py; do
echo "🔍 Running $f"
python -c "import psutil; print('Memory before:', psutil.virtual_memory().used // (1024*1024), 'MB')"
pytest -v -s --forked "$f" || exit 1
python -c "import psutil; print('Memory after :', psutil.virtual_memory().used // (1024*1024), 'MB')"
done