Documentation for github.event objects

Is there a way to see the actual documentation / specs for the github object we can access when setting up workflows? I tried to echo github.event for instance but that just prints object

My end goal is to have a workflow run only on PR merges or manual triggers, so I have the following configuration:

on:
  workflow_dispatch:
  pull_request:
    types: [closed]

and in my job, I do indeed need to check if the PR is merged

my-run:
    runs-on: [ubuntu-latest]
    if: ${{ github.event.pull_request.merged }}
    # more steps

but that means that if I trigger a manual workflow, the if clause prevents it from ever running… How can tell my if that I also want to run on workflow_dispatch? I tried to add || github.event.workflow_dispatch in there but that just doesn’t do anything… And because I can’t find exactly what is included in github.event, I don’t know what to try.

So my question is two-fold:

  • Where can I find detailed docs for all of the github.event objects & their sub-objects?
  • How can I have a workflow run on either a merged pr or a manual workflow_dispatch?

For reference, I did read through https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#github-context but that only covers some of the docs

UPDATE
So searching around I managed to find a way to echo any object by using toJson(<object>). But for workflow_dispatch I couldn’t find any relevant information :confused:

The best documentation I’m aware of is here: Events that trigger workflows

For most event types there’s a link to the webhook event payload documentation in the section on that event type on that page, e.g. here is the one for workflow_dispatch. I agree that is kind of complicated to find.

1 Like

Thanks for the response. Unfortunately I had already seen this page too and there isn’t much there either in terms of verifying that the event is indeed for workflow_dispatch.

1 Like

I did manage to find how to do so by first adding a step to print out the github object.

steps:
  - name: Echo github obj
    run: echo ${{ toJson(github) }}

This allowed me to see that the github object contains an event_name key, which, in the case of a workflow_dispatch event, contains workflow_dispatch.

It was then very easy to modify my if clause to also check for this key.

my-job:
  runs-on: [ubuntu-latest]
  if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch'
  steps:
    # more steps

note: somehow using double quotes around "workflow_dispatch" in the if clause raises an error (Unknown identifier), so make sure to use single quotes

1 Like