Skip to content

Post PR coverage comments from a workflow_run workflow - #14

Merged
tescalada merged 1 commit into
mainfrom
ci/fork-pr-coverage-comments
Jul 22, 2026
Merged

tescalada merged 1 commit into
mainfrom
ci/fork-pr-coverage-comments

Conversation

@tescalada

Copy link
Copy Markdown
Contributor

Fork PRs run CI with a read-only GITHUB_TOKEN — GitHub caps the token for pull_request events from forks regardless of the permissions declared in the workflow. The coverage-comment steps in the test job therefore failed with Resource not accessible by integration on every fork PR, failing the job even when the suite passed (see #12, where all 1277 tests pass but the check is red).

This splits coverage reporting in two, following the same pattern as publish-pr.yml:

  • The test job uploads pytest-coverage.txt, junit.xml, and diff-cover-report.md as a coverage-report artifact instead of commenting. The upload still runs on a red suite, so the report explaining a failure is preserved; files the failure suppressed are simply absent. The job's now-ineffective pull-requests: write grant is dropped.
  • A new coverage-comment workflow triggers on CI completion and runs in the base repo's context with pull-requests: write. It resolves the PR number from the API by head SHA — never from anything the PR controls — downloads the report artifact, and posts the two sticky comments (issue-number / number inputs, which both actions support for workflow_run triggers). It never checks out or executes fork code. Each comment step is gated on its report file existing.

The comment now appears on fork and same-repo PRs alike, through a single code path. Note workflow_run workflows execute from the default branch, so the new workflow takes effect once this merges; open PRs then need a re-run to pick up the artifact-upload side.

Fork PRs run CI with a read-only GITHUB_TOKEN: GitHub caps the token for
pull_request events from forks regardless of the permissions declared in
the workflow, so the comment steps in the test job failed the job on
every fork PR while the suite itself passed.

The test job now uploads pytest-coverage.txt, junit.xml, and
diff-cover-report.md as a coverage-report artifact instead of commenting.
The new coverage-comment workflow triggers on CI completion, runs in the
base repo's context with pull-requests: write, resolves the PR number
from the API by head SHA, and posts the two sticky comments. It follows
the same pattern as publish-pr.yml: it downloads report data only and
never checks out or executes fork code. Each comment step is gated on
its report file existing, since a failed run uploads only the files it
produced.
@tescalada
tescalada merged commit 7777f29 into main Jul 22, 2026
5 checks passed
@tescalada
tescalada deleted the ci/fork-pr-coverage-comments branch July 22, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant