|
| 1 | +--- |
| 2 | +publish_date: 2025-06-01 |
| 3 | +tags: |
| 4 | + - github |
| 5 | +--- |
| 6 | + |
| 7 | + |
| 8 | +Creating a GitHub action with an on action of workflow_dispatch lets you create a webhook to run anything essentially. |
| 9 | + |
| 10 | +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: |
| 11 | + |
| 12 | +```bash |
| 13 | +curl -X POST \ |
| 14 | + https://api.github.com/repos/my-code/your-repo/actions/workflows/deploy.yml/dispatches \ |
| 15 | + -H "Authorization: token YOUR_GITHUB_PAT" \ |
| 16 | + -H "Accept: application/vnd.github.v3+json" \ |
| 17 | + -H "Content-Type: application/json" \ |
| 18 | + -d '{"ref":"main"}' |
| 19 | +``` |
| 20 | + |
| 21 | +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: |
| 22 | + |
| 23 | +```yaml |
| 24 | +# deploy-chiubaca-com.yml |
| 25 | +name: Redeploy chiubaca.com to Cloudflare worker |
| 26 | +on: |
| 27 | + workflow_dispatch: |
| 28 | +jobs: |
| 29 | + deploy: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v3 |
| 33 | + - uses: pnpm/action-setup@v2 |
| 34 | + with: |
| 35 | + version: 8 |
| 36 | + - name: Install dependencies |
| 37 | + run: pnpm install |
| 38 | + - name: Build chiubaca.com |
| 39 | + run: pnpm -w run chiubaca.com:build |
| 40 | + - name: Publish to Cloudflare |
| 41 | + run: pnpm -w run chiubaca.com:deploy |
| 42 | + env: |
| 43 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 44 | +``` |
| 45 | +
|
| 46 | +Like in the above example, i can execute this action just by running: |
| 47 | +```bash |
| 48 | +curl -X POST \ |
| 49 | + https://api.github.com/repos/chiubaca/chiubaca-monorepo/actions/workflows/deploy-chiubaca-com.yml/dispatches \ |
| 50 | + -H "Authorization: token ${{secrets.GHUB_PAT_FOR_CHIUBACA_COM_REDEPLOY_ACTION}}" \ |
| 51 | + -H "Accept: application/vnd.github.v3+json" \ |
| 52 | + -H "Content-Type: application/json" \ |
| 53 | + -d '{"ref":"main"}' |
| 54 | + |
| 55 | +``` |
0 commit comments