Skip to content

feat(comment): optionally disable comment#544

Open
FalcoSuessgott wants to merge 1 commit intoOP5dev:mainfrom
FalcoSuessgott:optional-post-comment
Open

feat(comment): optionally disable comment#544
FalcoSuessgott wants to merge 1 commit intoOP5dev:mainfrom
FalcoSuessgott:optional-post-comment

Conversation

@FalcoSuessgott
Copy link
Copy Markdown

This action currently attempts to overwrite / recreate any previous comments. While this approach is useful for most setups, it leads to race conditions when this actions is being used in a matrix - where one job overwrites the comment of a previous job.

This PR introduces a new boolean argument post-comment that if disabled, skips posting the TF diff comment.
Users can then instead use the output of the action and implement their own commenting logic:

This approach could also be used to allow posting all diffs in one comment (#535):

Example:

jobs:
  tf-plan:
    strategy:
      fail-fast: false
      matrix:
        include:
          - cluster: dev
            account_id: "1234"
          - cluster: prod
            account_id: "56789"
  steps:
      - id: terraform-plan
        uses: op5dev/tf-via-pr@v13
        with:
          working-directory: infra
          post-comment: false

      - name: Post Terraform plan comment
        env:
          GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
          COMMENT_BODY: ${{ steps.terraform-plan.outputs.comment-body }}
          COMMENT_TITLE: ${{ github.workflow }} / ${{ matrix.cluster }}
        run: |
          comment_file="$(mktemp)"
          printf '## %s\n\n%s\n' \
            "${COMMENT_TITLE}" \
            "${COMMENT_BODY}" > "${comment_file}"

          gh pr comment "${{ github.event.number }}" \
            --repo "${{ github.repository }}" \
            --body-file "${comment_file}"

result:

Terraform Infrastructure CI / prod

terraform plan -chdir=infra -var-file=vars/default.tfvars -var-file=clusters/prod.tfvars
Diff of 3 changes.
Plan: 0 to add, 3 to change, 0 to destroy.
By @FalcoSuessgott at 2026-03-24T05:19:41Z.
Terraform Infrastructure CI / dev

terraform plan -chdir=infra -var-file=vars/default.tfvars -var-file=clusters/dev.tfvars
Diff of 4 changes.
Plan: 0 to add, 4 to change, 0 to destroy.
By @FalcoSuessgott at 2026-03-24T05:19:41Z .

@FalcoSuessgott FalcoSuessgott requested a review from rdhar as a code owner March 24, 2026 05:29
@FalcoSuessgott
Copy link
Copy Markdown
Author

alternatively, we could update comment-method to accept like none to skip comment creation

@ArkShocer
Copy link
Copy Markdown
Contributor

Can you show how you tried it with the normal commenting enabled in your matrix job? Or is the example yaml above already the one with the issue? We are using the action in pretty much every repository with matrix and have no issues at all.

@FalcoSuessgott
Copy link
Copy Markdown
Author

Can you show how you tried it with the normal commenting enabled in your matrix job? Or is the example yaml above already the one with the issue? We are using the action in pretty much every repository with matrix and have no issues at all.

No the example above is from the approach introduced in this PR (wait for all matrix jobs to finish and then post the plans in separate comments).

IIRC I noticed that this GHA would overwrite existing/previous comments (so that one matrix job would overwrite the plan comment of another matrix job), so I wasn't able to see all plans from my matrix jobs.

But if you got it work, then there might have been another problem on my side .. Ive migrated to Atlantis, so can't investigate further.

Regardless, perhaps this PR still makes sense for some custom setups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants