5151 with :
5252 github-token : ${{ secrets.GITHUB_TOKEN }}
5353 script : |
54- const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
54+ // 1. Retrieve existing bot comments for the PR
55+ const { data: comments } = await github.rest.issues.listComments({
56+ owner: context.repo.owner,
57+ repo: context.repo.repo,
58+ issue_number: context.issue.number,
59+ });
60+ const botComment = comments.find(comment => {
61+ return comment.user.type === 'Bot' && comment.body.includes('<!-- GitHub Actions Terraform PR comment bot -->')
62+ });
63+
64+ // 2. Put together bot new comment contents for the PR
65+ const output = `<!-- GitHub Actions Terraform PR comment bot -->
66+ #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
67+
5568 #### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
5669
5770 <details><summary>Show Plan</summary>
@@ -63,12 +76,22 @@ jobs:
6376 </details>
6477 *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
6578
79+ // 3. Delete previous comment for the PR
80+ if (botComment) {
81+ github.rest.issues.deleteComment({
82+ owner: context.repo.owner,
83+ repo: context.repo.repo,
84+ comment_id: botComment.id,
85+ });
86+ }
87+
88+ // 4. Create a new comment
6689 github.rest.issues.createComment({
67- issue_number: context.issue.number,
6890 owner: context.repo.owner,
6991 repo: context.repo.repo,
92+ issue_number: context.issue.number,
7093 body: output
71- })
94+ });
7295
7396 - name : Terraform Plan Status
7497 if : steps.plan.outcome == 'failure'
0 commit comments