Deploy Netlify with GitHub

This site is built using Hugo which is a static site generator. It’s my go-to tool for building sites if there is no need for it to be driven by dynamic data. It’s simple to use, fast and there are great templates out there. It’s even easy to make your own, I’ve end made one.

The next step is to have the site hosted somewhere, I’ve chosen to use Netlify as it has a great free use tier, which I doubt that this site will ever use more than. It also has great support for building Hugo sites and can pick up changes from the GitHub repository where the entire site is located.

So when I push a change to the GitHub repository, Netlify picks up the new changes, builds the entire site, and then deploys it. Simple, it’s usually done within 60 seconds.

Now the problem. I work on posts over a few days, I know it doesn’t look like it does it. But, I like to write the post over a few days, then set the date of the post in the future so I have some time to think about it and read it locally, then no longer have to think about it. Now this wouldn’t work with how Netfily picks up changes and builds because it will not build future posts, why would it? This means that on the day that the post needs to go live, I would have to click the manual deploy button to get the latest and then rebuild where the future post is now a post that should be visible. The key word here is manual. Which sucks.

There is probably an easier way to solve this within Netlify with routines or some sort of check, however I couldn’t quickly find one. Also I wasn’t sure if it was on the free tier. But there is another way, which is to use build hooks.

Netlify Configuration

It’s rather simple to do, firstly for the site that you’re managing go into the site configuration > build & deploy > continuous deployment. There you’ll find the build hooks section.

Great now we have a URL that if we send a POST request to, will trigger a build and update the website with the latest build from the Hugo static site. Now how to trigger this, well I’m going to use a GitHub action, because it’s simple and the site is already hosted on a GitHub repository.

Github Action

Below is the yaml for the GitHub build action. Note that it’s triggered on two actions. First is the cron schedule, I’ve set this to 1 am every day, because why not? The second is workflow_dispatch, this just allows me to have a little button on the GitHub UI to manually trigger the action. Which is good for testing.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
name: Nightly Deploy

on:
  schedule:
      - cron: '0 1 * * *'
  workflow_dispatch:
    
jobs:
  deployment:
    runs-on: ubuntu-latest
    steps:
    - name: Deploy Stage
      uses: fjogeleit/http-request-action@v1
      with:
        url: '<YOUR ENDPOINT HERE>'
        method: 'POST'

The next section is the meat and potatoes of the action, where we ask it to just make an HTTP request. Here you’ll paste your deploy URL from the previous step, and ensure that the method is set to POST. That’s all that’s required for the GitHub action, now click the run action button just to test that everything works. You’ll see on your Netlify dashboard that a deployment has been completed and it was triggered by a build hook.

Job done, no need to worry about it anymore, can now move on to something else.


<-- Introducing Night Sky Pi
Created Another Hugo Theme -->