Feature/ci cd #40
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: Build and Test Wheels | |
| on: | |
| push: | |
| branches: [main, master, feature/ci-cd] | |
| pull_request: | |
| branches: [main, master] | |
| workflow_dispatch: | |
| jobs: | |
| build_wheel: | |
| name: Build wheel on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # Checkout CFD C library | |
| - name: Checkout CFD C library | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.repository_owner }}/cfd | |
| path: cfd | |
| fetch-depth: 0 | |
| - name: Set up Python 3.8 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.8" | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build scikit-build-core setuptools-scm | |
| - name: Build CFD library | |
| run: | | |
| cmake -S cfd -B cfd/build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON | |
| cmake --build cfd/build --config Release | |
| echo "=== CFD library built ===" | |
| ls -la cfd/build/lib/ | |
| - name: Build wheel | |
| env: | |
| CFD_ROOT: ${{ github.workspace }}/cfd | |
| CFD_STATIC_LINK: "ON" | |
| run: | | |
| echo "CFD_ROOT=$CFD_ROOT" | |
| echo "Checking CFD library location..." | |
| ls -la $CFD_ROOT/build/lib/ || echo "Library dir not found" | |
| # Use pip wheel to build, which respects env vars better | |
| pip wheel . --no-deps --wheel-dir dist/ | |
| echo "=== Wheel built ===" | |
| ls -la dist/ | |
| - name: Inspect wheel contents | |
| run: | | |
| for wheel in dist/*.whl; do | |
| echo "=== Contents of $wheel ===" | |
| python -m zipfile -l "$wheel" | |
| done | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheel-${{ matrix.os }} | |
| path: dist/*.whl | |
| test_wheel: | |
| name: Test wheel on ${{ matrix.os }} with Python ${{ matrix.python }} | |
| needs: [build_wheel] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| python: ["3.8", "3.12"] | |
| steps: | |
| - name: Set up Python ${{ matrix.python }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "${{ matrix.python }}" | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: wheel-${{ matrix.os }} | |
| path: dist | |
| - name: Install wheel | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install dist/*.whl | |
| pip install pytest numpy | |
| - name: Test import | |
| run: | | |
| # Run from temp dir to avoid importing from source | |
| cd /tmp | |
| python -c " | |
| import cfd_python | |
| print('Package loaded:', cfd_python.__file__) | |
| print('Version:', cfd_python.__version__) | |
| print('Has list_solvers:', hasattr(cfd_python, 'list_solvers')) | |
| if hasattr(cfd_python, 'list_solvers'): | |
| print('Solvers:', cfd_python.list_solvers()) | |
| " | |
| # Checkout only tests directory for running tests | |
| - uses: actions/checkout@v4 | |
| with: | |
| sparse-checkout: tests | |
| sparse-checkout-cone-mode: false | |
| - name: Run tests | |
| run: | | |
| # Run from a different directory to use installed package | |
| cd /tmp | |
| pytest $GITHUB_WORKSPACE/tests/ -v |