How I Got My Netlify Site to Auto-Deploy

This site is built with Hugo and hosted on Netlify. Netlify watches the GitHub repository, builds on push, and deploys in under a minute. That works well until scheduling posts for the future. Hugo hides future dated posts, so the site will not rebuild on the day they should go live unless a manual deploy is triggered. Manual is the problem to solve.

Netlify build hook

In Netlify, open the site settings and go to Build & deploy → Continuous deployment → Build hooks. Create a build hook. Netlify gives you a URL that will trigger a new build when it receives a POST request.

Triggering from GitHub

Add a small GitHub Actions workflow in the site repository that runs on a daily schedule and on manual request. The job makes a simple HTTP POST to the Netlify build hook URL. That is enough to rebuild the site so scheduled posts publish without human intervention. The schedule used here is 01:00 daily, and a manual workflow_dispatch trigger is included 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'

Quick test

Run the workflow from the GitHub Actions tab. On the Netlify dashboard, the new deploy will show up as triggered by a build hook. That removes the calendar reminder and keeps scheduled posts automatic.

Thanks for reading.


↤ Previous Post
Next Post ↦