Creating a GitHub action with an on action of workflow_dispatch lets you create a webhook to run anything essentially.
for example, if I have a GitHub action called deploy.yml
my GitHub repo called my-code
I can execute this webhook with the following curl:
curl -X POST \
https://api.github.com/repos/my-code/your-repo/actions/workflows/deploy.yml/dispatches \
-H "Authorization: token YOUR_GITHUB_PAT" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
-d '{"ref":"main"}'
For some reason Cloudflare workers dont have deploy webhook like Cloudflare pages out the box, so this solution works as a pretty good alternative, heres the action that redeploys my website:
# deploy-chiubaca-com.yml
name: Redeploy chiubaca.com to Cloudflare worker
on:
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Install dependencies
run: pnpm install
- name: Build chiubaca.com
run: pnpm -w run chiubaca.com:build
- name: Publish to Cloudflare
run: pnpm -w run chiubaca.com:deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Like in the above example, i can execute this action just by running:
curl -X POST \
https://api.github.com/repos/chiubaca/chiubaca-monorepo/actions/workflows/deploy-chiubaca-com.yml/dispatches \
-H "Authorization: token ${{secrets.GHUB_PAT_FOR_CHIUBACA_COM_REDEPLOY_ACTION}}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
-d '{"ref":"main"}'