KINDERAS.COM

Mon Sep 12 2022

Quicktip: Triggering a webhook on a schedule using Github workflows

Have you ever had the need to trigger a webhook on a schedule, like every hour? In this short article we'll take a look at how you can trigger a Vercel webhook every hour using Github workflows.

This approach will work for any webhook url from any service.

There are three steps to doing this:

  1. Create a file (you can call it whatever you want) at the root of your project /.github/workflows/scheduled.yml
  2. Add a cron job (see the code below)
  3. Push the file to Github
name: Run build every hour
on:
  schedule:
    - cron: "*/60 * * * *"
jobs:
  cron:
    runs-on: ubuntu-latest
    steps:
      - name: Calling Vercel webhook for my-env
        run: |
          curl --request POST \
          --url 'https://api.vercel.com/v1/integrations/deploy/an_id'

This job will now run every hour from the default branch on Github. It doesn't matter if the file is found on multiple branches, it will only run from the default branch.