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
permissions
3. 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
Top comments (3)
is it possible to add some simple predefined link, which user can click and exec build in one go?
curl is fine, but would be awesome to add such link in release note, and let users to deploy with predefined settings releases.
Update in 2023:
You have to use
token
instead ofBearer
. So it's going to beAuthorization: token <Your personal access token here>
Great example, exactly what I was looking for. Thanks for sharing!