How to schedule Jekyll posts using GitHub actions

Oct 07 2019

Preface

In all these years, I have changed this blog several times, switching between Blogger, Wordpress, Ghost and Jekyll + GitHub pages.

Each platform had its advantages, and I liked Jekyll and GitHub pages a lot, but sometimes I wanted to schedule posts, and it was difficult. All the other options I tried had post scheduling, but had other things I didn’t like.

A summary about what I loved about Jekyll/GitHub pages:

GitHub PagesGhostWordpressBlogger
Supports markdownXX--
Supports scheduling-XXX
Free Ad-free HostingX--!
Total controlX!!-
FastXX--
SecureX!-X

The other day I discovered GitHub actions and installed the beta.

Today I thought about how could I schedule posts in Jekyll using actions. And now I have the solution.

soywiz/github-action-jekyll-publish-drafts to the rescue

I have created a new github action and published to the marketplace: https://github.com/soywiz/github-action-jekyll-publish-drafts

This plugin allows you to place a cron; for example each hour, and check in the _drafts folder, the files with a frontmatter with a date field that is older than the current time. Those files are moved to the _posts folder changing the prefix to include the date, makes a commit and pushes it back to the repository, creating a new commit and thus producing a page generation.

How cool is that?

Using the plugin

This should work for both public and private repositories:

  • You have to register to the GitHub actions beta.
  • You have to create the file .github/workflows/publish_drafts.yml with this content:
    name: Publish Drafts
    
    on:
      schedule:
        - cron: '*/60 * * * *'
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v1
        - name: Jekyll Publish Drafts
          uses: soywiz/github-action-jekyll-publish-drafts@v1
          with:
            github_token: ${ { secrets.GITHUB_TOKEN } }
            jekyll_path: ./
            branch: master
    

It registers an action that happens every hour, that does the job. You can configure jekyll_path and branch parameters. For example:

jekyll_path: ./docs
branch: gh-pages

About the plugin

The plugin is written using TypeScript and executed via Node.JS using docker.

You can check the repository for further details.