Scheduled Eleventy builds on Vercel with cron-triggered GitHub actions
In an effort to get away from client-side Javascript and embrace Eleventy for what it is (a static site generator), I've dropped my social-utils instance offline and my now-playing track display on my home page that still relied on it.
To update my feeds (feed.xml and follow.xml) and now page I've adopted @11ty/eleventy-fetch and regular builds at Vercel that are triggered by Github Actions that leverage cron for scheduling. The workflow file looks like this:
name: Scheduled Vercel build
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
schedule:
- cron: '0 * * * *'
jobs:
cron:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
This leverages three different Vercel secrets specific to your account that must be added to the Github Actions Secrets for your project (Project repo -> Settings -> Secruity section -> Secrets and variables -> Actions
).
Your Vercel org ID and project ID will be at the bottom of your organization/personal acount's settings (in the General section), with your project ID located in the same section of your project settings.
If you need to manually trigger a build, you can do so using a workflow with a [workflow_dispatch]
trigger like this:
name: Manual Vercel build
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on: [workflow_dispatch]
jobs:
cron:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
Once you have the appropriate secrets and workflow file in place, you can let GitHub take care of regularly rebuilding and refreshing your site.
Subscribe to my newsletter
Read articles from Cory Dransfeldt directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Cory Dransfeldt
Cory Dransfeldt
Husband, dad, developer, music nerd.