Qubyte Codes

How I schedule posts using GitHub Actions


In the past I used atd to schedule the publication of my blog posts. When I moved to Netlify I lost the ability to schedule posts, and didn't think about it until a recent conversation on twitter with Remy Sharp. Remy asked how to schedule blog posts for static sites and it got me thinking.

I've been using GitHub actions recently, and one workflow trigger it provides is a cron-like schedule. I wrote a little npm script to read a directory full of scheduled posts. Each post has its publication date checked, and if it's in the past, the script moves the post to the published posts directory (at which point Netlify kicks in). The script takes advantage of the token provided by the actions environment to make two requests, one to recreate the file in the posts directory, and one to delete the scheduled file using the GitHub Contents API.

Sadly, there's no way to move a file using the Contents API, so the create-then-delete is necessary. This leads to two commits rather than just one. It may be possible to do it in a single commit using the Trees API, but that's a good deal more involved and I don't mind a little noise in the commit history.

You can see the workflow using this script here, and the publisher here. These scripts have been replaced since GitHub actions have changed! See the later post for updated specifics.

Of course, the scheduler published this post. ;)


Mention from Remy Sharp on : This by @qubyte is a nice solution to static site scheduled posts (when git is your source of truth)