How to trigger daily Netlify builds using GitHub Actions

Published on in 11ty and Git

Or any other automatic periodic builds. I'm using daily builds to automatically publish scheduled blog posts on my 11ty site.

  1. Create a build hook on Netlify. Name it e.g. "Daily build from GitHub Actions."

    "Build hooks are URLs you can use to trigger new builds and deploys." To trigger a build, you can send a POST request to the URL.

  2. Create an encrypted secret for your GitHub repository. Name it e.g. NETLIFY_DAILY_BUILD_HOOK and use the URL from step 1 as the value.

    We are storing the URL as a secret because otherwise someone could spam the URL and rob you from your Netlify account's build minutes.

  3. Create a cron schedule expression using e.g. Crontab.guru or any of the other cron generators that can be easily found via Google.

    E.g. 50 5 * * * means "every day at 5:50 AM UTC." Crontab.guru has more cron examples.

  4. Create .github/workflows/daily-build.yml with the following content (replace the cron expression with your own):

    name: Daily Netlify build trigger

    on:
    schedule:
    # Runs at 5:50 AM UTC every day
    - cron: '50 5 * * *'

    jobs:
    build:
    runs-on: ubuntu-latest
    steps:
    - name: Curl request to Netlify's build hook
    env:
    NETLIFY_DAILY_BUILD_HOOK: ${{ secrets.NETLIFY_DAILY_BUILD_HOOK }}
    run: |
    curl -X POST -d {} "$NETLIFY_DAILY_BUILD_HOOK"

And that's it! GitHub will automatically run the Action every day around the specified time. The Action will do a POST request to the build hook which will trigger a build on Netlify.

Note about scheduled GitHub Actions events:

The schedule event can be delayed during periods of high loads of GitHub Actions workflow runs. High load times include the start of every hour. To decrease the chance of delay, schedule your workflow to run at a different time of the hour.

Further resources