diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0bce9ac66..c1d23bbac 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,6 +15,9 @@ env: jobs: lint-and-test: + permissions: + contents: read + code-quality: write strategy: fail-fast: false matrix: @@ -24,6 +27,9 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # Test the PR head rather than the merge commit so coverage lines map onto the PR diff + ref: ${{ github.event.pull_request.head.sha || github.sha }} - name: Setup Python with UV uses: $/.github/actions/setup-python-uv @@ -37,7 +43,16 @@ jobs: RUFF_OUTPUT_FORMAT: github - name: Run tests with coverage - run: uv run pytest --cov=src/bcbench --cov=packages/bcbench-core/src/bcbench_core --cov-report=term-missing + run: uv run pytest --cov --cov-report=term-missing --cov-report=xml + + - name: Upload coverage to GitHub Code Quality + # main pushes set the baseline and same-repo PRs are compared to it; other runs (forks, dispatch) cannot upload + if: matrix.os == 'ubuntu-latest' && ((github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)) + uses: actions/upload-code-coverage@2b21a77928be8d5168c2b9581a67f2adbebacc52 # v1.4.4 + with: + file: coverage.xml + language: Python + label: code-coverage/pytest e2e: strategy: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 98ea84f11..44bdfc792 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,7 +62,7 @@ uv run bcbench --help uv run bcbench run copilot microsoft__BCApps-5633 --category bug-fix --repo-path /path/to/BCApps # Run tests (bcbench and bcbench-core) -uv run pytest --cov=src/bcbench --cov=packages/bcbench-core/src/bcbench_core --cov-report=term-missing +uv run pytest --cov --cov-report=term-missing # Lint and format uv run pre-commit run --all-files diff --git a/pyproject.toml b/pyproject.toml index 6331ce995..343fb1351 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,11 @@ markers = [ ] collect_imported_tests = false +[tool.coverage.run] +# Repo-relative paths in coverage.xml so GitHub Code Quality can map them onto PR files +relative_files = true +include = ["src/bcbench/*", "packages/bcbench-core/src/bcbench_core/*"] + [tool.ruff] # The app inherits the bcbench-core lint baseline; tables redefined below replace the inherited ones. extend = "packages/bcbench-core/pyproject.toml"