如何远程触发 GitHub Action

通常,我们需要在 GitHub 上进行一些操作,才能触发 GitHub Action。本篇将介绍一种通过 API 远程调用触发 GitHub Action 的方法。

1. 常见的几种触发 GitHub Action 的方式

下面是一个 GitHub Action 的示例:

相关推荐

站点声明:本站部分内容转载自网络,作品版权归原作者及来源网站所有,任何内容转载、商业用途等均须联系原作者并注明来源。

相关侵权、举报、投诉及建议等,请发邮件至E-mail:service@mryunwei.com

回到顶部
1
2
3
4
5
6
7
name: GitHub Actions Demo
on: [push, pull_request]
jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Hello World!"
on:
  workflow_dispatch:
    inputs:
      name:
        description: 'Person to greet'
        required: true
        default: 'Mona the Octocat'
on:
  push
on:
  issues:
    types: [opened, edited, milestoned]
on:
  issue_comment:
    types: [created, deleted]
on:
  project:
    types: [created, deleted]
on:
  pull_request:
    types: [assigned, opened, synchronize, reopened]
on: 
  repository_dispatch:
    types:
      - webhook-1
      - webhook-2

jobs:
  run:
    runs-on: ubuntu-latest

    steps:
    - name: Hello World
      run: |
        echo Hello World!
curl -X POST https://api.github.com/repos/:owner/:repo/dispatches 
    -H "Accept: application/vnd.github.everest-preview+json" 
    -H "Authorization: token TRIGGER_TOKEN" 
    --data '{"event_type": "TRIGGER_EVENT"}'
curl -X POST https://api.github.com/repos/shaowenchen/wait-webhook-to-run/dispatches 
    -H "Accept: application/vnd.github.everest-preview+json" 
    -H "Authorization: token ghp_xxxxxxxxxxxxxxxxxxxxxxxxxx" 
    --data '{"event_type": "webhook-1"}'
curl -X POST https://api.github.com/repos/shaowenchen/wait-webhook-to-run/dispatches 
    -H "Accept: application/vnd.github.everest-preview+json" 
    -H "Authorization: token ghp_xxxxxxxxxxxxxxxxxxxxxxxxxx" 
    --data '{"event_type": "webhook-2"}'