How to trigger daily Netlify builds using GitHub Actions

Published on in Eleventy, Git and Netlify

Or any other automatic periodic builds. I'm using daily builds to automatically publish scheduled blog posts on my Eleventy 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 a .github/workflows/daily-build.yml file with the following contents (replace the cron expression with your own):

    name: Daily Netlify build trigger
    
    on:
      schedule:
        # Run 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:
              BUILD_HOOK: ${{ secrets.NETLIFY_DAILY_BUILD_HOOK }}
            run: |
              curl -X POST -d {} "$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