diff --git a/.github/workflows/build-timing-report.yml b/.github/workflows/build-timing-report.yml index 0b01beaf36..586dcd1439 100644 --- a/.github/workflows/build-timing-report.yml +++ b/.github/workflows/build-timing-report.yml @@ -247,26 +247,47 @@ jobs: const body = fs.readFileSync(process.env.BUILD_TIMING_COMMENT, 'utf8'); const { owner, repo } = context.repo; const issue_number = Number('${{ steps.timing-context.outputs.pr-number }}'); - const comments = await github.paginate( - github.rest.issues.listComments, - { owner, repo, issue_number, per_page: 100 } - ); - const existing = comments.find(comment => - comment.user?.type === 'Bot' && comment.body?.includes(marker) - ); - if (existing) { - await github.rest.issues.updateComment({ - owner, - repo, - comment_id: existing.id, - body, - }); - } else { - await github.rest.issues.createComment({ - owner, - repo, - issue_number, - body, - }); + try { + const comments = await github.paginate( + github.rest.issues.listComments, + { owner, repo, issue_number, per_page: 100 } + ); + const existing = comments.find(comment => + comment.user?.type === 'Bot' && comment.body?.includes(marker) + ); + + if (existing) { + await github.rest.issues.updateComment({ + owner, + repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner, + repo, + issue_number, + body, + }); + } + } catch (error) { + // The rendered report is already attached to the job summary (see the + // previous step), so failing to post the PR comment must not fail this + // reporting job and surface as a red X on otherwise-green CI. + if (error.status === 403) { + core.warning( + 'Could not post the build timing PR comment: GITHUB_TOKEN is not ' + + 'permitted to write issue comments (HTTP 403 "Resource not accessible ' + + 'by integration"). For `workflow_run` jobs the token is capped at the ' + + 'repository default, so the `issues: write` permission declared in this ' + + 'workflow cannot take effect until write access is enabled under ' + + 'Settings → Actions → General → Workflow permissions ' + + '(or a token/app granting `issues: write` is provided). The report is ' + + 'still available in the job summary above.' + ); + } else { + core.warning(`Could not post the build timing PR comment: ${error.message}`); + } }