Scheduling a deployment to Vercel
If your static site is a function of time, triggering a build at regular intervals can ensure things remain fresh.
Maybe you have dynamic calculations on your about page or like to line
up posts for publishing at a future date. Whatever the reason, one solution is
to have Vercel rebuild your static site at a time of your cron’s choosing.
We’ll use a GitHub workflow to run an action every day, and trigger a build using a Vercel Deploy hook.
Deploy hooks can be found within the Git settings of each project, and require a name and target branch.
https://vercel.com/{org}/{project}/settings/git
With a newly minted URL, we parameterise the GitHub workflow using a secret.
https://github.com/{org}/{project}/settings/secrets/actions
An example workflow that runs curl
everyday at 02:00 looks like this:
name: Build
on:
workflow_dispatch:
schedule:
- cron: '0 2 * * *'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Trigger a deploy
run: curl -X POST "${{ secrets.VERCEL_DEPLOY_HOOK }}"
Note, we can skip the time consuming check-out step as we only need to execute
curl
, which is baked into the CI environment.
Don’t forget to add the all-important workflow_dispatch
trigger to enable
manual testing at a time of our choosing. Otherwise, you could be waiting a few
days to get things just right!