diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 403152bab..7831d169c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -75,6 +75,14 @@ jobs: DB_PASSWORD: debug_toolbar DB_HOST: 127.0.0.1 DB_PORT: 3306 + COVERAGE_FILE: ".coverage.mysql.${{ matrix.python-version }}" + + - name: Store coverage file + uses: actions/upload-artifact@v4 + with: + name: coverage-mysql-${{ matrix.python-version }} + path: .coverage.mysql.${{ matrix.python-version }}* + include-hidden-files: true postgres: @@ -169,6 +177,14 @@ jobs: DB_HOST: localhost DB_PORT: 5432 DJANGO_SELENIUM_TESTS: ${{ matrix.env.DJANGO_SELENIUM_TESTS }} + COVERAGE_FILE: ".coverage.${{ matrix.database }}.${{ matrix.python-version }}" + + - name: Store coverage file + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ matrix.database }}-${{ matrix.python-version }} + path: .coverage.${{ matrix.database }}.${{ matrix.python-version }}* + include-hidden-files: true sqlite: runs-on: ubuntu-latest @@ -214,6 +230,14 @@ jobs: env: DB_BACKEND: sqlite3 DB_NAME: ":memory:" + COVERAGE_FILE: ".coverage.sqlite.${{ matrix.python-version }}" + + - name: Store coverage file + uses: actions/upload-artifact@v4 + with: + name: coverage-sqlite-${{ matrix.python-version }} + path: .coverage.sqlite.${{ matrix.python-version }}* + include-hidden-files: true lint: runs-on: ubuntu-latest @@ -252,3 +276,38 @@ jobs: - name: Test with tox run: tox -e docs,packaging + + coverage: + name: Coverage + runs-on: ubuntu-latest + needs: + - mysql + - postgres + - sqlite + permissions: + pull-requests: write + contents: write + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - uses: actions/download-artifact@v4 + id: download + with: + pattern: coverage-* + merge-multiple: true + + - name: Coverage comment + id: coverage_comment + uses: py-cov-action/python-coverage-comment-action@6494290850a5098c2836298dad8f11082b4ceaa9 # v3 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MERGE_COVERAGE_FILES: true + + - name: Store Pull Request comment to be posted + uses: actions/upload-artifact@v4 + if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' + with: + name: python-coverage-comment-action + path: python-coverage-comment-action.txt diff --git a/docs/changes.rst b/docs/changes.rst index 6e8cdcc8a..532404dab 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -6,6 +6,7 @@ Pending * Deprecated ``RedirectsPanel`` in favor of ``HistoryPanel`` for viewing toolbar data from redirected requests. +* Fixed support for generating code coverage comments in PRs. 6.1.0 (2025-10-30) ------------------ diff --git a/pyproject.toml b/pyproject.toml index 8b6e4b26d..527aa79cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,6 +99,7 @@ skip_empty = true [tool.coverage.run] branch = true parallel = true +relative_files = true source = [ "debug_toolbar", ] diff --git a/tox.ini b/tox.ini index 39f2adc9e..37887e952 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,7 @@ deps = passenv= CI COVERAGE_ARGS + COVERAGE_FILE DB_BACKEND DB_NAME DB_USER