website/deploy.sh

40 lines
799 B
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-15 11:27:34 +00:00
printf "$red An error occurred on line $1\n"
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
# 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-15 11:27:34 +00:00
git push $main_remote_alias $target_branch