目录
需求一:由 Action 触发 Webhook
- 使用 distributhor/workflow-webhook
- 地址:https://github.com/distributhor/workflow-webhook
示例:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Invoke deployment hook
        uses: distributhor/workflow-webhook@v1
        env:
          webhook_type: 'json-extended'
          webhook_url: $
          webhook_secret: $
          data: '{ "weapon": "hammer", "drink" : "beer" }'
- WEBHOOK_URL和- WEBHOOK_SECRET分别为 Webhook 地址和密码,均在仓库的- secrets中设置。
需求二:由仓库 A 的 Action 触发仓库 B 的 Action
仓库 B 的设置
- 在仓库 B 的 .github/workflows/Action.yml中添加一个触发条件repository_dispatch
on:
  repository_dispatch:
  workflow_dispatch:
  schedule:
    - cron: "0 0 * * *"
仓库 A 的设置
- 在仓库 A 的 .github/workflows/Action.yml添加以下片段
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger auto update actions
          run: |
            curl -XPOST -u "$:$" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" $ --data '{"event_type": "build_application"}'
- PAT_USERNAME为仓库 B 用户的用户名;
- PAT_TOKEN为仓库 B 用户的 Personal Access Token;
- PAT_ADDR形如- https://api.github.com/repos/xxx/yyyy/dispatches,- xxx为仓库 B 用户名,- yyyy为仓库 B 的名称;
- 以上变量在仓库 A 的 secrets中设置。
引用
- https://github.community/t/triggering-actions-by-other-repository-webhooks/16295/5
- https://github.community/t/triggering-by-other-repository/16163