Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Github Actions repository_dispatch example
name: Build Artifacts
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: call the other repo
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EVENT: YOUR_EVENT_TYPE
ORG: YOUR_ORG_NAME
REPO: YOUR_REPO_NAME
run: |
curl -d "{\"event_type\": \"${EVENT}\"}" -H "Content-Type: application/json" -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.everest-preview+json" "https://api.github.com/repos/${ORG}/${REPO}/dispatches"
name: dispatch receiver
on: [repository_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: dispatch trigger
if: github.event.action == "YOUR_EVENT_TYPE"
run: |
echo "repository_dispatch triggered"
@Daniel-ltw
Copy link
Author

Daniel-ltw commented Sep 30, 2019

Your repository_dispatch receiver yaml config have to be in the repo default branch.

@jdolitsky
Copy link

jdolitsky commented Jan 30, 2020

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

and triggered with

curl -H "Accept: application/vnd.github.everest-preview+json" \
    -H "Authorization: token <token>" \
    --request POST \
    --data '{"event_type": "manual-trigger-mytest"}' \
    https://api.github.com/repos/<org>/<repo>/dispatches

(credit to https://goobar.io/2019/12/07/manually-trigger-a-github-actions-workflow/)

@big-andy-coates
Copy link

big-andy-coates commented May 3, 2022

For this to work with the latest Github workflows you can't use secrets.GITHUB_TOKEN when triggering another workflow. If you do, Github will ignore the request. This is to avoid infinite loops. Instead, you will need to set up an access token, store it in your repo or orgs secrets and reference that instead.

Docs: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment