robburger / terraform-pr-commenter

A GitHub Action that adds opinionated comments to a PR from Terraform fmt/init/plan output
MIT License
132 stars 65 forks source link

Comment update removes the wrong comment #23

Open marcellovictorino opened 2 years ago

marcellovictorino commented 2 years ago

This is a great action. Thanks for sharing!

In order to provide a bit more context when running on multiple working directories and environments, I've been using a workaround. Injecting the values of interest into the TF_WORKSPACE env variable.

Which works 👍

- name: >
    Post Plan >> Env: ${{ matrix.project.env }} | Dir: ${{ matrix.project.dir }}
  if: always() && github.ref != 'refs/heads/master' && (steps.plan.outcome == 'success' || steps.plan.outcome == 'failure')
  uses: robburger/terraform-pr-commenter@v1
  env:
    TF_WORKSPACE: ${{ format('Env= {0} | Dir= {1}', matrix.project.env, matrix.project.dir) }}
  with:
    commenter_type: plan
    commenter_input: ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
    commenter_exitcode: ${{ steps.plan.outputs.exitcode }}

image


But I noticed that, sometimes, the action incorrectly identifies an "already existing" comment and decides to update it. For example, I have 9 different working-directories / env. But only get 5 PR comments

@robburger Any ideas? How exactly is the "uniqueness" of a comment defined? I imagined that, by adding more detail to the TF_WORKSPACE, it would make it more accurate.

JensRantil commented 1 year ago

If you search for the WORKSPACE variable in the script, you can see where it's being used. One thing to notice is that the variable is only used for commenter_type=="plan". This means your workaround will not work for init nor validate.

How exactly is the "uniqueness" of a comment defined?

Have a look at this line. In essence, it filters out the comment containing the string

"### Terraform `plan` .* for Workspace: `'"$WORKSPACE"'`"
JensRantil commented 1 year ago

This issue is related to #17.