From 181f512815feecd010b3471ca890f3ee394a613d Mon Sep 17 00:00:00 2001 From: PastaClaw Date: Tue, 12 May 2026 14:17:44 -0500 Subject: [PATCH] ci: tolerate book preview comment permission errors --- .github/workflows/book-preview.yml | 65 +++++++++++++++++------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/.github/workflows/book-preview.yml b/.github/workflows/book-preview.yml index 9542f4ae2e2..215e2777db6 100644 --- a/.github/workflows/book-preview.yml +++ b/.github/workflows/book-preview.yml @@ -9,6 +9,7 @@ on: permissions: contents: read + issues: write pull-requests: write concurrency: @@ -50,36 +51,44 @@ jobs: const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; const artifactUrl = `${repoUrl}/actions/runs/${runId}`; - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - }); - - const marker = ''; - const existing = comments.find(c => c.body.includes(marker)); - const body = [ - marker, - `📖 **Book Preview** built successfully.`, - ``, - `Download the preview from the [workflow artifacts](${artifactUrl}).`, - `To view locally: download the artifact, unzip, and open \`index.html\`.`, - ``, - `_Updated at ${new Date().toISOString()}_`, - ].join('\n'); - - if (existing) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: existing.id, - body, - }); - } else { - await github.rest.issues.createComment({ + try { + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, - body, }); + + const marker = ''; + const existing = comments.find(c => c.body.includes(marker)); + const body = [ + marker, + `📖 **Book Preview** built successfully.`, + ``, + `Download the preview from the [workflow artifacts](${artifactUrl}).`, + `To view locally: download the artifact, unzip, and open \`index.html\`.`, + ``, + `_Updated at ${new Date().toISOString()}_`, + ].join('\n'); + + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body, + }); + } + } catch (error) { + if (error?.status === 403 && String(error?.message ?? '').includes('Resource not accessible by integration')) { + core.warning('Skipping book preview PR comment because this workflow token cannot write comments for the event.'); + } else { + throw error; + } }