From 7317183dfba78fe42db75534cc7f4569a71ec20f Mon Sep 17 00:00:00 2001 From: Tim Hsiung <26526132+bearomorphism@users.noreply.github.com> Date: Sat, 30 May 2026 14:23:53 +0800 Subject: [PATCH] fix(ci): make bump preview comment sticky The PR bump preview workflow passed ody-includes to peter-evans/create-or-update-comment@v5, but that action has no such input -- it only creates a new comment, or updates one passed via comment-id. Every run therefore appended another duplicate comment (e.g. 6 stacked on #2007). Insert a peter-evans/find-comment@v3 step ahead of the post step to look up an existing preview comment by sentinel marker and bot author, then pass its id (empty for the first run) to create-or-update-comment. This matches the documented pattern in the action's README and keeps the bump preview as a single sticky comment per PR. Apply the same fix to the docs/tutorials/github_actions.md example so other projects copying the workflow don't inherit the bug, and also bump the example from create-or-update-comment@v4 to @v5 to match the workflow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/pr-bump-preview.yml | 18 +++++++++++++++++- docs/tutorials/github_actions.md | 23 +++++++++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-bump-preview.yml b/.github/workflows/pr-bump-preview.yml index 1eab96774..49893e9c2 100644 --- a/.github/workflows/pr-bump-preview.yml +++ b/.github/workflows/pr-bump-preview.yml @@ -84,11 +84,27 @@ jobs: esac } > comment.md + # Look up an existing preview comment so the next step edits it in + # place instead of appending a new one on every run. + # `peter-evans/create-or-update-comment` does not search by body + # itself -- it only creates new comments, or updates a specific + # `comment-id`. + - name: Find existing preview comment + id: find-comment + uses: peter-evans/find-comment@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + comment-author: "github-actions[bot]" + body-includes: "" + - name: Post or update PR comment uses: peter-evans/create-or-update-comment@v5 with: token: ${{ secrets.GITHUB_TOKEN }} + # When empty (no prior comment found) a new one is created; + # otherwise the existing comment is edited in place. + comment-id: ${{ steps.find-comment.outputs.comment-id }} issue-number: ${{ github.event.pull_request.number }} body-path: comment.md - body-includes: "" edit-mode: replace diff --git a/docs/tutorials/github_actions.md b/docs/tutorials/github_actions.md index 7717bdbf5..f0b216072 100644 --- a/docs/tutorials/github_actions.md +++ b/docs/tutorials/github_actions.md @@ -205,12 +205,20 @@ jobs: ;; esac } > comment.md - - uses: peter-evans/create-or-update-comment@v4 + - name: Find existing preview comment + id: find-comment + uses: peter-evans/find-comment@v3 with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.pull_request.number }} - body-path: comment.md + comment-author: "github-actions[bot]" body-includes: "" + - uses: peter-evans/create-or-update-comment@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + comment-id: ${{ steps.find-comment.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body-path: comment.md edit-mode: replace ``` @@ -235,10 +243,13 @@ jobs: `update_changelog_on_bump` is set in your config, also the changelog entries that would be produced). Exit code `21` (`NoneIncrementExit`) is treated as "no eligible bump" rather than a failure. -- **Sticky comment**: The hidden HTML marker `` - lets [`peter-evans/create-or-update-comment`](https://github.com/peter-evans/create-or-update-comment) - find and replace the previous preview on every push, instead of leaving a - growing trail of comments. +- **Sticky comment**: [`peter-evans/find-comment`](https://github.com/peter-evans/find-comment) + looks up an existing comment by the hidden HTML marker + `` and bot author, then + [`peter-evans/create-or-update-comment`](https://github.com/peter-evans/create-or-update-comment) + edits it in place (or creates a new one on the first run when the + marker is not yet present), instead of leaving a growing trail of + comments. [jinja]: https://github.com/commitizen-tools/commitizen/blob/master/commitizen/changelog.py