Automatic Publishing With Jigsaw, Netlify and GitHub Actions

When I first setup this blog (just a couple of weeks back) I was using a combination of; Tighten Jigsaw, GitHub Actions & Pages. That setup allowed me to initially get my blog up and running very quickly, letting me focus solely on the content. However, soon after I published that post @the_nabeelahmed suggested using Netlify over GitHub Pages and provided me with the minimum configuration details needed to get Netlify working.

As I had some time that evening, I checked out Netlify and was genuinely able to get my blog published and switched over in a matter of minutes. That is a developer experience I loved.

Now, I know that some of you are saying / screaming:

James, you've only just started blogging, focus on the content and stop optimizing early!

To you, I say: thanks for the concern, but I'm optimising my writing workflow to allow me to focus on the content whilst reaping all the benefits of a static site and in doing so, I'm able to write about my experiences. Yes, I could use Wordpress, but that requires even more work to customise to my liking (and I never want to use hosted Wordpress ever again).

I may have switched to Netlify but it wasn't a case of disliking GitHub Pages! Here are my reasons for switching:

I created a custom build hook which we'll use later to trigger a scheduled automatic deployment.

Jigsaw Requirements

I want to be able to write ahead of myself and by this, I mean that I want to write a post that's scheduled for a date in the future and have GitHub Actions publish it automatically. To make this happen, I made a couple of small changes to the Jigsaw config files.

Firstly, I needed to update the config.staging.php file so that the baseUrl is set to env('DEPLOY_URL'). This means that when Netlify deploys a branch preview, I can navigate the blog correctly. DEPLOY_URL is an environment variable set by Netlify.

Next, I needed to add a filter to my posts collection in my base config.php array:

For this to work, you need to create a new secret in your repository for GH_TOKEN, which is a personal access token with repo permissions. I also created a secret of NETLIFY_BUILD_HOOK which contains the URL that Netlify generated for us earlier.

GitHub Actions will automatically run the workflow every hour between 8AM and 10PM (which is typically when I'd want to write a post)! Since any changes I make to the source branch will automatically be deployed, this covers everything I need! By doing this, Netlify is essentially regenerating any draft posts every hour.

I'm particularly happy with this configuration for a few reasons:

I can adjust the schedule as I see fit and run automerge more or less frequently if I need.

I can treat pull requests as drafts until it has the finished label.

Any posts that are merged, but we're not yet at their publish date will automatically build and become published with no manual deployments needed.

Let me know if you use this technique or something similar at @jbrooksuk.