Scheduling Posts with Github Actions

How I do scheduled posts for this (entirely static) site
2 min read

Blog Setup

Many static site generators do this already - where if you date a post into the future they won’t render in index pages unless in production mode. I do the same thing here.

In local mode, things that are queued render as “Scheduled”, but once rendered in production they’re hidden except for in administration pages.

As I’ve previously blogged about - some content on this site is encrypted, and only accessible via the correct username/password combo.. So, I can still see the state of what will be going live via my administration dashboard page, but those things aren’t yet public.

I apply encryption automatically to posts that are queued - so future things can’t be seen prior to publishing. To do the actual publishing, I have a scheduled Github Action which runs a publish a couple times a day.

Github Actions

This is the config for my “build & deploy” action. I deploy on push, as well as to master.

I have a conditional configured in my “deploy to s3” step, so it will only actually release when scheduled builds run or manual pushes to the master branch: if: (github.event_name == 'push' && github.ref == 'refs/heads/master') || github.event_name == 'schedule'

Github Action Workflow

name: 'Deploy'
on:
  pull_request:
    branches: '*'
  push:
    branches: '*'
  schedule:
    - cron: '21 13,16,20 * * *' # 9am, 12pm, 4pm UTC
jobs:
  # ... normal job setup for GH actions

Feedback

Found a typo or technical problem? report an issue!

Subscribe to my Newsletter

Like this post? Subscribe to get notified for future posts like this.