Skip to main content

Hide Old PR Comments

In the workflow built in Getting Started, tfcmt posts comments on pull requests.
However, one issue is that old comments remain and continue to accumulate.

There are two solutions:

  1. Hide old comments using hide-comment action
  2. Use tfcmt plan -patch to update existing comments instead of creating new ones

We recommend option 1.

hide-comment action

Run hide-comment action. pull_request:write permission is required.

- uses: suzuki-shunsuke/tfaction@latest
with:
action: hide-comment

With this setup, old comments will be hidden.

tfcmt plan -patch

Create a tfcmt configuration file:

# yaml-language-server: $schema=https://raw.githubusercontent.com/suzuki-shunsuke/tfcmt/v4.14.1/json-schema/tfcmt.json
# https://github.com/suzuki-shunsuke/tfcmt
plan_patch: true

This causes terraform plan and apply comments to be updated instead of creating new ones.

However, tfaction does not only post comments via tfcmt. Older comments created by tools other than tfcmt will still remain.

Therefore, it is recommended to combine this with hide-comment action. That said, if you do so, you might conclude that using only hide-comment action is sufficient.

- uses: suzuki-shunsuke/tfaction@latest
with:
action: hide-comment
if: |
Comment.HasMeta && Comment.Meta.SHA1 != Commit.SHA1 && Comment.Meta.Program != "tfcmt"