Feature/ci cd #14
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] | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: [main, master] | |
| release: | |
| types: [published] | |
| # Allow manual triggering or remote triggering via GitHub CLI/API | |
| # (used by cfd repo's version-release.yml via: gh workflow run build-wheels.yml) | |
| workflow_dispatch: | |
| inputs: | |
| cfd_ref: | |
| description: "CFD library ref (tag/branch/commit). Leave empty to auto-detect." | |
| required: false | |
| default: "" | |
| jobs: | |
| build_wheels: | |
| name: Build wheels on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # Determine which version of CFD library to use | |
| # Priority: workflow_dispatch input > latest cfd release tag | |
| # This ensures we always build against stable, tested cfd releases | |
| - name: Determine CFD library version | |
| id: cfd-version | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| # Check for workflow_dispatch input first | |
| if [[ -n "${{ github.event.inputs.cfd_ref }}" ]]; then | |
| echo "ref=${{ github.event.inputs.cfd_ref }}" >> $GITHUB_OUTPUT | |
| echo "Using CFD library ref from input: ${{ github.event.inputs.cfd_ref }}" | |
| else | |
| # Fetch the latest release tag from cfd repo | |
| LATEST_TAG=$(gh api repos/${{ github.repository_owner }}/cfd/releases/latest --jq '.tag_name' 2>/dev/null || echo "") | |
| if [[ -n "$LATEST_TAG" ]]; then | |
| echo "ref=$LATEST_TAG" >> $GITHUB_OUTPUT | |
| echo "Using latest CFD release: $LATEST_TAG" | |
| else | |
| # Fallback to master if no releases exist | |
| echo "ref=master" >> $GITHUB_OUTPUT | |
| echo "No CFD releases found, falling back to master branch" | |
| fi | |
| fi | |
| # Checkout the CFD C library into workspace subdirectory | |
| - name: Checkout CFD C library | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.repository_owner }}/cfd | |
| path: cfd | |
| ref: ${{ steps.cfd-version.outputs.ref }} | |
| fetch-depth: 0 | |
| # Build wheels using cibuildwheel | |
| # Configuration is in pyproject.toml - only override CFD_ROOT for CI | |
| # (pyproject.toml uses ../cfd for local dev, CI uses ./cfd) | |
| - name: Build wheels | |
| uses: pypa/cibuildwheel@v2.21.3 | |
| env: | |
| # Override CFD_ROOT to point to the cfd subdirectory in CI workspace | |
| # CIBW_ENVIRONMENT overrides pyproject.toml environment settings | |
| CIBW_ENVIRONMENT: "CMAKE_BUILD_TYPE=Release CFD_STATIC_LINK=ON CFD_USE_STABLE_ABI=ON CFD_ROOT=./cfd" | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.os }} | |
| path: ./wheelhouse/*.whl | |
| build_sdist: | |
| name: Build source distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Build sdist | |
| run: pipx run build --sdist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: sdist | |
| path: dist/*.tar.gz | |
| test_package: | |
| name: Test package installation | |
| needs: [build_wheels] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.os }} | |
| path: wheelhouse | |
| - name: Install wheel and test dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install --find-links wheelhouse cfd-python | |
| python -m pip install pytest numpy | |
| - name: Run full test suite | |
| run: pytest tests/ -v | |
| upload_pypi: | |
| name: Upload to PyPI | |
| needs: [build_wheels, build_sdist, test_package] | |
| runs-on: ubuntu-latest | |
| # Publish on: release event, tag push (v*), or workflow_dispatch on a tag | |
| if: | | |
| github.event_name == 'release' || | |
| (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || | |
| (github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')) | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/cfd-python | |
| permissions: | |
| id-token: write | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: wheels-* | |
| path: dist | |
| merge-multiple: true | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: sdist | |
| path: dist | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist/ | |
| upload_test_pypi: | |
| name: Upload to Test PyPI | |
| needs: [build_wheels, build_sdist, test_package] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | |
| environment: | |
| name: testpypi | |
| url: https://test.pypi.org/p/cfd-python | |
| permissions: | |
| id-token: write | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: wheels-* | |
| path: dist | |
| merge-multiple: true | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: sdist | |
| path: dist | |
| - name: Publish to Test PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| packages-dir: dist/ |