1. Create a new action with repository_dispatch
trigger
Make sure your action is set to trigger on
repository_dispatch
event. This is the same event used when triggering the action through the UI.name: Node.js CI
on:
repository_dispatch:
schedule:
- cron: '5 12 * * 0'
jobs:
build:
runs-on: ubuntu-latest
2. Get yourself a personal access token to use the Github API
You can create one here: https://github.com/settings/tokens
Make sure you add
repo
and workflow
permissions3. Create the HTTP request
POST https://api.github.com/repos/<username>/<repo>/dispatches
Authorization: Bearer <Your personal access token here>
{"event_type": "hello"}
cURL
curl --request POST \
--url 'https://api.github.com/repos/<USERNAME>/<REPO>/dispatches' \
--header 'authorization: Bearer <TOKEN>' \
--data '{"event_type": "hello"}'
Sources
- https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch
- https://github.community/t/github-actions-api-to-run-a-workflow-and-cli-atop-of-it/18399
- https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#create-a-repository-dispatch-event