#!/usr/bin/env bash # ref: https://github.com/jekyll/jekyll set -eu # Exit on error or unset variable PAGES_BRANCH="site" SITE_DIR="_output" _backup_dir="$(mktemp -d)" DATE_STAMP=$(date +"%Y-%m-%d %H:%M:%S") init() { echo "Initializing..." } build() { # clean if [[ -d $SITE_DIR ]]; then rm -rf "$SITE_DIR" fi # Run the Ruby script to generate the output bundle exec ruby "./scaffold.rb" } setup_gh() { if [[ -z $(git branch -av | grep "$PAGES_BRANCH") ]]; then git checkout -b "$PAGES_BRANCH" else git checkout "$PAGES_BRANCH" fi } backup() { mv "$SITE_DIR"/* "$_backup_dir" mv .git "$_backup_dir" if [[ -f CNAME ]]; then mv CNAME "$_backup_dir" fi } flush() { rm -rf ./* rm -rf .[^.] .??* shopt -s dotglob nullglob mv "$_backup_dir"/* . } deploy() { # Configure Git user for the commit git config --global user.name "Elizabeth Cray" git config --global user.email "liz@cray.lgbt" # Reset the current HEAD to prepare for new commits git update-ref -d HEAD git add -A git commit -m "[Automation] Site update: ${DATE_STAMP}" # Push the new branch to the remote repository git push -u origin "$PAGES_BRANCH" --force } reset() { git checkout main } main() { init build setup_gh backup flush deploy reset } # Execute the main function main