Welcome fellow bloggers! If you are here, then you are interested in automating parts of your blog with GitHub Actions. I’ve been able to add efficiencies to my blog that help deploy future blog posts, keep third-party expenditure to a minimum, and I’m planning on doing more. I will keep my automation updated in this post, so check back regularly.

What Are GitHub Actions

GitHub Actions is an integrated feature of GitHub. I’ve recently started to dabble in it, and I’m impressed.

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. GitHub

Enabled by GitHub Actions, you are capable of running any series of commands within a Docker container, with support for Windows, Linux, and macOS environments.

In my particular case, my usage of GitHub Actions always comes in under 2,000 minutes a month, meaning its all free.

To get started using GitHub Actions, you’ll need to add a folder to the root of your GitHub repository.

> mkdir .github/workflows/

In this directory, you’ll add YAML files for each action. Let’s get started!

Note: As of writing this post, you cannot manually trigger actions.

Netlify Scheduled Deployment

I found a blog post by Nickolas C. Zakas detailing how to trigger manual deployment withing Netlify, which is where I host my blog. I recommend following his detailed step-by-step tutorial.

This GitHub Action will call Netlify’s build endpoint and trigger a manual build. This action is excellent for queueing up future posts and publishing them when the date arrives.

name: Netlify Deploy

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

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger Netlify Hook
        run: curl -X POST ${{ secrets.netlify_build_url }}

Algolia Search Indexing

Algolia is an excellent search provider, and they offer a free tier for folks. One of the issues you may run into is that it is a credit-based system. Previously, I had all my blog posts indexed on every Netlify build. This worked, but became costly when I noticed minor edits in blog posts. So, I decided to automate the indexing of my blog.

name: Algolia Search

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

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-ruby@v1
      with:
        ruby-version: '2.6'

    - name: Ruby Version
      run: ruby --version

    - name: Algolia Index
      env: 
        ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
      run: |
        sudo apt-get -yqq install libpq-dev
        gem install bundler
        bundle install --jobs 4 --retry 3
        bundle exec jekyll build
        bundle exec jekyll algolia

A few things to note about this action:

  • I am installing Ruby
  • I am installing Bundler
  • I am building my Jekyll site
  • I am running the Jekyll-Algolia search indexer

As of writing this post, this build takes about five minutes to execute.

Twitter Promotion

Self-promotion is a big part of blogging. Online search is perfect for folks searching for specific solutions to their problems. Twitter is an excellent source of spontaneous discovery. I like to tweet about posts I’ve written and to let my followers discover my writing. Here I wrote a GitHub Action using a BlogPromoter .NET Core app I wrote. The .NET Core application pulls a random post from your RSS feed and tweets it through your account for you.

name: Twitter Promoter

on:
  schedule:
    # 10 AM and 3 PM Everyday
    - cron: "00 10,15 * * *"

jobs:
  build:
    runs-on: ubuntu-latest

    steps:

    - name: Checkout Blog Promoter
      uses: actions/checkout@v2
      with:
        repository: khalidabuhakmeh/BlogPromoter

    - name: Install .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '3.1.100'

    - name: Run Promoter
      env: 
        twitter_account: '@buhakmeh'
        blog_feed_url: 'https://khalidabuhakmeh.com/feed.xml'
        twitter_access_token: ${{ secrets.twitter_access_token }}
        twitter_access_token_secret: ${{ secrets.twitter_access_token_secret }}
        twitter_consumer_key: ${{ secrets.twitter_consumer_key }}
        twitter_consumer_secret: ${{ secrets.twitter_consumer_secret }}
      run: dotnet run -c Release

Note: You’ll need to sign up for Twitter developer access. Also, you’ll need to set up your GitHub environment variables appropriately.

Conclusion

GitHub Actions are a significant improvement to the GitHub ecosystem. Actions can help you build a robust blogging platform with minimal effort and zero out of pocket costs. Where I sit today, I can create a backlog of posts, index all my writing for user search, and promote my self all through GitHub Actions. GitHub Actions have great triggers too, so you can do just about anything.