github / lock

Lock Action to support deployment locking for the branch-deploy Action
MIT License
31 stars 5 forks source link

TypeError: Cannot read properties of undefined (reading 'body') #58

Closed mwkcoding closed 2 weeks ago

mwkcoding commented 3 weeks ago

I'm trying to use the lock action headless to enable locks to make sure an environment can only be used for one PR at a time.

But when I try to lock the environment I get this error:

/home/runner/work/_actions/github/lock/v2/src/main.js:63
    const body = context.payload.comment.body.trim()
^
TypeError: Cannot read properties of undefined (reading 'body')
    at run (/home/runner/work/_actions/github/lock/v2/src/main.js:63:1)
    at /home/runner/work/_actions/github/lock/v2/src/main.js:289:1
    at /home/runner/work/_actions/github/lock/v2/dist/index.js:326[82]([REPO_URL]/actions/runs/11520936978/job/32073423092#step:5:83):3
    at Object.<anonymous> (/home/runner/work/_actions/github/lock/v2/dist/index.js:32685:12)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1024:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at node:internal/main/run_main_module:28:49

The step I am trying to run that fails

...
- name: Lock environment
  uses: github/lock@v2
  id: lock-environment
  if: steps.lock-check.outputs.locked == 'false'
  with:
    environment: ${{ needs.get-slot-from-label.outputs.slot }}
    github_token: ${{ secrets.GITHUB_TOKEN }}
...
mwkcoding commented 2 weeks ago

It looks like it assumes there's a body from an issue comment to read. This is not the case when using the action purely headless.

mwkcoding commented 2 weeks ago

I was missing the "mode" input. Works now.