ci: run coverage as part of "build" job #2
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
| on: | ||
| workflow_call: | ||
| inputs: | ||
| os: | ||
| required: true | ||
| type: string | ||
| python-version: | ||
| required: true | ||
| type: string | ||
| python-architecture: | ||
| required: true | ||
| type: string | ||
| rust: | ||
| required: true | ||
| type: string | ||
| rust-target: | ||
| required: true | ||
| type: string | ||
| MSRV: | ||
| required: true | ||
| type: string | ||
| jobs: | ||
| build: | ||
| continue-on-error: ${{ endsWith(inputs.python-version, '-dev') || contains(fromJSON('["3.7", "3.8"]'), inputs.python-version) || contains(fromJSON('["beta", "nightly"]'), inputs.rust) }} | ||
| runs-on: ${{ inputs.os }} | ||
| if: ${{ !(startsWith(inputs.python-version, 'graalpy') && startsWith(inputs.os, 'windows')) }} | ||
| env: | ||
| # On windows 32 bit, we are running on an x64 host, so we need to specifically set the target | ||
| # NB we don't do this for *all* jobs because it breaks coverage of proc macros to have an | ||
| # explicit target set. | ||
| CARGO_BUILD_TARGET: ${{ (inputs.os == 'windows-latest' && inputs.python-architecture == 'x86' && inputs.rust-target) || '' }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| # For PRs, we need to run on the real PR head, not the resultant merge of the PR into the target branch. | ||
| # | ||
| # This is necessary for coverage reporting to make sense; we then get exactly the coverage change | ||
| # between the base branch and the real PR head. | ||
| # | ||
| # If it were run on the merge commit the problem is that the coverage potentially does not align | ||
| # with the commit diff, because the merge may affect line numbers. | ||
| ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} | ||
| - name: Set up Python ${{ inputs.python-version }} | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| architecture: ${{ inputs.python-architecture }} | ||
| check-latest: ${{ startsWith(inputs.python-version, 'pypy') }} # PyPy can have FFI changes within Python versions, which creates pain in CI | ||
| - name: Install nox | ||
| run: python -m pip install --upgrade pip && pip install nox | ||
| - if: inputs.python-version == 'graalpy24.1' | ||
| name: Install GraalPy virtualenv (only GraalPy 24.1) | ||
| run: python -m pip install 'git+https://github.com/oracle/graalpython#egg=graalpy_virtualenv_seeder&subdirectory=graalpy_virtualenv_seeder' | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@master | ||
| with: | ||
| toolchain: ${{ inputs.rust }} | ||
| targets: ${{ inputs.rust-target }} | ||
| # rust-src needed to correctly format errors, see #1865 | ||
| components: rust-src,llvm-tools-preview | ||
| - uses: Swatinem/rust-cache@v2 | ||
| with: | ||
| save-if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'CI-save-pr-cache') }} | ||
| - if: inputs.os == 'ubuntu-latest' | ||
| name: Prepare LD_LIBRARY_PATH (Ubuntu only) | ||
| run: echo LD_LIBRARY_PATH=${pythonLocation}/lib >> $GITHUB_ENV | ||
| - if: inputs.rust == inputs.MSRV | ||
| name: Prepare MSRV package versions | ||
| run: nox -s set-msrv-package-versions | ||
| - if: inputs.rust != 'stable' | ||
| name: Ignore changed error messages when using trybuild | ||
| run: echo "TRYBUILD=overwrite" >> "$GITHUB_ENV" | ||
| - if: inputs.rust == 'nightly' | ||
| name: Prepare to test on nightly rust | ||
| run: echo "MAYBE_NIGHTLY=nightly" >> "$GITHUB_ENV" | ||
| - if: inputs.python-version == '3.12' | ||
| name: Install cargo-llvm-cov | ||
| uses: taiki-e/install-action@cargo-llvm-cov | ||
| - if: inputs.python-version == '3.12' | ||
| name: Prepare coverage environment | ||
| run: | | ||
| cargo llvm-cov clean --workspace --profraw-only | ||
| nox -s set-coverage-env | ||
| - name: Build docs | ||
| run: nox -s docs | ||
| - name: Build (no features) | ||
| if: ${{ !startsWith(inputs.python-version, 'graalpy') }} | ||
| run: cargo build --lib --tests --no-default-features | ||
| # --no-default-features when used with `cargo build/test -p` doesn't seem to work! | ||
| - name: Build pyo3-build-config (no features) | ||
| run: | | ||
| cd pyo3-build-config | ||
| cargo build --no-default-features | ||
| # Run tests (except on PyPy, because no embedding API). | ||
| - if: ${{ !startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy') }} | ||
| name: Test (no features) | ||
| run: cargo test --no-default-features --lib --tests | ||
| # --no-default-features when used with `cargo build/test -p` doesn't seem to work! | ||
| - name: Test pyo3-build-config (no features) | ||
| run: | | ||
| cd pyo3-build-config | ||
| cargo test --no-default-features | ||
| - name: Build (all additive features) | ||
| if: ${{ !startsWith(inputs.python-version, 'graalpy') }} | ||
| run: cargo build --lib --tests --no-default-features --features "multiple-pymethods full $MAYBE_NIGHTLY" | ||
| - if: ${{ startsWith(inputs.python-version, 'pypy') }} | ||
| name: Build PyPy (abi3-py39) | ||
| run: cargo build --lib --tests --no-default-features --features "multiple-pymethods abi3-py39 full $MAYBE_NIGHTLY" | ||
| # Run tests (except on PyPy, because no embedding API). | ||
| - if: ${{ !startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy') }} | ||
| name: Test | ||
| run: cargo test --no-default-features --features "full $MAYBE_NIGHTLY" | ||
| # Repeat, with multiple-pymethods feature enabled (it's not entirely additive) | ||
| - if: ${{ !startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy') }} | ||
| name: Test | ||
| run: cargo test --no-default-features --features "multiple-pymethods full $MAYBE_NIGHTLY" | ||
| # Run tests again, but in abi3 mode | ||
| - if: ${{ !startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy') }} | ||
| name: Test (abi3) | ||
| run: cargo test --no-default-features --features "multiple-pymethods abi3 full $MAYBE_NIGHTLY" | ||
| # Run tests again, for abi3-py37 (the minimal Python version) | ||
| - if: ${{ (!startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy')) && (inputs.python-version != '3.7') }} | ||
| name: Test (abi3-py37) | ||
| run: cargo test --no-default-features --features "multiple-pymethods abi3-py37 full $MAYBE_NIGHTLY" | ||
| - name: Test proc-macro code | ||
| run: cargo test --manifest-path=pyo3-macros-backend/Cargo.toml | ||
| - name: Test build config | ||
| run: cargo test --manifest-path=pyo3-build-config/Cargo.toml | ||
| - name: Test python examples and tests | ||
| shell: bash | ||
| run: nox -s test-py | ||
| env: | ||
| CARGO_TARGET_DIR: ${{ github.workspace }}/target | ||
| - uses: dorny/paths-filter@v3 | ||
| if: ${{ inputs.rust == 'stable' && !startsWith(inputs.python-version, 'graalpy') }} | ||
| id: ffi-changes | ||
| with: | ||
| base: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }} | ||
| ref: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }} | ||
| filters: | | ||
| changed: | ||
| - 'pyo3-ffi/**' | ||
| - 'pyo3-ffi-check/**' | ||
| - '.github/workflows/ci.yml' | ||
| - '.github/workflows/build.yml' | ||
| - name: Run pyo3-ffi-check | ||
| # pypy 3.9 on windows is not PEP 3123 compliant, nor is graalpy | ||
| if: ${{ endsWith(inputs.python-version, '-dev') || (steps.ffi-changes.outputs.changed == 'true' && inputs.rust == 'stable' && !startsWith(inputs.python-version, 'graalpy') && !(inputs.python-version == 'pypy3.9' && contains(inputs.os, 'windows'))) }} | ||
| run: nox -s ffi-check | ||
| - name: Generate coverage report | ||
| if: inputs.python-version == '3.12' | ||
| run: cargo llvm-cov | ||
| --package=pyo3 | ||
| --package=pyo3-build-config | ||
| --package=pyo3-macros-backend | ||
| --package=pyo3-macros | ||
| --package=pyo3-ffi | ||
| report --codecov --output-path coverage.json | ||
| - name: Upload coverage report | ||
| uses: codecov/codecov-action@v4 | ||
| if: inputs.python-version == '3.12' | ||
| with: | ||
| file: coverage.json | ||
| name: ${{ inputs.os }}/${{ inputs.python-version }} | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| env: | ||
| CARGO_TERM_VERBOSE: true | ||
| RUST_BACKTRACE: 1 | ||
| RUSTFLAGS: "-D warnings" | ||
| RUSTDOCFLAGS: "-D warnings" | ||