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 account'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.

Cory Dransfeldt
Cory Dransfeldt

I'm a software developer in Camarillo, California. I enjoy hanging out with my beautiful family and 4 rescue dogs, technology, automation, music, writing, reading and tv and movies.