diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..d270286 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,37 @@ +#!/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" + +trap 'error_log $LINENO' ERR + +# Cleaning up the build site +printf "Deleting older version of the site" +rm -rf public/ +mkdir public/ + +git worktree prune +rm -rf .git/worktrees/public/ + +# Building the site +printf "Building the site" +hugo + +# Pushing the build into the pages branch +printf "$green -> Deploying page to GitHub...$reset\n" +cd public +git add --all +git commit -m "Deploying site to branch $target_branch." + +git push origin $target_branch diff --git a/first-time-setup.sh b/first-time-setup.sh new file mode 100644 index 0000000..ab63696 --- /dev/null +++ b/first-time-setup.sh @@ -0,0 +1,38 @@ +#!/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" + +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 +git push origin $target_branch +git checkout $default_branch + +# Cleaning up the build site first +rm -rf public + +# Adding a worktree for the target branch and setting it to origin +git worktree add -B $target_branch public/ origin/$target_branch