diff options
| author | saurabh <saurabhrai1717@gmail.com> | 2025-12-04 20:55:21 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-04 10:25:21 -0500 |
| commit | 26b0e2bb92caf2d16cabe455792350f20d6f42ca (patch) | |
| tree | 90057eca6a3fd66d398222adedf0ca141ed757c3 /.github/workflows/coverage_comment.yml | |
| parent | 0ca3a0661173b02e2cbb0183d8543e790e7e4a55 (diff) | |
Fixed #36620 -- Fixed workflow to summarize coverage in PRs.
Follow-up to a89183e63844a937aacd3ddb73c4952ef869d2cc, which was
reverted in e4c4a178aa642f8493b7ae2c0ad58527af51f67e because a change
to the workflow trigger resulted in the PR branch not being checked out.
We used this opportunity to reimplement the coverage tracing and coverage
commenting in a two-workflow pattern with more granular permissions.
To reduce duplicative workflows, we removed the existing python test workflow
on PRs, at least until we run more distinct configurations on GitHub actions. The
run with coverage tracing enabled is sufficient for now. The existing workflow still
runs on pushes to main. We can revisit when adding more test configurations.
Diffstat (limited to '.github/workflows/coverage_comment.yml')
| -rw-r--r-- | .github/workflows/coverage_comment.yml | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/.github/workflows/coverage_comment.yml b/.github/workflows/coverage_comment.yml new file mode 100644 index 0000000000..d63e6f4a75 --- /dev/null +++ b/.github/workflows/coverage_comment.yml @@ -0,0 +1,72 @@ +name: Coverage Comment + +on: + workflow_run: + workflows: ["Coverage Tests"] + types: + - completed + +permissions: + contents: read + pull-requests: write + +jobs: + comment: + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' && + github.repository == 'django/django' && + github.event.workflow_run.pull_requests[0] != null + name: Post Coverage Comment + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - name: Download diff coverage report + uses: actions/download-artifact@v4 + with: + name: diff-coverage-report-${{ github.event.workflow_run.pull_requests[0].number }} + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Post/update PR comment + env: + PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} + uses: actions/github-script@v8 + with: + script: | + const fs = require('fs'); + const reportPath = 'diff-cover-report.md'; + let body = 'No coverage data available.'; + if (fs.existsSync(reportPath)) { + body = fs.readFileSync(reportPath, 'utf8'); + } + const commentBody = '### 📊 Coverage Report for Changed Files\n\n```\n' + body + '\n```\n\n**Note:** Missing lines are warnings only. Some lines may not be covered by SQLite tests as they are database-specific.\n\nFor more information about code coverage on pull requests, see the [contributing documentation](https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/#code-coverage-on-pull-requests).'; + + const prNumber = parseInt(process.env.PR_NUMBER); + if (isNaN(prNumber)) { + core.setFailed('PR number is not available or invalid.'); + return; + } + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + + for (const c of comments) { + if ((c.body || '').includes('📊 Coverage Report for Changed Files')) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: c.id, + }); + } + } + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody, + }); |
