CI: Need to conserve runner disk space #80
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ANTsPyNet Unit Tests | ||
| on: | ||
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| branches: [master] | ||
| workflow_dispatch: | ||
| env: | ||
| USE_ANTSPY_SOURCE_BUILD: false | ||
| ANTSXNET_CACHE_DIR: ${{ runner.temp }}/ANTsXNet | ||
| jobs: | ||
| ########################################### | ||
| # Job 1 — Build or Restore ANTsXNet Data Cache | ||
| ########################################### | ||
| prepare-data: | ||
| name: Prepare ANTsXNet Data | ||
| runs-on: ubuntu-22.04 | ||
| outputs: | ||
| cache-key: ${{ steps.compute-key.outputs.cache-key }} | ||
| cache-hit: ${{ steps.restore-cache.outputs.cache-hit }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
| - name: Compute cache key | ||
| id: compute-key | ||
| run: | | ||
| KEY="antsxnet-${{ hashFiles( | ||
| 'antspynet/utilities/get_antsxnet_data.py', | ||
| 'antspynet/utilities/get_pretrained_network.py' | ||
| ) }}" | ||
| echo "cache-key=$KEY" >> "$GITHUB_OUTPUT" | ||
| - name: Try restoring ANTsXNet data cache | ||
| id: restore-cache | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| key: ${{ steps.compute-key.outputs.cache-key }} | ||
| path: ${{ env.ANTSXNET_CACHE_DIR }} | ||
| - name: Cache hit — skip download | ||
| if: steps.restore-cache.outputs.cache-hit == 'true' | ||
| run: echo "Cache HIT — will use cached ANTsXNet data." | ||
| - name: Set up Python 3.11 | ||
| if: steps.restore-cache.outputs.cache-hit != 'true' | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
| - name: Install ANTsPy for data download | ||
| if: steps.restore-cache.outputs.cache-hit != 'true' | ||
| run: | | ||
| if [ "$USE_ANTSPY_SOURCE_BUILD" = "true" ]; then | ||
| echo "Installing ANTsPy from source..." | ||
| git clone https://github.com/ANTsX/ANTsPy.git | ||
| pip install scikit-build-core pybind11 nanobind | ||
| pip install ./ANTsPy --no-build-isolation --no-deps | ||
| else | ||
| echo "Installing ANTsPy from PyPI..." | ||
| pip install antspyx | ||
| fi | ||
| - name: Download ANTsXNet models (cache miss) | ||
| if: steps.restore-cache.outputs.cache-hit != 'true' | ||
| run: | | ||
| pip install -e . | ||
| python download_all_data.py --strict --cache-dir ${{ env.ANTSXNET_CACHE_DIR }} | ||
| - name: Save newly downloaded ANTsXNet data to cache | ||
| if: steps.restore-cache.outputs.cache-hit != 'true' | ||
| uses: actions/cache/save@v4 | ||
| with: | ||
| key: ${{ steps.compute-key.outputs.cache-key }} | ||
| path: ${{ env.ANTSXNET_CACHE_DIR }} | ||
| ########################################### | ||
| # Job 2 — Test Matrix | ||
| ########################################### | ||
| test: | ||
| name: Test on Python ${{ matrix.python-version }} | ||
| runs-on: ubuntu-22.04 | ||
| needs: prepare-data | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ["3.11", "3.12", "3.13"] | ||
| steps: | ||
| - name: Checkout repository | ||
| 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 | ||
| run: | | ||
| if [ "$USE_ANTSPY_SOURCE_BUILD" = "true" ]; then | ||
| echo "Installing ANTsPy from source..." | ||
| git clone https://github.com/ANTsX/ANTsPy.git | ||
| pip install scikit-build-core pybind11 nanobind | ||
| pip install ./ANTsPy --no-build-isolation --no-deps | ||
| else | ||
| echo "Installing ANTsPy from PyPI..." | ||
| pip install antspyx | ||
| fi | ||
| - name: Restore ANTsXNet model cache for tests | ||
| uses: actions/cache/restore@v4 | ||
| with: | ||
| key: ${{ needs.prepare-data.outputs.cache-key }} | ||
| path: ~/.keras/ANTsXNet | ||
| - name: Install ANTsPyNet | ||
| run: | | ||
| pip install -e . | ||
| - 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 | ||