I have adapted parts of several different suggestions to create an automated workflow for my Jekyll website. With one simple bash script, I am able to update my site after every key entry. The site is under version control using git and is really easy to use.

The Goal of This Process

I really hate repeating myself. And that includes repeatedly performing the same actions on my computer. With this new website on DigitalOcean, there are many repetitive process that I would like to automate. Consider this workflow:

  1. Create or modify a page on the site
  2. Save the changes
  3. Commit changes to local git repository
  4. Check out revisions on a developmental server
  5. Push changes to the production server
  6. Rebuild production site to include the changes
  7. Reindex the site so that Algolia picks up the changes

This workflow is shown graphically in the Mermaid figure below.

graph TB; A(LOCAL FILES) == git commit ==> B(GIT REPO); A -. modifications .-> A; A -- jekyll serve --> C[DEVELOPMENT SITE]; B == git push droplet master ==> D(DROPLET /TMP); D == jekyll build to target ==> E[PRODUCTION SITE]; D -. delete all files .-> D; A == jekyll algolia push ==> F[SITE REINDEXED]; style A fill:#CCC; style C fill:#F99; style E fill:#99F; style F fill:#0C0;

I definitely do not want to do this manually every time! So, I have written a bash script to take care of it for me. Here is my “update” bash script:

#! /bin/bash
#===============================================================
# UPDATE
# This script updates my website after editing its contents
# Dr. Clifton Franklund
# Ferris State University
# 2018, MIT
#===============================================================

# Check for commit message 
if [ $# -eq 0 ]
  then
    # default commit message
    message="Updated website contents"
  else
    # first passed argument is message
    message=$1
fi

# update my git repository
git add .
git status
git commit -m "$message"

# send update to DigitalOcean droplet
git push droplet master

# reindex the website
jekyll algolia push

I stored this script in my /bin directory (which is on my path) and changed permissions with chmod 755 to make it executable. Not when I type update "This is a sample commit", all saved changes are committed to git, published to my droplet, built as a new site, and reindexed. All automatically. I smile a little every time I do this - it is a small dopamine hit, I think. Feel free to copy, modify, and/or use this script for your own projects.

Like somethat that you read here? Feel free to share it.