Skip to content

Commit 7317183

Browse files
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>
1 parent df8f6a0 commit 7317183

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

.github/workflows/pr-bump-preview.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,27 @@ jobs:
8484
esac
8585
} > comment.md
8686
87+
# Look up an existing preview comment so the next step edits it in
88+
# place instead of appending a new one on every run.
89+
# `peter-evans/create-or-update-comment` does not search by body
90+
# itself -- it only creates new comments, or updates a specific
91+
# `comment-id`.
92+
- name: Find existing preview comment
93+
id: find-comment
94+
uses: peter-evans/find-comment@v3
95+
with:
96+
token: ${{ secrets.GITHUB_TOKEN }}
97+
issue-number: ${{ github.event.pull_request.number }}
98+
comment-author: "github-actions[bot]"
99+
body-includes: "<!-- commitizen-bump-preview -->"
100+
87101
- name: Post or update PR comment
88102
uses: peter-evans/create-or-update-comment@v5
89103
with:
90104
token: ${{ secrets.GITHUB_TOKEN }}
105+
# When empty (no prior comment found) a new one is created;
106+
# otherwise the existing comment is edited in place.
107+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
91108
issue-number: ${{ github.event.pull_request.number }}
92109
body-path: comment.md
93-
body-includes: "<!-- commitizen-bump-preview -->"
94110
edit-mode: replace

docs/tutorials/github_actions.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,20 @@ jobs:
205205
;;
206206
esac
207207
} > comment.md
208-
- uses: peter-evans/create-or-update-comment@v4
208+
- name: Find existing preview comment
209+
id: find-comment
210+
uses: peter-evans/find-comment@v3
209211
with:
210212
token: ${{ secrets.GITHUB_TOKEN }}
211213
issue-number: ${{ github.event.pull_request.number }}
212-
body-path: comment.md
214+
comment-author: "github-actions[bot]"
213215
body-includes: "<!-- commitizen-bump-preview -->"
216+
- uses: peter-evans/create-or-update-comment@v5
217+
with:
218+
token: ${{ secrets.GITHUB_TOKEN }}
219+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
220+
issue-number: ${{ github.event.pull_request.number }}
221+
body-path: comment.md
214222
edit-mode: replace
215223
```
216224
@@ -235,10 +243,13 @@ jobs:
235243
`update_changelog_on_bump` is set in your config, also the changelog
236244
entries that would be produced). Exit code `21` (`NoneIncrementExit`)
237245
is treated as "no eligible bump" rather than a failure.
238-
- **Sticky comment**: The hidden HTML marker `<!-- commitizen-bump-preview -->`
239-
lets [`peter-evans/create-or-update-comment`](https://github.com/peter-evans/create-or-update-comment)
240-
find and replace the previous preview on every push, instead of leaving a
241-
growing trail of comments.
246+
- **Sticky comment**: [`peter-evans/find-comment`](https://github.com/peter-evans/find-comment)
247+
looks up an existing comment by the hidden HTML marker
248+
`<!-- commitizen-bump-preview -->` and bot author, then
249+
[`peter-evans/create-or-update-comment`](https://github.com/peter-evans/create-or-update-comment)
250+
edits it in place (or creates a new one on the first run when the
251+
marker is not yet present), instead of leaving a growing trail of
252+
comments.
242253

243254
[jinja]: https://github.com/commitizen-tools/commitizen/blob/master/commitizen/changelog.py
244255

0 commit comments

Comments
 (0)