diff --git a/.github/workflows/preview-docs.yml b/.github/workflows/preview-docs.yml index e326885d7..87844777e 100644 --- a/.github/workflows/preview-docs.yml +++ b/.github/workflows/preview-docs.yml @@ -143,8 +143,35 @@ jobs: echo ":herb: **Preview your docs:** <${{ steps.generate-docs.outputs.preview_url }}>" > comment.md - name: Post PR comment - uses: thollander/actions-comment-pull-request@v2.4.3 + uses: actions/github-script@v7 with: - filePath: comment.md - comment_tag: preview-docs - mode: upsert + script: | + const fs = require('fs'); + const commentBody = fs.readFileSync('comment.md', 'utf8') + '\n'; + const marker = ''; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number + }); + + const existingComment = comments.find(comment => comment.body.includes(marker)); + + if (existingComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existingComment.id, + body: commentBody + }); + console.log(`Updated existing comment ${existingComment.id}`); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: commentBody + }); + console.log('Created new comment'); + }