website/first-time-setup.sh

41 lines
948 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() {
printf "$red An error occurred on line $1.\n"
}
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
printf "$green -> Setting up first time things...$reset\n"
trap 'error_log $LINENO' ERR
# Creating orphan branch for the site
git checkout --orphan $target_branch
# Reset the branch while retaining the files
git reset --hard
# Initialize the branch
git commit --allow-empty -m "Initializing $target_branch branch"
# Pushing the branch into origin
2019-08-19 16:26:13 +00:00
git push --force $main_remote_alias $target_branch
2019-08-15 10:50:28 +00:00
git checkout $default_branch
# Cleaning up the build site first
2019-08-15 11:27:34 +00:00
rm -rf $build_directory
2019-08-15 10:50:28 +00:00
# Adding a worktree for the target branch and setting it to origin
2019-08-15 11:27:34 +00:00
git worktree add -B $target_branch $build_directory $main_remote_alias/$target_branch