website/deploy.sh

45 lines
1.0 KiB
Bash
Raw Normal View History

2019-08-15 10:50:28 +00:00
#!/bin/bash
# Deploys the Hugo build into GitHub Pages.
# ANSI color codes
red="\u001b[31m"
green="\u001b[32m"
reset="\u001b[0m"
error_log() {
2019-08-19 16:26:13 +00:00
printf "$red An error occurred on line $1\n $reset"
2019-08-15 10:50:28 +00:00
}
target_branch="gh-pages"
default_branch="master"
2019-08-15 11:27:34 +00:00
main_remote_alias="origin"
build_directory="public/"
2019-08-15 10:50:28 +00:00
trap 'error_log $LINENO' ERR
# Cleaning up the build site
printf "Deleting older version of the site"
2019-08-15 11:27:34 +00:00
rm -rf $build_directory
mkdir $build_directory
2019-08-15 10:50:28 +00:00
git worktree prune
2019-08-15 11:27:34 +00:00
rm -rf .git/worktrees/$build_directory
2019-08-15 10:50:28 +00:00
2019-08-19 16:26:13 +00:00
# Building the worktree for the target branch
# https://git-scm.com/docs/git-worktree
echo "Checking out $target_branch branch into public"
git worktree add -B $target_branch $public $main_remote_alias/$target_branch
2019-08-15 10:50:28 +00:00
# Building the site
printf "Building the site"
hugo
# Pushing the build into the pages branch
printf "$green -> Deploying page to GitHub...$reset\n"
2019-08-15 11:27:34 +00:00
cd $build_directory
2019-08-15 10:50:28 +00:00
git add --all
git commit -m "Deploying site to branch $target_branch."
2019-08-19 16:26:13 +00:00
git push --force $main_remote_alias $target_branch