How I Got My Netlify Site to Auto-Deploy
Version note: This post records the Netlify and GitHub Actions setup documented in January 2024. The site now deploys through GitHub Pages.
This site uses Hugo and Netlify. Netlify watches the GitHub repository. It builds on push. It deploys in under one minute. This method fails for future dated posts. Hugo hides these posts. The site does not rebuild on the publish date. A manual deploy is required. I need to remove this manual step.
Netlify build hook
Open the site settings in Netlify. Go to Build & deploy → Continuous deployment → Build hooks. Create a build hook. Netlify provides a URL. This URL triggers a new build. It requires a POST request.
Triggering from GitHub
Add a GitHub Actions workflow to the repository. The workflow runs on a daily schedule. It also runs on manual request. The job sends an HTTP POST to the Netlify URL. This rebuilds the site. Scheduled posts publish without human action. The schedule is 01:00 daily. A manual workflow_dispatch trigger is included for testing.
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. Check the Netlify dashboard. The new deploy shows a build hook trigger. This removes the need for calendar reminders. Scheduled posts publish automatically.