Merge pull request #281 from toruseo/dependabot/github_actions/codeco… #452
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: Measure coverage | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| measure-coverage: | |
| runs-on: ubuntu-latest | |
| if: | | |
| (github.event_name == 'push' && github.repository == 'toruseo/UXsim') || | |
| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.repository == 'toruseo/UXsim') | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python 3.13 | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.13" | |
| - name: Install lcov | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y lcov | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install scikit-build-core nanobind cmake ninja | |
| - name: Install uxsim and dependencies | |
| run: | | |
| pip install -e '.[dev,advanced]' | |
| - name: Install pytest other dependencies | |
| run: | | |
| pip install osmnx requests pytest-rerunfailures | |
| - name: Run Python tests with coverage | |
| run: pytest -n 4 tests/test_verification_straight_road.py tests/test_verification_route_choice.py tests/test_verification_node.py tests/test_verification_exceptional.py tests/test_verification_sioux_falls.py tests/test_verification_multilane.py tests/test_verification_taxi.py tests/test_verification_dta_solvers.py tests/test_other_functions.py tests/test_optional_functions_python313.py --durations=0 -v --cov=uxsim --cov-report=xml --cov-config=.github/.coveragerc | |
| - name: Run C++ mode tests with coverage | |
| run: pytest tests/test_cpp_mode.py tests/test_cpp_build.py --reruns 5 -v --cov=uxsim --cov-report=xml --cov-append --cov-config=.github/.coveragerc | |
| - name: Build C++ with coverage instrumentation | |
| run: | | |
| cmake -B build_cov -DCOVERAGE=ON -Dnanobind_DIR=$(python3 -c 'import nanobind; print(nanobind.cmake_dir())') | |
| cmake --build build_cov | |
| - name: Run tests for C++ coverage | |
| run: | | |
| UXSIM_CPP_DIR=$(python3 -c "import importlib.util, os; spec=importlib.util.find_spec('uxsim.uxsim_cpp'); print(os.path.dirname(spec.origin) if spec and spec.origin else 'uxsim')") | |
| cp build_cov/uxsim_cpp*.so "$UXSIM_CPP_DIR/" 2>/dev/null || cp build_cov/*.so "$UXSIM_CPP_DIR/" 2>/dev/null || true | |
| python3 -m pytest tests/test_cpp_build.py tests/test_cpp_mode.py --reruns 5 -q | |
| - name: Collect C++ coverage | |
| run: | | |
| lcov --capture --directory build_cov --output-file cpp_coverage.info --ignore-errors source,gcov,empty,mismatch | |
| lcov --remove cpp_coverage.info '/usr/*' '*/nanobind/*' '*/python*' --output-file cpp_coverage_filtered.info --ignore-errors unused,empty | |
| lcov --list cpp_coverage_filtered.info || true | |
| - name: Upload coverage reports to Codecov | |
| uses: codecov/codecov-action@v6.0.0 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage.xml,./cpp_coverage_filtered.info | |
| name: codecov-umbrella | |
| fail_ci_if_error: true | |
| verbose: true |