Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 982
alpaca Avatar asked Sep 09 '20 00:09

alpaca


People also ask

How do I test local actions on GitHub?

Act the solution. The two important reasons that you should use Act: Fast Feedback - Rather than having to commit/push every time you want to test out the changes you are making to your . github/workflows/ files (or for any changes to embedded GitHub actions), you can use act to run the actions locally.

What is payload URL in GitHub?

The payload URL is the URL of the server that will receive the webhook POST requests.


Video Answer


1 Answers

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

like image 138
riQQ Avatar answered Oct 18 '22 17:10

riQQ