From dd55ff73fe7091e4e04775a22bc8e6b78ba8842e Mon Sep 17 00:00:00 2001 From: "Haoran Sun (Business Central)" Date: Fri, 2 Oct 2026 15:17:31 +0200 Subject: [PATCH 1/2] Upload test coverage to GitHub Code Quality Code Quality is enabled for the repository, so CI uploads the pytest coverage report and github-code-quality[bot] comments on pull requests. - Coverage paths are repo-relative (relative_files + include), so files with the same name in bcbench and bcbench_core map unambiguously - CI checks out the PR head instead of the merge commit, as the upload requires, and only the Ubuntu run uploads to keep one report per label Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3fa47b3c-f5d6-4c36-9be3-c4fdf2bebe47 --- .github/workflows/CI.yml | 17 ++++++++++++++++- CONTRIBUTING.md | 2 +- pyproject.toml | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0bce9ac66..dd1c46609 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 + # One upload per label: the Ubuntu run reports; fork PRs cannot get code-quality: write + if: matrix.os == 'ubuntu-latest' && (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" From be159e5eb4acd8136979e5139b492c430c66eb56 Mon Sep 17 00:00:00 2001 From: "Haoran Sun (Business Central)" Date: Fri, 2 Oct 2026 19:33:06 +0200 Subject: [PATCH 2/2] Upload coverage only from main pushes and same-repo pull requests The coverage API rejects uploads from non-default branches without a pull request number, so manually dispatched runs on feature branches skip it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3fa47b3c-f5d6-4c36-9be3-c4fdf2bebe47 --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index dd1c46609..c1d23bbac 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -46,8 +46,8 @@ jobs: run: uv run pytest --cov --cov-report=term-missing --cov-report=xml - name: Upload coverage to GitHub Code Quality - # One upload per label: the Ubuntu run reports; fork PRs cannot get code-quality: write - if: matrix.os == 'ubuntu-latest' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) + # 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