Feature/ci cd #7
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 > release tag > push tag > master branch | |
| - name: Determine CFD library version | |
| id: cfd-version | |
| shell: bash | |
| 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 }}" | |
| elif [[ "${{ github.event_name }}" == "release" ]]; then | |
| # Use the release tag | |
| echo "ref=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT | |
| echo "Using CFD library tag: ${{ github.event.release.tag_name }}" | |
| elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then | |
| # Push of a tag | |
| TAG=${GITHUB_REF#refs/tags/} | |
| echo "ref=$TAG" >> $GITHUB_OUTPUT | |
| echo "Using CFD library tag: $TAG" | |
| elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| # Manual trigger without input - use the current ref | |
| echo "ref=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| echo "Using CFD library ref matching current branch/tag: ${{ github.ref_name }}" | |
| else | |
| # For PR/push to branch, use master (cfd repo's default branch) | |
| echo "ref=master" >> $GITHUB_OUTPUT | |
| echo "Using CFD library branch: master" | |
| 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 | |
| # All other settings come from pyproject.toml [tool.cibuildwheel] | |
| CIBW_ENVIRONMENT_PASS_LINUX: CFD_ROOT | |
| CIBW_ENVIRONMENT_PASS_MACOS: CFD_ROOT | |
| CIBW_ENVIRONMENT_PASS_WINDOWS: CFD_ROOT | |
| 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/ |