mercari / tfnotify

A CLI command to parse Terraform execution result and notify it to GitHub
MIT License
619 stars 91 forks source link

No Github comments from tfnotify #120

Open leszczynskimikolaj opened 1 year ago

leszczynskimikolaj commented 1 year ago

My issue: Even though I set GITHUB_REF env var, I still get tfnotify comments attached to my commits instead of having them attached to related PR and what's more I do not get any labels attached to my PR.

My tfnotify.yml

ci: github-actions
notifier:
  github:
    token: <redacted>
    repository:
      owner: <redacted>
      name: <redacted>
terraform:
  plan:
    template: |
      {{ .Title }}
      {{ .Message }}
      {{if .Result}}
      <pre><code>{{ .Result }}
      </pre></code>
      {{end}}
      <details><summary>Details (Click me)</summary>
      <pre><code>{{ .Body }}
      </pre></code></details>
    when_add_or_update_only:
      label: "add-or-update"
    when_no_changes:
      label: "no-changes"
    when_plan_error:
      label: "error"
    when_destroy:
      label: "destroy"
      template: |
        ## :warning: WARNING: Resource Deletion will happen :warning:
        This plan contains **resource deletion**. Please check the plan result very carefully!

The command I run as part of my local tests:

export GITHUB_REF=refs/pull/240/merge
cat plan_result.temp | tfnotify --config tfnotify.yml plan --message "example tfnotify comment message"

I have a feeling tfnotify does not respect the GITHUB_REF env var I set and hence this code does not get executed.

Starefossen commented 1 year ago

I am facing similar problems and tfnotify is not setting any lanes either...

leszczynskimikolaj commented 1 year ago

cc: @dtan4 as I saw this PR

Starefossen commented 1 year ago

I got this to work locally but for some reason tfnotify insists on posting commit comments instead of pull request comments for the exact same environment variables set.

leszczynskimikolaj commented 1 year ago

@Starefossen what do you mean exactly? I also get the commit's comments instead of pull request's comments but still no PR labels. Can you provide here the command you run?

Starefossen commented 1 year ago

I compiled it myself, didn't realize that the "latest" version was so far behind master branch.

Starefossen commented 1 year ago

You can use the tfnotify binary I have compiled from here: https://github.com/nais/tfnotify/releases/tag/v0.7.8

Starefossen commented 1 year ago

I also made #121 to fix the build and release so they can get a new version out.