terraform-plan-comment icon indicating copy to clipboard operation
terraform-plan-comment copied to clipboard

Error: Cannot read properties of undefined (reading 'head')

Open rj93-finseta opened this issue 1 year ago • 6 comments

I am attempting to use the action but I'm getting the following error:

Run borchero/terraform-plan-comment@v2
  with:
    token: ***
    working-directory: src
    planfile: plan.tfplan
    terraform-cmd: terraform
    header: 📝 Terraform Plan
  
Render plan
Render comment
Error: Cannot read properties of undefined (reading 'head')

There is no expanded out under the render plan, or render comment steps (not sure if there should be).

Running ls -la src outputs:

drwxr-xr-x 3 runner docker 4096 Sep 23 10:53 .
drwxr-xr-x 6 runner docker 4096 Sep 23 10:53 ..
drwxr-xr-x 3 runner docker 4096 Sep 23 10:53 .terraform
-rw-r--r-- 1 runner docker 2710 Sep 23 10:53 .terraform.lock.hcl
-rw-r--r-- 1 runner docker   98 Sep 23 10:53 main.tf
-rw-r--r-- 1 runner docker 5337 Sep 23 10:53 plan.tfplan

Any ideas what could be causing this?

rj93-finseta avatar Sep 23 '24 10:09 rj93-finseta

Is the workflow called from a pull_request event? I think this would cause the error (which should probably be improved...).

borchero avatar Sep 23 '24 15:09 borchero

I have an open PR, and I am pushing commits to it. So I have:

on:
  push:

in my workflow

rj93-finseta avatar Sep 23 '24 16:09 rj93-finseta

I see! Your workflow requires the trigger

on:
  pull_request:

as, otherwise, the action does not know which PR to post a comment to. In a push event, the context only provides the branch name and not the pull request(s) that the branch is associated with.

borchero avatar Sep 23 '24 18:09 borchero

Now do we skip posting when we have a workflow with both:

on:
  push:
    branches:
    - main
  pull_request:
    branches:
    - main

chrisk-petsure avatar Oct 30 '24 03:10 chrisk-petsure

Now do we skip posting when we have a workflow with both:

Yes, exactly. You'd need to add if: github.event_name == 'pull_request' to the workflow step which uploads the comment.

borchero avatar Oct 31 '24 08:10 borchero

🤖 Stalebot

This issue hasn't seen updates in the last 60 days.

If it has been resolved or won't be worked on, please consider closing the issue. Otherwise, it will be closed automatically in 30 days.

github-actions[bot] avatar Feb 15 '25 21:02 github-actions[bot]