Skip to content

Commit 898dfa7

Browse files
committed
refactor: update PR comments instead of creating new ones
1 parent 398464a commit 898dfa7

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

.github/workflows/opentofu.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,27 @@ jobs:
6262
tail -n 1000 plan-filtered.txt > plan-filtered-truncated.txt
6363
mv plan-filtered-truncated.txt plan-filtered.txt
6464
65-
- name: Comment PR with Plan
66-
uses: actions/github-script@v7
65+
- name: Find existing comment
66+
uses: peter-evans/find-comment@v3
67+
id: fc
6768
with:
68-
github-token: ${{ secrets.GITHUB_TOKEN }}
69-
script: |
70-
const fs = require('fs');
71-
const planOutput = fs.readFileSync('plan-filtered.txt', 'utf8');
69+
issue-number: ${{ github.event.pull_request.number }}
70+
comment-author: 'github-actions[bot]'
71+
body-includes: '<!-- opentofu-plan -->'
7272

73-
const output = `#### OpenTofu Plan
74-
\`\`\`
75-
${planOutput}
76-
\`\`\`
77-
`;
78-
github.rest.issues.createComment({
79-
issue_number: context.issue.number,
80-
owner: context.repo.owner,
81-
repo: context.repo.repo,
82-
body: output
83-
});
73+
- name: Comment PR with Plan
74+
uses: peter-evans/create-or-update-comment@v4
75+
with:
76+
comment-id: ${{ steps.fc.outputs.comment-id }}
77+
issue-number: ${{ github.event.pull_request.number }}
78+
body-path: plan-filtered.txt
79+
body-prefix: |
80+
<!-- opentofu-plan -->
81+
#### OpenTofu Plan
82+
```
83+
body-suffix: |
84+
```
85+
edit-mode: replace
8486

8587
apply:
8688
name: OpenTofu Apply

0 commit comments

Comments
 (0)