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

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
Author

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

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.

1 participant