githubgithub-actions

How to get my own GitHub events payload json for testing GitHub Actions locally?


I use GitHub Actions and want to test it locally. I'm using this tool and it works fine. https://github.com/nektos/act

I can provide a event.json for local testing, but it's really hard to create a real event payload.

Is there any way to get real event payload? For example, I create pull request on my repository from the console, and get that event payload json.


Solution

  • To get event data, you can use a GitHub action to print the event to the log.

    # change this to the event type you want to get the data for
    on:
      pull_request:
        types: [opened, closed, reopened]
    
    jobs:
      printJob:    
        name: Print event
        runs-on: ubuntu-latest
        steps:
        - name: Dump GitHub context
          env:
            GITHUB_CONTEXT: ${{ toJson(github) }}
          run: |
            echo "$GITHUB_CONTEXT"
    

    Alternatively, you can find example event data in the documentation: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#webhook-payload-example-30