Scheduling Netlify builds with GitHub Actions
Netlify normally rebuilds a site after a repository change. If the content itself depends on the current date, you may also need a build when nobody has committed anything. A scheduled GitHub Actions workflow is a simple way to call a Netlify build hook.
The schedule event uses POSIX cron syntax and UTC times. Scheduled workflows run from the latest commit on the default branch. In 2020, GitHub documented five minutes as the shortest interval.
This example triggers the workflow every 15 minutes:
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '*/15 * * * *'
The Netlify build hook
A build hook is a URL that starts a new build and deploy when it receives a POST request. In the Netlify dashboard used at the time, it was under Site settings > Build & deploy > Continuous deployment > Build hooks.
Call it from a workflow
Create .github/workflows/main.yml in the repository:
name: Schedule Netlify Build
on:
schedule:
- cron: '0 6 * * *'
jobs:
build:
name: Request Netlify Webhook
runs-on: ubuntu-latest
steps:
- name: Curl request
run: curl -X POST -d {} HERE-GOES-YOUR-BUILD-HOOK
Replace HERE-GOES-YOUR-BUILD-HOOK with the URL from Netlify. The cron expression runs the workflow every day at 06:00 UTC.
The hook URL can trigger deployments, so I would store it as a GitHub Actions secret rather than commit it to a public repository. The inline value keeps the example small, but a secret is the safer production setup.