Test, build, and deploy Python package #6
Workflow file for this run
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: "Test, build, and deploy Python package" | |
| on: | |
| pull_request: | |
| branches: [main] | |
| push: | |
| branches: [main] | |
| tags: | |
| - v* | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| name: Test package | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| environment: [py312, py314] | |
| platform: [ubuntu-latest] | |
| runs-on: ${{ matrix.platform }} | |
| steps: | |
| # checkout@v5.0.0 | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 | |
| # setup-pixi@v0.9.2 | |
| - uses: prefix-dev/setup-pixi@28eb668aafebd9dede9d97c4ba1cd9989a4d0004 | |
| with: | |
| cache: true | |
| cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }} | |
| environments: ${{ matrix.environment }} | |
| activate-environment: true | |
| - name: configure | |
| run: mkdir -p build && cd build && cmake .. -GNinja -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_TESTING=ON | |
| - name: build | |
| run: cd build && ninja | |
| - name: test C++ | |
| run: cd build && ctest --output-on-failure | |
| - name: Install Python package | |
| run: pip install . -v | |
| - name: Test with Python ${{ matrix.python-version }} | |
| run: pytest | |
| release-build: | |
| name: Build and release package | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| environment: [py311, py312, py313, py314] | |
| platform: [ubuntu-latest, macos-latest, windows-latest] | |
| runs-on: ${{ matrix.platform }} | |
| needs: | |
| - test | |
| permissions: | |
| # IMPORTANT: this permission is mandatory for trusted publishing | |
| id-token: write | |
| # Dedicated environments with protections for publishing are strongly recommended. | |
| environment: | |
| name: pypi | |
| # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: | |
| url: https://pypi.org/p/PerceMon | |
| if: "startsWith(github.ref, 'refs/tags/')" | |
| steps: | |
| # checkout@v5.0.0 | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 | |
| # setup-pixi@v0.9.2 | |
| - uses: prefix-dev/setup-pixi@28eb668aafebd9dede9d97c4ba1cd9989a4d0004 | |
| with: | |
| cache: true | |
| cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }} | |
| environments: ${{ matrix.environment }} | |
| activate-environment: true | |
| - name: Build wheels and sdist | |
| run: uv build | |
| - name: Upload wheels and sdist | |
| # upload-artifact@v5.0.0 | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 | |
| with: | |
| name: release-dists | |
| path: dist/ | |
| - name: Publish release distributions to PyPI | |
| run: uv publish |