Trigger a Netlify build every day using GitHub Actions
Tags: github, actions, netlify
Published: 2022-02-20 19:18:04

---
title: Trigger a Netlify build every day using GitHub Actions
published: true
date: 2022-02-20 00:00:00 UTC
tags: github, actions, netlify
canonical_url: https://www.visualstudiogeeks.com/github/netlify/trigger-netlify-build-everyday-using-github
---

I host this blog on Netlify and source control is managed using GitHub. Often, I end up writing few blog posts together, but not necessarily want all of them published together. Jekyll allows to put future date in the post and it will not be published until that date. This lets me write blog posts on same day but end up publishing them later based on the date set for the post. However, this means that when you run `jekyll build` posts with future dates will be skipped and I will need to run `jekyll build` again on the post date to publish the blog posts. Same applies to Netlify. Curious how we can solve this by triggering scheduled deploys on Netlify?

<!-- more -->

![Jekyll skips posts with future dates](https://www.visualstudiogeeks.com/images/screenshots/utkarsh/2022/feb/trigger-netlify-build-everyday-using-github-actions/jekyll-skip.png)
_Jekyll skipping posts with future date_

## Create Netlify build hook

Netlify supports [build hooks](https://docs.netlify.com/configure-builds/build-hooks/), which lets you trigger new builds and deploys by making a request to a URL.

![Configure build hooks in netlify](https://www.visualstudiogeeks.com/images/screenshots/utkarsh/2022/feb/trigger-netlify-build-everyday-using-github-actions/configure-builds-build-hooks.png)
_Configure build hooks_

Go to `Site Settings` and `Build Hooks` section and click `Add Build Hook` button.

![Add build hook](https://www.visualstudiogeeks.com/images/screenshots/utkarsh/2022/feb/trigger-netlify-build-everyday-using-github-actions/add-build-hook.jpg)
_Add build hook_

Give a name and select a branch to trigger the build and click `Save`. You will see the URL which you can use to trigger the build.

![Save build hook](https://www.visualstudiogeeks.com/images/screenshots/utkarsh/2022/feb/trigger-netlify-build-everyday-using-github-actions/build-hook.jpg)
_URL of the build hook_

## Create GitHub Actions workflow

Go to GitHub repo and create a actions yaml file under `.github\workflows` folder. GitHub Actions supports scheduled jobs, which lets you run a job at a specific time. See the below example. I am using cron expression to run the build every day at 04:00 AM UTC timezone.

```
name: nightly-netlify-build

on:
  schedule:
    - cron: "1 4 * * *"

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: trigger netlify build
        run: |
          curl -X POST -d '{}' https://api.netlify.com/build_hooks/2eae8d5c79506d0213a38be0e

```

Save the file and push the changes. That is it, you have created a GitHub Actions workflow which can trigger nightly build of the blog. Go to Netlify and see the `Deploys` tab. You will see the deploys triggered by the build hook.

![GitHub tooltip](https://www.visualstudiogeeks.com/images/screenshots/utkarsh/2022/feb/trigger-netlify-build-everyday-using-github-actions/verify-netlify.jpg)
_Deploys triggered by the build hook_

Isn’t that cool? If you liked the post, do share it in your social channels. Thanks for reading.