Commit 42099f3
authored
Fix permission issue in forks for coverage comment (#148)
## Problem
When working with forks, the "Post Coverage Comment" fails
due to the following error:
Error: Resource not accessible by integration
## Diagnosis
When a Pull Request is opened from a fork (which is common in
open source), GitHub generates a `GITHUB_TOKEN` with read-only
permissions for the target repository. This is a security
measure to prevent malicious code in a fork from modifying
your repository or stealing secrets.
Even though you specified `permissions: pull-requests: write` in
your YAML, GitHub ignores this elevation request for forks.
Consequently, the action `marocchino/sticky-pull-request-comment`
fails because it cannot write to the PR.
## Solution
To fix this securely, the workflow must be split into two separate
workflows:
* The test workflow (the current `ci.yml`)
* The comment workflow (new)
The latter runs automatically *after* the test workflow finishes.
Because this runs in your repo's context (not the fork's), it
has write permissions and can download the artifact to post the comment.1 parent a69ae3e commit 42099f3
3 files changed
Lines changed: 49 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
165 | 169 | | |
166 | | - | |
167 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
168 | 175 | | |
169 | 176 | | |
170 | 177 | | |
| |||
228 | 235 | | |
229 | 236 | | |
230 | 237 | | |
231 | | - | |
| 238 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments