Improve deploy and setup script

This commit is contained in:
foo-dogsquared 2019-08-15 19:27:34 +08:00
parent 5f79866847
commit 1078a3845d
2 changed files with 13 additions and 9 deletions

View File

@ -8,21 +8,23 @@ green="\u001b[32m"
reset="\u001b[0m"
error_log() {
printf "$red An error occurred on line $1.\n"
printf "$red An error occurred on line $1\n"
}
target_branch="gh-pages"
default_branch="master"
main_remote_alias="origin"
build_directory="public/"
trap 'error_log $LINENO' ERR
# Cleaning up the build site
printf "Deleting older version of the site"
rm -rf public/
mkdir public/
rm -rf $build_directory
mkdir $build_directory
git worktree prune
rm -rf .git/worktrees/public/
rm -rf .git/worktrees/$build_directory
# Building the site
printf "Building the site"
@ -30,8 +32,8 @@ hugo
# Pushing the build into the pages branch
printf "$green -> Deploying page to GitHub...$reset\n"
cd public
cd $build_directory
git add --all
git commit -m "Deploying site to branch $target_branch."
git push origin $target_branch
git push $main_remote_alias $target_branch

View File

@ -13,6 +13,8 @@ error_log() {
target_branch="gh-pages"
default_branch="master"
main_remote_alias="origin"
build_directory="public/"
printf "$green -> Setting up first time things...$reset\n"
@ -28,11 +30,11 @@ git reset --hard
git commit --allow-empty -m "Initializing $target_branch branch"
# Pushing the branch into origin
git push origin $target_branch
git push $main_remote_alias $target_branch
git checkout $default_branch
# Cleaning up the build site first
rm -rf public
rm -rf $build_directory
# Adding a worktree for the target branch and setting it to origin
git worktree add -B $target_branch public/ origin/$target_branch
git worktree add -B $target_branch $build_directory $main_remote_alias/$target_branch