@@ -92,6 +92,16 @@ is done in 2 steps:
9292 untrusted code
93932 . From a trusted workflow, publish the comment on the PR
9494
95+ The write permissions in the ` CI ` workflow below are intentional. They are
96+ used when the PR is trusted enough, usually because it comes from the same
97+ repository, for this workflow to publish or update the comment directly.
98+ When that happens, the second workflow can be skipped.
99+ For ` pull_request ` runs coming from forks, which are untrusted by default,
100+ GitHub downgrades requested write permissions to read-only unless the
101+ repository is explicitly configured to send write tokens to workflows from
102+ pull requests. In other words, these settings do not grant write access to
103+ untrusted code.
104+
95105``` yaml
96106# .github/workflows/ci.yml
97107name : CI
@@ -107,12 +117,11 @@ jobs:
107117 name : Run tests & display coverage
108118 runs-on : ubuntu-latest
109119 permissions :
110- # Gives the action the necessary permissions for publishing new
111- # comments in pull requests .
120+ # Allows the action to publish new comments directly on trusted PRs.
121+ # Forked pull_request runs are downgraded to read-only by GitHub .
112122 pull-requests : write
113- # Gives the action the necessary permissions for pushing data to the
114- # python-coverage-comment-action branch, and for editing existing
115- # comments (to avoid publishing multiple comments in the same PR)
123+ # Allows updating the python-coverage-comment-action branch and editing
124+ # existing comments when direct publication is allowed.
116125 contents : write
117126 steps :
118127 - uses : actions/checkout@v4
0 commit comments