Skip to main content

Hiding Old PR Comments

In the workflow built in Getting Started, tfcmt posts comments to the PR, but old comments remain visible indefinitely.

There are two solutions:

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

We recommend option 1.

hide-comment action

Run the hide-comment action in your GitHub Actions workflow.

The pull_requests: write permission is required.

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

This hides old comments:

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 result comments to be updated in place:

However, tfaction posts comments from sources other than tfcmt, and those old comments will still remain. It is best to use this in combination with hide-comment action. That said, if you are using both together, hide-comment action alone may be sufficient.

- uses: suzuki-shunsuke/tfaction@latest
with:
# Do not hide comments posted by tfcmt
if: |
Comment.HasMeta && Comment.Meta.SHA1 != Commit.SHA1 && Comment.Meta.Program != "tfcmt"