Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats is the difference between repository_dispatch and workflow_dispatch in Github Actions?

Please explain the difference between these 2 event triggers with some real world example.

like image 277
Sajith Mantharath Avatar asked Aug 31 '25 18:08

Sajith Mantharath


2 Answers

Apparently, repository_dispatch events may only be read on the default branch

See:

  • this example (or this one) using workflow_dispatch
  • this example with repository_dispatch

For the latter, from William Villeneuve :

# TODO: replace :token, :user, and :repo
curl -H "Authorization: token :token" \
    -H 'Accept: application/vnd.github.everest-preview+json' \
    "https://api.github.com/repos/:user/:repo/dispatches" \
    -d '{"event_type": "awesomeness", "client_payload": {"foo": "bar"}}'
name: example-client-payload-action
on: repository_dispatch
jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - run: 'echo "field: ${{ github.event.client_payload.foo }}"'
      - run: 'echo "payload: ${{ toJson(github.event.client_payload) }}"'
      - run: echo baz
        if: github.event.action == 'baz'

As seen here:

Just posting here since it doesn't seem to be documented - you can also specify a list of types to trigger on:

on:
  repository_dispatch:
    types:
      - manual-trigger-mytest
      - manual-trigger-all

From "Manually Trigger A GitHub Actions Workflow"

like image 128
VonC Avatar answered Sep 02 '25 11:09

VonC


The way I understand this is:

Dispatch is any process that is triggered by something "outside GitHub". Example: A person clicking a button OR an API being called.

Having that said:

  • workflow_dispatch is a workflow run that you trigger literally by clicking the run button on the workflow.
  • repository_dispatch is a workflow that is triggered via this API and ideally will have a event_type that you can use on your yaml workflow at on/repository_dispatch/types.
like image 33
ReAlm Avatar answered Sep 02 '25 11:09

ReAlm