# Running a CRON Job with GitHub Actions
In your project root, create a .github/workflows
directory containing a scheduled-builds.yml
file. Let's use the following template as a starting point:
# .github/workflows/scheduled-builds.yml
name: Trigger Site Rebuild on a CRON Schedule
on:
schedule:
# Runs "at minute 55 past every hour" (see https://crontab.guru)
- cron: '55 * * * *'
jobs:
build:
name: Trigger Site Rebuild
runs-on: ubuntu-latest
steps:
- name: cURL request
# Hit the webhook endpoint to rebuild from the "main" branch
run: curl -X POST -d {} https://<webhook-endpoint-url>
# Add the Webhook URL
Add the webhook URL generated in the previous step to the run
(opens new window) command at the end of the file.
# Configure the Schedule
This GitHub action uses CRON (opens new window) patterns to define a schedule that will drive the job
that hits the webhook endpoint to trigger a site rebuild. You can use the crontab.guru (opens new window) tool to check that a CRON pattern matches the intended schedule.
If we paste the CRON pattern in the template (55 * * * *
) in the Crontab Guru, we see that this schedule corresponds to “At minute 55.” This means that the site will rebuild every hour at hh:55
. If we wanted to build the site twice an hour, then we could use the pattern 25,55 * * * *
to build the site “At minute 25 and 55.”
# Deploy the GitHub Action
Once you have added the CRON pattern of your choosing, commit & push this file to your GitHub repository to initiate the GitHub Action.