Automating Jekyll Commits with Gitkwik

After using gitkwik to handle versioning and commits in JavaScript-based projects, I wanted a simpler version for my Jekyll site. This version removes all the NPM logic, supports versioning directly inside _config.yml, and auto-builds the site with jekyll build so I never forget.


What It Does

  1. Checks for uncommitted changes
  2. Prompts for a commit message
  3. Offers to bump the version: in _config.yml (patch, minor, or major)
  4. Commits the version bump (if any) separately
  5. Builds the site with bundle exec jekyll build
  6. Optionally commits _site/ if tracked

It skips the push step — I like to eyeball everything one last time before sending it up.


jekyllkwik.sh

#!/bin/bash

set -e

echo "Checking for changes..."
if git diff --quiet && git diff --cached --quiet; then
  echo "Working directory clean. No changes to commit. Exiting."
  exit 0
fi

echo "Detected changes:"
git status -s

echo ""
read -p "Enter your commit message: " commit_message

echo "Staging changes..."
git add .

echo "Committing..."
git commit -m "$commit_message"

echo ""
echo "Do you want to bump the version number in _config.yml?"
select bump in "patch" "minor" "major" "no version change" "cancel"; do
  case $bump in
    patch|minor|major)
      echo "Bumping $bump version in _config.yml..."

      if grep -q "^[[:space:]]*version:" _config.yml; then
        old_version=$(grep "^[[:space:]]*version:" _config.yml | sed -E 's/^[[:space:]]*version:[[:space:]]*["]?([^"]+)["]?/\1/')
        IFS='.' read -r major minor patch <<< "$old_version"

        case $bump in
          patch) patch=$((patch + 1)) ;;
          minor) minor=$((minor + 1)); patch=0 ;;
          major) major=$((major + 1)); minor=0; patch=0 ;;
        esac

        new_version="${major}.${minor}.${patch}"
        sed -i '' -E "s/^[[:space:]]*version:[[:space:]]*\"?[^\"]+\"?/version: \"$new_version\"/" _config.yml

        echo "version: $old_version$new_version"
        git add _config.yml
        git commit -m "bump version to $new_version"
      else
        echo "No version: field found in _config.yml — skipping."
      fi
      break
      ;;
    "no version change")
      echo "Skipping version bump..."
      break
      ;;
    cancel)
      echo "Cancelled."
      exit 0
      ;;
    *)
      echo "Invalid selection."
      ;;
  esac
done

echo "Building Jekyll site..."
bundle exec jekyll build || { echo "Jekyll build failed."; exit 1; }

if [ -d "_site" ]; then
  echo "Checking for changes in _site..."
  if ! git diff --quiet _site; then
    echo "Staging updated _site output..."
    git add _site
    git commit -m "update _site build output"
  else
    echo "No changes in _site."
  fi
fi

echo "Done! You can now push your changes."

Adding version: to _config.yml

Part of this scripts function is to handle versioning, so you need to add this line near the top of your _config.yml:

version: 1.0.0

You can then use it inside your Jekyll templates using:

{ '{ site.version }' }