Skip to content

Commit 92a3700

Browse files
authored
Fix check_release_notes 403 by restoring pull-requests: write and making the comment non-fatal (#20198)
check_release_notes runs via pull_request_target, so GitHub executes the workflow from the default branch (main). Creating the informational PR comment requires pull-requests: write, but #20081 reduced the token to read, turning the check red with HTTP 403 on any PR that had to create (not update) the comment - e.g. Maestro/darc PR #20133. Restore pull-requests: write so the comment posts, and guard the comment step with continue-on-error plus try/catch so posting can never fail the release-notes verdict. Supersedes #20200.
1 parent d89529c commit 92a3700

1 file changed

Lines changed: 35 additions & 22 deletions

File tree

‎.github/workflows/check_release_notes.yml‎

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
permissions:
99
contents: read
1010
issues: write
11-
pull-requests: read
11+
pull-requests: write
1212
concurrency:
1313
group: release-notes-${{ github.event.pull_request.number }}
1414
cancel-in-progress: true
@@ -17,7 +17,7 @@ jobs:
1717
permissions:
1818
contents: read
1919
issues: write
20-
pull-requests: read
20+
pull-requests: write
2121
env:
2222
GH_TOKEN: ${{ github.token }}
2323
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
@@ -305,38 +305,51 @@ jobs:
305305
exit 1
306306
fi
307307
# Keep one bot comment current without evaluating pull request content as JavaScript.
308+
# Posting the informational comment is best-effort and must never fail the check:
309+
# this job runs via pull_request_target, and the Actions GITHUB_TOKEN is not always
310+
# permitted to create a new issue comment (the comment API can return HTTP 403
311+
# "Resource not accessible by integration"), even though release-notes validation
312+
# above has already succeeded.
308313
- name: Create or update comment
309314
if: ${{ (success() || failure()) && steps.release_notes_changes.outputs.release-notes-check-message != '' }}
315+
continue-on-error: true
310316
uses: actions/github-script@v9
311317
env:
312318
COMMENT_BODY: ${{ steps.release_notes_changes.outputs.release-notes-check-message }}
313319
with:
314320
github-token: ${{ github.token }}
315321
script: |
316322
const marker = '<!-- DO_NOT_REMOVE: release_notes_check -->';
317-
const comments = await github.paginate(github.rest.issues.listComments, {
318-
owner: context.repo.owner,
319-
repo: context.repo.repo,
320-
issue_number: context.issue.number,
321-
per_page: 100
322-
});
323-
const existing = comments.find(comment =>
324-
comment.user?.login === 'github-actions[bot]' && comment.body?.includes(marker));
325-
326-
if (existing) {
327-
const comment = await github.rest.issues.updateComment({
323+
try {
324+
const comments = await github.paginate(github.rest.issues.listComments, {
325+
owner: context.repo.owner,
326+
repo: context.repo.repo,
327+
issue_number: context.issue.number,
328+
per_page: 100
329+
});
330+
const existing = comments.find(comment =>
331+
comment.user?.login === 'github-actions[bot]' && comment.body?.includes(marker));
332+
333+
if (existing) {
334+
const comment = await github.rest.issues.updateComment({
335+
owner: context.repo.owner,
336+
repo: context.repo.repo,
337+
comment_id: existing.id,
338+
body: process.env.COMMENT_BODY
339+
});
340+
return comment.data.id;
341+
}
342+
343+
const comment = await github.rest.issues.createComment({
344+
issue_number: context.issue.number,
328345
owner: context.repo.owner,
329346
repo: context.repo.repo,
330-
comment_id: existing.id,
331347
body: process.env.COMMENT_BODY
332348
});
333349
return comment.data.id;
350+
} catch (error) {
351+
// The comment is informational only. The release-notes verdict is enforced by the
352+
// "Check for release notes changes" step, so never fail the job if posting fails
353+
// (e.g. a read-only token on some pull requests).
354+
core.warning(`Unable to post release-notes comment: ${error.message}`);
334355
}
335-
336-
const comment = await github.rest.issues.createComment({
337-
issue_number: context.issue.number,
338-
owner: context.repo.owner,
339-
repo: context.repo.repo,
340-
body: process.env.COMMENT_BODY
341-
});
342-
return comment.data.id;

0 commit comments

Comments
 (0)