如何获取我自己的 GitHub 事件有效负载 json 以在本地测试 GitHub 操作?

alp*_*aca 6 github github-actions

我使用 GitHub Actions 并想在本地测试它。我正在使用这个工具,它工作正常。 https://github.com/nektos/act

我可以提供一个 event.json 用于本地测试,但是创建一个真正的事件负载真的很难。

有没有办法获得真正的事件有效载荷?例如,我从控制台在我的存储库上创建拉取请求,并获取该事件有效负载 json。

riQ*_*iQQ 8

要获取事件数据,您可以使用 GitHub 操作将事件打印到日志中。

# 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"
Run Code Online (Sandbox Code Playgroud)

或者,您可以在文档中找到示例事件数据:https : //docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#webhook-payload-example-30

  • 警告:[文档说](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)“警告:使用整个 github 上下文时,请注意它包含诸如`github.token`之类的敏感信息。GitHub 在打印到控制台时会掩盖秘密,但在导出或打印上下文时应小心谨慎。” (2认同)