Create a personal access token with repo
and workflow
permissions ready.
Create a workflow with sample code below and add a file call index.js
with console.log(main branch)
name: Build
on:
repository_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: echo github actor
run: echo ${{ github.actor }}
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.client_payload.branch || 'dev' }}
- name: Run index.js
run: node index.js
git add .
git commit -m "init"
git push origin main
Create a branch call dev
, then commit index.js
to console.log(dev branch)
git add .
git commit -m "fix: dev"
git push origin dev
Use curl
to call dispatch action
## Example 1
curl --request POST \
--url 'https://api.github.com/repos/ookangzheng/test-build/dispatches' \
--header 'authorization: Bearer <PERSONAL_ACCESS_TOKEN>' \
-d '{"event_type":"trigger", "client_payload": {"branch":"dev"}}'
## Example 2
curl -i -u <GITHUB_USERNAME>:<PERSONAL_ACCESS_TOKEN> --request POST \
--url 'https://api.github.com/repos/ookangzheng/test-build/dispatches' \
-d '{"event_type":"trigger", "client_payload": {"branch":"dev"}}'
- https://dev.to/rikurouvila/how-to-trigger-a-github-action-with-an-htt-request-545
- https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch
- https://github.community/t/how-to-trigger-repository-dispatch-event-for-non-default-branch/14470/10
- https://github.com/actions-packages-examples/branch-builds
- https://dev.to/rikurouvila/how-to-trigger-a-github-action-with-an-htt-request-545
- https://github.com/octokit/request-action
- https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_dispatch
- https://github.com/peter-evans/repository-dispatch
- https://dev.to/s_abderemane/manual-trigger-with-github-actions-279e
- https://github.com/marketplace/actions/auto-approve