Scheduled posts using GitHub Actions and Netlify

X @urre

Scheduled posts using GitHub Actions and Netlify

A traditional CMS handles scheduling posts easily. Static site builders may not have the same features built in, but be able to schedule a post is still important.

There are plenty of ways of doing it of course. We have all the modern tools to achieve it. I use Vercel for most of my side projects (Read about Vercel Deploy Hooks), but for a recent use case I needed to schedule music tips on my site Jazztips which is hosted on Netlify

Let’s jump right into it.

Setup a build hook in Netlify

Visit Site settings → Build & deploy → Build hooks

Build hooks

Setup a webhook on GitHub

Setup a web hook on GitHub

Setup a web hook on GitHub

Select which events that should trigger the hook

Setup a web hook on GitHub

Store the build hook as a GitHub secret

GitHub secret

Create a GitHub Workflow

  • Create a folder .GitHub/workflows
  • Inside, create a file netlify.yml
name: Netlify Deploy

on:
  schedule:
  - cron: "0 13 * * *"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Trigger Netlify Hook
      run: curl -X POST $

Select desired time interval e.g. “Every day at 1pm” (or similar). In the cURL command we use the NETLIFY_BUILD_URL secret created earlier.

Gatsby, Jekyll or [insert static site builder/CMS of choice here]

For Jazztips I use Jekyll. Set future: false in config.yml. Posts with future dates in the front matter date: 2020-XX-XX will only publish when the time is right 👍.

👉 Worth noting here is that some modern headless CMS has this built in their UIs.

Using Merge Schedule GitHub Action

Another option is this handy GitHub Action called Merge Schedule. It allows for mergeing pull requests on a scheduled day.

Create this YML file

We can now schedule a merge by creating a pull request description with just one line:

/schedule YYYY-MM-DD

This will now schedule the pull request merge at YYY-MM-DD

Done!

Now you can see the “Daily cron job” beeing triggered the hook in your deploy logs. Make sure to setup Deploy Notifiations also to get notified when a deploy request is accepted/rejected/pending.

Netlify deploy logs

More great options